98 lines
2.2 KiB
C++
98 lines
2.2 KiB
C++
#ifndef __IMFResponse_h__
|
|
#define __IMFResponse_h__
|
|
|
|
#include "IMFMessage.h"
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
namespace coreutils {
|
|
|
|
///
|
|
/// IMFResponse
|
|
///
|
|
/// Use this object to build a response output for a protocol that uses headers
|
|
/// and responses as the main communications protocol.
|
|
///
|
|
|
|
class IMFResponse {
|
|
|
|
public:
|
|
|
|
enum Mode { LENGTH, STREAMING };
|
|
|
|
///
|
|
/// The constructor for the object.
|
|
///
|
|
|
|
IMFResponse();
|
|
|
|
///
|
|
/// The destructor for the object.
|
|
///
|
|
|
|
~IMFResponse();
|
|
|
|
///
|
|
/// Returns the response generated from the contained values that
|
|
/// do not return a content length. Using this constructor ensures
|
|
/// a zero length Content-Length value.
|
|
///
|
|
/// @return the complete response string to send to client.
|
|
///
|
|
|
|
std::stringstream getResponse(Mode mode = LENGTH);
|
|
|
|
///
|
|
/// Returns the response plus the content passed as a parameter.
|
|
///
|
|
/// This method will automatically generate the proper Content-Length
|
|
/// value for the response.
|
|
///
|
|
/// @param content the content that will be provided on the response
|
|
/// message to the client.
|
|
///
|
|
/// @return the complete response string to send to client.
|
|
///
|
|
|
|
std::stringstream getResponse(std::stringstream &content, Mode mode = LENGTH);
|
|
|
|
///
|
|
/// Sets the protocol value for the response message. The protocol
|
|
/// should match the header received.
|
|
///
|
|
/// @param protocol the protocol value to return in response.
|
|
///
|
|
|
|
void setProtocol(ZString protocol);
|
|
|
|
///
|
|
/// Sets the return code value for the response.
|
|
///
|
|
/// @param code the response code value to return in the response.
|
|
///
|
|
|
|
void setCode(ZString code);
|
|
|
|
///
|
|
/// Sets the return code string value for the response.
|
|
///
|
|
/// @param text the text value for the response code to return on
|
|
/// the response.
|
|
///
|
|
|
|
void setText(ZString text);
|
|
|
|
private:
|
|
ZString protocol;
|
|
ZString code;
|
|
ZString text;
|
|
|
|
char contentLength[32];
|
|
const char *CRLF = "\r\n";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|