10 #ifndef __PION_HTTPRESPONSE_HEADER__
11 #define __PION_HTTPRESPONSE_HEADER__
13 #include <boost/shared_ptr.hpp>
14 #include <boost/lexical_cast.hpp>
15 #include <pion/PionConfig.hpp>
16 #include <pion/net/HTTPMessage.hpp>
17 #include <pion/net/HTTPRequest.hpp>
38 : m_status_code(RESPONSE_CODE_OK),
39 m_status_message(RESPONSE_MESSAGE_OK)
50 : m_status_code(RESPONSE_CODE_OK), m_status_message(RESPONSE_MESSAGE_OK),
51 m_request_method(request_method)
57 m_status_code(http_response.m_status_code),
58 m_status_message(http_response.m_status_message),
59 m_request_method(http_response.m_request_method)
65 : m_status_code(RESPONSE_CODE_OK),
66 m_status_message(RESPONSE_MESSAGE_OK)
75 m_status_code = RESPONSE_CODE_OK;
76 m_status_message = RESPONSE_MESSAGE_OK;
77 m_request_method.clear();
82 return (m_request_method == REQUEST_METHOD_HEAD
83 || (m_status_code >= 100 && m_status_code <= 199)
84 || m_status_code == 204 || m_status_code == 205
85 || m_status_code == 304
96 m_request_method = http_request.
getMethod();
109 m_status_message = msg;
127 inline void setCookie(
const std::string& name,
const std::string& value) {
129 addHeader(HEADER_SET_COOKIE, set_cookie_header);
140 inline void setCookie(
const std::string& name,
const std::string& value,
141 const std::string& path)
144 addHeader(HEADER_SET_COOKIE, set_cookie_header);
155 inline void setCookie(
const std::string& name,
const std::string& value,
156 const std::string& path,
const unsigned long max_age)
159 addHeader(HEADER_SET_COOKIE, set_cookie_header);
169 inline void setCookie(
const std::string& name,
const std::string& value,
170 const unsigned long max_age)
173 addHeader(HEADER_SET_COOKIE, set_cookie_header);
179 addHeader(HEADER_SET_COOKIE, set_cookie_header);
183 inline void deleteCookie(
const std::string& name,
const std::string& path) {
185 addHeader(HEADER_SET_COOKIE, set_cookie_header);
202 m_first_line += boost::lexical_cast<std::string>(m_status_code);
205 m_first_line += m_status_message;
212 unsigned int m_status_code;
215 std::string m_status_message;
218 std::string m_request_method;
223 typedef boost::shared_ptr<HTTPResponse> HTTPResponsePtr;
void setStatusCode(unsigned int n)
sets the HTTP response status code
void addHeader(const std::string &key, const std::string &value)
adds a value for the HTTP header named key
void setLastModified(const unsigned long t)
sets the time that the response was last modified (Last-Modified)
virtual void clear(void)
clears all message data
static std::string get_date_string(const time_t t)
converts time_t format into an HTTP-date string
HTTPResponse(const HTTPRequest &http_request)
virtual void updateFirstLine(void) const
updates the string containing the first line for the HTTP message
void changeHeader(const std::string &key, const std::string &value)
changes the value for the HTTP header named key
void setCookie(const std::string &name, const std::string &value, const unsigned long max_age)
boost::uint16_t getVersionMajor(void) const
returns the major HTTP version number
virtual void clear(void)
clears all response data
virtual ~HTTPResponse()
virtual destructor
void setStatusMessage(const std::string &msg)
sets the HTTP response status message
virtual bool isContentLengthImplied(void) const
the content length may be implied for certain types of responses
void setCookie(const std::string &name, const std::string &value, const std::string &path)
void setCookie(const std::string &name, const std::string &value, const std::string &path, const unsigned long max_age)
const std::string & getMethod(void) const
returns the request method (i.e. GET, POST, PUT)
HTTPResponse(const HTTPResponse &http_response)
copy constructor
boost::uint16_t getVersionMinor(void) const
returns the minor HTTP version number
void setCookie(const std::string &name, const std::string &value)
HTTPResponse(const std::string &request_method)
the following enables use of the lock-free cache
const std::string & getStatusMessage(void) const
returns the HTTP response status message
void deleteCookie(const std::string &name, const std::string &path)
deletes cookie called name by adding a Set-Cookie header (cookie has a path)
std::string getVersionString(void) const
returns a string representation of the HTTP version (i.e. "HTTP/1.1")
void deleteCookie(const std::string &name)
deletes cookie called name by adding a Set-Cookie header (cookie has no path)
unsigned int getStatusCode(void) const
returns the HTTP response status code
void setChunksSupported(bool b)
set to true if chunked transfer encodings are supported
void clearFirstLine(void) const
void updateRequestInfo(const HTTPRequest &http_request)
static std::string make_set_cookie_header(const std::string &name, const std::string &value, const std::string &path, const bool has_max_age=false, const unsigned long max_age=0)