pion-net  4.0.9
Public Member Functions | Protected Member Functions | List of all members
pion::net::HTTPResponse Class Reference

#include <HTTPResponse.hpp>

Inherits pion::net::HTTPMessage.

Public Member Functions

 HTTPResponse (const HTTPRequest &http_request)
 
 HTTPResponse (const std::string &request_method)
 
 HTTPResponse (const HTTPResponse &http_response)
 copy constructor
 
 HTTPResponse (void)
 
virtual ~HTTPResponse ()
 virtual destructor
 
virtual void clear (void)
 clears all response data
 
virtual bool isContentLengthImplied (void) const
 the content length may be implied for certain types of responses
 
void updateRequestInfo (const HTTPRequest &http_request)
 
void setStatusCode (unsigned int n)
 sets the HTTP response status code
 
void setStatusMessage (const std::string &msg)
 sets the HTTP response status message
 
unsigned int getStatusCode (void) const
 returns the HTTP response status code
 
const std::string & getStatusMessage (void) const
 returns the HTTP response status message
 
void setCookie (const std::string &name, const std::string &value)
 
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)
 
void setCookie (const std::string &name, const std::string &value, const unsigned long max_age)
 
void deleteCookie (const std::string &name)
 deletes cookie called name by adding a Set-Cookie header (cookie has no path)
 
void deleteCookie (const std::string &name, const std::string &path)
 deletes cookie called name by adding a Set-Cookie header (cookie has a path)
 
void setLastModified (const unsigned long t)
 sets the time that the response was last modified (Last-Modified)
 
- Public Member Functions inherited from pion::net::HTTPMessage
 HTTPMessage (void)
 constructs a new HTTP message object
 
 HTTPMessage (const HTTPMessage &http_msg)
 copy constructor
 
HTTPMessageoperator= (const HTTPMessage &http_msg)
 assignment operator
 
virtual ~HTTPMessage ()
 virtual destructor
 
bool isValid (void) const
 returns true if the message is valid
 
bool getChunksSupported (void) const
 returns true if chunked transfer encodings are supported
 
boost::asio::ip::address & getRemoteIp (void)
 returns IP address of the remote endpoint
 
boost::uint16_t getVersionMajor (void) const
 returns the major HTTP version number
 
boost::uint16_t getVersionMinor (void) const
 returns the minor HTTP version number
 
std::string getVersionString (void) const
 returns a string representation of the HTTP version (i.e. "HTTP/1.1")
 
std::size_t getContentLength (void) const
 returns the length of the payload content (in bytes)
 
bool isChunked (void) const
 returns true if the message content is chunked
 
char * getContent (void)
 returns a pointer to the payload content, or NULL if there is none
 
const char * getContent (void) const
 returns a const pointer to the payload content, or NULL if there is none
 
ChunkCachegetChunkCache (void)
 returns a reference to the chunk cache
 
const std::string & getHeader (const std::string &key) const
 returns a value for the header if any are defined; otherwise, an empty string
 
HeadersgetHeaders (void)
 returns a reference to the HTTP headers
 
bool hasHeader (const std::string &key) const
 returns true if at least one value for the header is defined
 
const std::string & getCookie (const std::string &key) const
 
CookieParamsgetCookieParams (void)
 returns the cookie parameters
 
bool hasCookie (const std::string &key) const
 
void addCookie (const std::string &key, const std::string &value)
 
void changeCookie (const std::string &key, const std::string &value)
 
void deleteCookie (const std::string &key)
 
const std::string & getFirstLine (void) const
 returns a string containing the first line for the HTTP message
 
bool hasMissingPackets () const
 true if there were missing packets
 
void setMissingPackets (bool newVal)
 set to true when missing packets detected
 
bool hasDataAfterMissingPackets () const
 true if more data seen after the missing packets
 
void setDataAfterMissingPacket (bool newVal)
 
void setIsValid (bool b=true)
 sets whether or not the message is valid
 
void setChunksSupported (bool b)
 set to true if chunked transfer encodings are supported
 
void setRemoteIp (const boost::asio::ip::address &ip)
 sets IP address of the remote endpoint
 
void setVersionMajor (const boost::uint16_t n)
 sets the major HTTP version number
 
void setVersionMinor (const boost::uint16_t n)
 sets the minor HTTP version number
 
void setContentLength (const std::size_t n)
 sets the length of the payload content (in bytes)
 
void setDoNotSendContentLength (void)
 if called, the content-length will not be sent in the HTTP headers
 
DataStatus getStatus () const
 return the data receival status
 
void setStatus (DataStatus newVal)
 
void updateContentLengthUsingHeader (void)
 sets the length of the payload content using the Content-Length header
 
void updateTransferCodingUsingHeader (void)
 sets the transfer coding using the Transfer-Encoding header
 
char * createContentBuffer (void)
 
void setContent (const std::string &content)
 resets payload content to match the value of a string
 
void clearContent (void)
 clears payload content buffer
 
void setContentType (const std::string &type)
 sets the content type for the message payload
 
void addHeader (const std::string &key, const std::string &value)
 adds a value for the HTTP header named key
 
void changeHeader (const std::string &key, const std::string &value)
 changes the value for the HTTP header named key
 
void deleteHeader (const std::string &key)
 removes all values for the HTTP header named key
 
bool checkKeepAlive (void) const
 returns true if the HTTP connection may be kept alive
 
void prepareBuffersForSend (WriteBuffers &write_buffers, const bool keep_alive, const bool using_chunks)
 
std::size_t send (TCPConnection &tcp_conn, boost::system::error_code &ec, bool headers_only=false)
 
std::size_t receive (TCPConnection &tcp_conn, boost::system::error_code &ec, bool headers_only=false)
 
std::size_t write (std::ostream &out, boost::system::error_code &ec, bool headers_only=false)
 
std::size_t read (std::istream &in, boost::system::error_code &ec, bool headers_only=false)
 
void concatenateChunks (void)
 
- Public Member Functions inherited from pion::net::HTTPTypes
virtual ~HTTPTypes ()
 virtual destructor
 

Protected Member Functions

virtual void updateFirstLine (void) const
 updates the string containing the first line for the HTTP message
 
- Protected Member Functions inherited from pion::net::HTTPMessage
void prepareHeadersForSend (const bool keep_alive, const bool using_chunks)
 
void appendHeaders (WriteBuffers &write_buffers)
 
void clearFirstLine (void) const
 

Additional Inherited Members

- Public Types inherited from pion::net::HTTPMessage
enum  DataStatus { STATUS_NONE, STATUS_TRUNCATED, STATUS_PARTIAL, STATUS_OK }
 defines message data integrity status codes
 
typedef std::vector
< boost::asio::const_buffer > 
WriteBuffers
 data type for I/O write buffers (these wrap existing data to be sent)
 
typedef std::vector< char > ChunkCache
 used to cache chunked data
 
- Public Types inherited from pion::net::HTTPTypes
typedef StringDictionary Headers
 data type for HTTP headers
 
typedef StringDictionary CookieParams
 data type for HTTP cookie parameters
 
typedef StringDictionary QueryParams
 data type for HTTP query parameters
 
- Static Public Member Functions inherited from pion::net::HTTPTypes
static std::string get_date_string (const time_t t)
 converts time_t format into an HTTP-date string
 
static std::string make_query_string (const QueryParams &query_params)
 builds an HTTP query string from a collection of query parameters
 
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)
 
- Static Public Attributes inherited from pion::net::HTTPTypes
static const std::string STRING_EMPTY
 
static const std::string STRING_CRLF
 
static const std::string STRING_HTTP_VERSION
 
static const std::string HEADER_NAME_VALUE_DELIMITER
 
static const std::string HEADER_HOST
 
static const std::string HEADER_COOKIE
 
static const std::string HEADER_SET_COOKIE
 
static const std::string HEADER_CONNECTION
 
static const std::string HEADER_CONTENT_TYPE
 
static const std::string HEADER_CONTENT_LENGTH
 
static const std::string HEADER_CONTENT_LOCATION
 
static const std::string HEADER_CONTENT_ENCODING
 
static const std::string HEADER_LAST_MODIFIED
 
static const std::string HEADER_IF_MODIFIED_SINCE
 
static const std::string HEADER_TRANSFER_ENCODING
 
static const std::string HEADER_LOCATION
 
static const std::string HEADER_AUTHORIZATION
 
static const std::string HEADER_REFERER
 
static const std::string HEADER_USER_AGENT
 
static const std::string HEADER_X_FORWARDED_FOR
 
static const std::string HEADER_CLIENT_IP
 
static const std::string CONTENT_TYPE_HTML
 
static const std::string CONTENT_TYPE_TEXT
 
static const std::string CONTENT_TYPE_XML
 
static const std::string CONTENT_TYPE_URLENCODED
 
static const std::string REQUEST_METHOD_HEAD
 
static const std::string REQUEST_METHOD_GET
 
static const std::string REQUEST_METHOD_PUT
 
static const std::string REQUEST_METHOD_POST
 
static const std::string REQUEST_METHOD_DELETE
 
static const std::string RESPONSE_MESSAGE_OK
 
static const std::string RESPONSE_MESSAGE_CREATED
 
static const std::string RESPONSE_MESSAGE_ACCEPTED
 
static const std::string RESPONSE_MESSAGE_NO_CONTENT
 
static const std::string RESPONSE_MESSAGE_FOUND
 
static const std::string RESPONSE_MESSAGE_UNAUTHORIZED
 
static const std::string RESPONSE_MESSAGE_FORBIDDEN
 
static const std::string RESPONSE_MESSAGE_NOT_FOUND
 
static const std::string RESPONSE_MESSAGE_METHOD_NOT_ALLOWED
 
static const std::string RESPONSE_MESSAGE_NOT_MODIFIED
 
static const std::string RESPONSE_MESSAGE_BAD_REQUEST
 
static const std::string RESPONSE_MESSAGE_SERVER_ERROR
 
static const std::string RESPONSE_MESSAGE_NOT_IMPLEMENTED
 
static const std::string RESPONSE_MESSAGE_CONTINUE
 
static const unsigned int RESPONSE_CODE_OK = 200
 
static const unsigned int RESPONSE_CODE_CREATED = 201
 
static const unsigned int RESPONSE_CODE_ACCEPTED = 202
 
static const unsigned int RESPONSE_CODE_NO_CONTENT = 204
 
static const unsigned int RESPONSE_CODE_FOUND = 302
 
static const unsigned int RESPONSE_CODE_UNAUTHORIZED = 401
 
static const unsigned int RESPONSE_CODE_FORBIDDEN = 403
 
static const unsigned int RESPONSE_CODE_NOT_FOUND = 404
 
static const unsigned int RESPONSE_CODE_METHOD_NOT_ALLOWED = 405
 
static const unsigned int RESPONSE_CODE_NOT_MODIFIED = 304
 
static const unsigned int RESPONSE_CODE_BAD_REQUEST = 400
 
static const unsigned int RESPONSE_CODE_SERVER_ERROR = 500
 
static const unsigned int RESPONSE_CODE_NOT_IMPLEMENTED = 501
 
static const unsigned int RESPONSE_CODE_CONTINUE = 100
 
- Static Protected Member Functions inherited from pion::net::HTTPMessage
template<typename DictionaryType >
static const std::string & getValue (const DictionaryType &dict, const std::string &key)
 
template<typename DictionaryType >
static void changeValue (DictionaryType &dict, const std::string &key, const std::string &value)
 
template<typename DictionaryType >
static void deleteValue (DictionaryType &dict, const std::string &key)
 
- Protected Attributes inherited from pion::net::HTTPMessage
std::string m_first_line
 

Detailed Description

HTTPResponse: container for HTTP response information

Definition at line 27 of file HTTPResponse.hpp.

Constructor & Destructor Documentation

pion::net::HTTPResponse::HTTPResponse ( const HTTPRequest http_request)
inline

constructs a new HTTPResponse object for a particular request

Parameters
http_requestthe request that this is responding to

Definition at line 37 of file HTTPResponse.hpp.

References updateRequestInfo().

pion::net::HTTPResponse::HTTPResponse ( const std::string &  request_method)
inline

constructs a new HTTPResponse object for a particular request method

Parameters
request_methodthe method used by the HTTP request we are responding to

Definition at line 49 of file HTTPResponse.hpp.

pion::net::HTTPResponse::HTTPResponse ( void  )
inline

default constructor: you are strongly encouraged to use one of the other constructors, since HTTPResponse parsing is influenced by the request method

Definition at line 64 of file HTTPResponse.hpp.

Member Function Documentation

void pion::net::HTTPResponse::setCookie ( const std::string &  name,
const std::string &  value 
)
inline

sets a cookie by adding a Set-Cookie header (see RFC 2109) the cookie will be discarded by the user-agent when it closes

Parameters
namethe name of the cookie
valuethe value of the cookie

Definition at line 127 of file HTTPResponse.hpp.

References pion::net::HTTPMessage::addHeader(), and pion::net::HTTPTypes::make_set_cookie_header().

void pion::net::HTTPResponse::setCookie ( const std::string &  name,
const std::string &  value,
const std::string &  path 
)
inline

sets a cookie by adding a Set-Cookie header (see RFC 2109) the cookie will be discarded by the user-agent when it closes

Parameters
namethe name of the cookie
valuethe value of the cookie
paththe path of the cookie

Definition at line 140 of file HTTPResponse.hpp.

References pion::net::HTTPMessage::addHeader(), and pion::net::HTTPTypes::make_set_cookie_header().

void pion::net::HTTPResponse::setCookie ( const std::string &  name,
const std::string &  value,
const std::string &  path,
const unsigned long  max_age 
)
inline

sets a cookie by adding a Set-Cookie header (see RFC 2109)

Parameters
namethe name of the cookie
valuethe value of the cookie
paththe path of the cookie
max_agethe life of the cookie, in seconds (0 = discard)

Definition at line 155 of file HTTPResponse.hpp.

References pion::net::HTTPMessage::addHeader(), and pion::net::HTTPTypes::make_set_cookie_header().

void pion::net::HTTPResponse::setCookie ( const std::string &  name,
const std::string &  value,
const unsigned long  max_age 
)
inline

sets a cookie by adding a Set-Cookie header (see RFC 2109)

Parameters
namethe name of the cookie
valuethe value of the cookie
max_agethe life of the cookie, in seconds (0 = discard)

Definition at line 169 of file HTTPResponse.hpp.

References pion::net::HTTPMessage::addHeader(), and pion::net::HTTPTypes::make_set_cookie_header().

void pion::net::HTTPResponse::updateRequestInfo ( const HTTPRequest http_request)
inline

Updates HTTP request information for the response object (use this if the response cannot be constructed using the request)

Parameters
http_requestthe request that this is responding to

Definition at line 95 of file HTTPResponse.hpp.

References pion::net::HTTPRequest::getMethod(), pion::net::HTTPMessage::getVersionMajor(), pion::net::HTTPMessage::getVersionMinor(), and pion::net::HTTPMessage::setChunksSupported().

Referenced by HTTPResponse().


The documentation for this class was generated from the following file: