ServerCore/Response.h
2019-02-07 13:28:21 -08:00

109 lines
2.6 KiB
C++

#ifndef __Response_h__
#define __Response_h__
#include "includes"
#include "Object.h"
namespace core {
///
/// Response
///
/// Use this object to build a response output for a protocol that uses headers
/// and responses as the main communications protocol.
///
class Response : public Object {
public:
enum Mode { LENGTH, STREAMING };
///
/// The constructor for the object.
///
Response();
///
/// The destructor for the object.
///
~Response();
///
/// 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::string 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::string getResponse(std::string 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(std::string protocol);
///
/// Sets the return code value for the response.
///
/// @param code the response code value to return in the response.
///
void setCode(std::string 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(std::string text);
///
/// Specifies the type of data that will be returned in this response.
///
/// @param mimeType the mime type for the data.
///
void setMimeType(std::string mimeType);
void addHeaderItem(std::string key, std::string value);
private:
std::string protocol;
std::string code;
std::string text;
std::string mimeType;
std::string CRLF = "\r\n";
std::map<std::string, std::string> header;
};
}
#endif