class Poco::Net::HTTPMessage
Overview
The base class for HTTPRequest and HTTPResponse. More…
#include <HTTPMessage.h> class HTTPMessage: public Poco::Net::MessageHeader { public: // 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 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; protected: // construction HTTPMessage(); HTTPMessage(const std::string& version); }; // direct descendants class HTTPRequest; class HTTPResponse;
Inherited Members
public: // typedefs typedef Poco::ListMap<std::string, std::string> HeaderMap; typedef HeaderMap::Iterator Iterator; typedef HeaderMap::ConstIterator ConstIterator; // 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 );
Detailed Documentation
The base class for HTTPRequest and HTTPResponse.
Defines the common properties of all HTTP messages. These are version, content length, content type and transfer encoding.
Construction
HTTPMessage()
Creates the HTTPMessage with version HTTP/1.0.
HTTPMessage(const std::string& version)
Creates the HTTPMessage and sets the version.
Methods
void setVersion(const std::string& version)
Sets the HTTP version for this message.
const std::string& getVersion() const
Returns the HTTP version for this message.
void setContentLength(std::streamsize length)
Sets the Content-Length header.
If length is UNKNOWN_CONTENT_LENGTH, removes the Content-Length header.
std::streamsize getContentLength() const
Returns the content length for this message, which may be UNKNOWN_CONTENT_LENGTH if no Content-Length header is present.
bool hasContentLength() const
Returns true iff a Content-Length header is present.
void setTransferEncoding(const std::string& transferEncoding)
Sets the transfer encoding for this message.
The value should be either IDENTITY_TRANSFER_CODING or CHUNKED_TRANSFER_CODING.
const std::string& getTransferEncoding() const
Returns the transfer encoding used for this message.
Normally, this is the value of the Transfer-Encoding header field. If no such field is present, returns IDENTITY_TRANSFER_CODING.
void setChunkedTransferEncoding(bool flag)
If flag is true, sets the Transfer-Encoding header to chunked.
Otherwise, removes the Transfer-Encoding header.
bool getChunkedTransferEncoding() const
Returns true if the Transfer-Encoding header is set and its value is chunked.
void setContentType(const std::string& mediaType)
Sets the content type for this message.
Specify NO_CONTENT_TYPE to remove the Content-Type header.
void setContentType(const MediaType& mediaType)
Sets the content type for this message.
const std::string& getContentType() const
Returns the content type for this message.
If no Content-Type header is present, returns UNKNOWN_CONTENT_TYPE.
void setKeepAlive(bool keepAlive)
Sets the value of the Connection header field.
The value is set to “Keep-Alive” if keepAlive is true, or to “Close” otherwise.
bool getKeepAlive() const
Returns true if.
* the message has a Connection header field and its value is "Keep-Alive" * the message is a HTTP/1.1 message and not Connection header is set
Returns false otherwise.