class Poco::Net::HTTPResponse
Overview
This class encapsulates an HTTP response message. Moreā¦
#include <HTTPResponse.h> class HTTPResponse: public Poco::Net::HTTPMessage { public: // enums enum HTTPStatus; // fields static const std::string HTTP_REASON_CONTINUE; static const std::string HTTP_REASON_SWITCHING_PROTOCOLS; static const std::string HTTP_REASON_OK; static const std::string HTTP_REASON_CREATED; static const std::string HTTP_REASON_ACCEPTED; static const std::string HTTP_REASON_NONAUTHORITATIVE; static const std::string HTTP_REASON_NO_CONTENT; static const std::string HTTP_REASON_RESET_CONTENT; static const std::string HTTP_REASON_PARTIAL_CONTENT; static const std::string HTTP_REASON_MULTIPLE_CHOICES; static const std::string HTTP_REASON_MOVED_PERMANENTLY; static const std::string HTTP_REASON_FOUND; static const std::string HTTP_REASON_SEE_OTHER; static const std::string HTTP_REASON_NOT_MODIFIED; static const std::string HTTP_REASON_USEPROXY; static const std::string HTTP_REASON_TEMPORARY_REDIRECT; static const std::string HTTP_REASON_BAD_REQUEST; static const std::string HTTP_REASON_UNAUTHORIZED; static const std::string HTTP_REASON_PAYMENT_REQUIRED; static const std::string HTTP_REASON_FORBIDDEN; static const std::string HTTP_REASON_NOT_FOUND; static const std::string HTTP_REASON_METHOD_NOT_ALLOWED; static const std::string HTTP_REASON_NOT_ACCEPTABLE; static const std::string HTTP_REASON_PROXY_AUTHENTICATION_REQUIRED; static const std::string HTTP_REASON_REQUEST_TIMEOUT; static const std::string HTTP_REASON_CONFLICT; static const std::string HTTP_REASON_GONE; static const std::string HTTP_REASON_LENGTH_REQUIRED; static const std::string HTTP_REASON_PRECONDITION_FAILED; static const std::string HTTP_REASON_REQUESTENTITYTOOLARGE; static const std::string HTTP_REASON_REQUESTURITOOLONG; static const std::string HTTP_REASON_UNSUPPORTEDMEDIATYPE; static const std::string HTTP_REASON_REQUESTED_RANGE_NOT_SATISFIABLE; static const std::string HTTP_REASON_EXPECTATION_FAILED; static const std::string HTTP_REASON_INTERNAL_SERVER_ERROR; static const std::string HTTP_REASON_NOT_IMPLEMENTED; static const std::string HTTP_REASON_BAD_GATEWAY; static const std::string HTTP_REASON_SERVICE_UNAVAILABLE; static const std::string HTTP_REASON_GATEWAY_TIMEOUT; static const std::string HTTP_REASON_VERSION_NOT_SUPPORTED; static const std::string HTTP_REASON_UNKNOWN; static const std::string DATE; static const std::string SET_COOKIE; // construction HTTPResponse(); HTTPResponse( HTTPStatus status, const std::string& reason ); HTTPResponse( const std::string& version, HTTPStatus status, const std::string& reason ); HTTPResponse(HTTPStatus status); HTTPResponse( const std::string& version, HTTPStatus status ); // methods void setStatus(HTTPStatus status); HTTPStatus getStatus() const; void setStatus(const std::string& status); void setReason(const std::string& reason); const std::string& getReason() const; void setStatusAndReason( HTTPStatus status, const std::string& reason ); void setStatusAndReason(HTTPStatus status); void setDate(const Poco::Timestamp& dateTime); Poco::Timestamp getDate() const; void addCookie(const HTTPCookie& cookie); void getCookies(std::vector<HTTPCookie>& cookies) const; virtual void write(std::ostream& ostr) const; virtual void read(std::istream& istr); static const std::string& getReasonForStatus(HTTPStatus status); }; // direct descendants class HTTPServerResponse;
Inherited Members
public: // typedefs typedef Poco::ListMap<std::string, std::string> HeaderMap; typedef HeaderMap::Iterator Iterator; typedef HeaderMap::ConstIterator ConstIterator; // fields static const std::string HTTP_1_0; static const std::string HTTP_1_1; static const std::string IDENTITY_TRANSFER_ENCODING; static const std::string CHUNKED_TRANSFER_ENCODING; static const int UNKNOWN_CONTENT_LENGTH; static const std::string UNKNOWN_CONTENT_TYPE; static const std::string CONTENT_LENGTH; static const std::string CONTENT_TYPE; static const std::string TRANSFER_ENCODING; static const std::string CONNECTION; static const std::string CONNECTION_KEEP_ALIVE; static const std::string CONNECTION_CLOSE; static const std::string EMPTY; // methods NameValueCollection& operator=(const NameValueCollection& nvc); void swap(NameValueCollection& nvc); const std::string& operator[](const std::string& name) const; void set( const std::string& name, const std::string& value ); void add( const std::string& name, const std::string& value ); const std::string& get(const std::string& name) const; const std::string& get( const std::string& name, const std::string& defaultValue ) const; bool has(const std::string& name) const; ConstIterator find(const std::string& name) const; ConstIterator begin() const; ConstIterator end() const; bool empty() const; std::size_t size() const; void erase(const std::string& name); void clear(); MessageHeader& operator=(const MessageHeader& messageHeader); virtual void write(std::ostream& ostr) const; virtual void read(std::istream& istr); int getFieldLimit() const; void setFieldLimit(int limit); bool hasToken( const std::string& fieldName, const std::string& token ) const; static void splitElements( const std::string& s, std::vector<std::string>& elements, bool ignoreEmpty = true ); static void splitParameters( const std::string& s, std::string& value, NameValueCollection& parameters ); static void splitParameters( const std::string::const_iterator& begin, const std::string::const_iterator& end, NameValueCollection& parameters ); static void quote( const std::string& value, std::string& result, bool allowSpace = false ); void setVersion(const std::string& version); const std::string& getVersion() const; void setContentLength(std::streamsize length); std::streamsize getContentLength() const; bool hasContentLength() const; void setTransferEncoding(const std::string& transferEncoding); const std::string& getTransferEncoding() const; void setChunkedTransferEncoding(bool flag); bool getChunkedTransferEncoding() const; void setContentType(const std::string& mediaType); void setContentType(const MediaType& mediaType); const std::string& getContentType() const; void setKeepAlive(bool keepAlive); bool getKeepAlive() const;
Detailed Documentation
This class encapsulates an HTTP response message.
In addition to the properties common to all HTTP messages, a HTTP response has status code and a reason phrase.
Construction
HTTPResponse()
Creates the HTTPResponse with OK status.
HTTPResponse( HTTPStatus status, const std::string& reason )
Creates the HTTPResponse with the given status and reason phrase.
HTTPResponse( const std::string& version, HTTPStatus status, const std::string& reason )
Creates the HTTPResponse with the given version, status and reason phrase.
HTTPResponse(HTTPStatus status)
Creates the HTTPResponse with the given status an an appropriate reason phrase.
HTTPResponse( const std::string& version, HTTPStatus status )
Creates the HTTPResponse with the given version, status an an appropriate reason phrase.
Methods
void setStatus(HTTPStatus status)
Sets the HTTP status code.
Does not change the reason phrase.
HTTPStatus getStatus() const
Returns the HTTP status code.
void setStatus(const std::string& status)
Sets the HTTP status code.
The string must contain a valid HTTP numerical status code.
void setReason(const std::string& reason)
Sets the HTTP reason phrase.
const std::string& getReason() const
Returns the HTTP reason phrase.
void setStatusAndReason( HTTPStatus status, const std::string& reason )
Sets the HTTP status code and reason phrase.
void setStatusAndReason(HTTPStatus status)
Sets the HTTP status code and reason phrase.
The reason phrase is set according to the status code.
void setDate(const Poco::Timestamp& dateTime)
Sets the Date header to the given date/time value.
Poco::Timestamp getDate() const
Returns the value of the Date header.
void addCookie(const HTTPCookie& cookie)
Adds the cookie to the response by adding a Set-Cookie header.
void getCookies(std::vector<HTTPCookie>& cookies) const
Returns a vector with all the cookies set in the response header.
May throw an exception in case of a malformed Set-Cookie header.
virtual void write(std::ostream& ostr) const
Writes the HTTP response to the given output stream.
virtual void read(std::istream& istr)
Reads the HTTP response from the given input stream.
100 Continue responses are ignored.
static const std::string& getReasonForStatus(HTTPStatus status)
Returns an appropriate reason phrase for the given status code.