class Poco::Net::HTTPRequest
Overview
This class encapsulates an HTTP request message. More…
#include <HTTPRequest.h> class HTTPRequest: public Poco::Net::HTTPMessage { public: // fields static const std::string HTTP_GET; static const std::string HTTP_HEAD; static const std::string HTTP_PUT; static const std::string HTTP_POST; static const std::string HTTP_OPTIONS; static const std::string HTTP_DELETE; static const std::string HTTP_TRACE; static const std::string HTTP_CONNECT; static const std::string HTTP_PATCH; static const std::string HOST; static const std::string COOKIE; static const std::string AUTHORIZATION; static const std::string PROXY_AUTHORIZATION; static const std::string UPGRADE; // construction HTTPRequest(); HTTPRequest(const std::string& version); HTTPRequest( const std::string& method, const std::string& uri ); HTTPRequest( const std::string& method, const std::string& uri, const std::string& version ); // methods void setMethod(const std::string& method); const std::string& getMethod() const; void setURI(const std::string& uri); const std::string& getURI() const; void setHost(const std::string& host); void setHost( const std::string& host, Poco::UInt16 port ); const std::string& getHost() const; void setCookies(const NameValueCollection& cookies); void getCookies(NameValueCollection& cookies) const; bool hasCredentials() const; void getCredentials( std::string& scheme, std::string& authInfo ) const; void setCredentials( const std::string& scheme, const std::string& authInfo ); bool hasProxyCredentials() const; void getProxyCredentials( std::string& scheme, std::string& authInfo ) const; void setProxyCredentials( const std::string& scheme, const std::string& authInfo ); virtual void write(std::ostream& ostr) const; virtual void read(std::istream& istr); protected: // methods void getCredentials( const std::string& header, std::string& scheme, std::string& authInfo ) const; void setCredentials( const std::string& header, const std::string& scheme, const std::string& authInfo ); }; // direct descendants class HTTPServerRequest;
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 request message.
In addition to the properties common to all HTTP messages, a HTTP request has a method (e.g. GET, HEAD, POST, etc.) and a request URI.
Construction
HTTPRequest()
Creates a GET / HTTP/1.0 HTTP request.
HTTPRequest(const std::string& version)
Creates a GET / HTTP/1.x request with the given version (HTTP/1.0 or HTTP/1.1).
HTTPRequest( const std::string& method, const std::string& uri )
Creates a HTTP/1.0 request with the given method and URI.
HTTPRequest( const std::string& method, const std::string& uri, const std::string& version )
Creates a HTTP request with the given method, URI and version.
Methods
void setMethod(const std::string& method)
Sets the method.
const std::string& getMethod() const
Returns the method.
void setURI(const std::string& uri)
Sets the request URI.
const std::string& getURI() const
Returns the request URI.
void setHost(const std::string& host)
Sets the value of the Host header field.
void setHost( const std::string& host, Poco::UInt16 port )
Sets the value of the Host header field.
If the given port number is a non-standard port number (other than 80 or 443), it is included in the Host header field.
const std::string& getHost() const
Returns the value of the Host header field.
Throws a NotFoundException if the request does not have a Host header field.
void setCookies(const NameValueCollection& cookies)
Adds a Cookie header with the names and values from cookies.
void getCookies(NameValueCollection& cookies) const
Fills cookies with the cookies extracted from the Cookie headers in the request.
bool hasCredentials() const
Returns true iff the request contains authentication information in the form of an Authorization header.
void getCredentials( std::string& scheme, std::string& authInfo ) const
Returns the authentication scheme and additional authentication information contained in this request.
Throws a NotAuthenticatedException if no authentication information is contained in the request.
void setCredentials( const std::string& scheme, const std::string& authInfo )
Sets the authentication scheme and information for this request.
bool hasProxyCredentials() const
Returns true iff the request contains proxy authentication information in the form of an Proxy-Authorization header.
void getProxyCredentials( std::string& scheme, std::string& authInfo ) const
Returns the proxy authentication scheme and additional proxy authentication information contained in this request.
Throws a NotAuthenticatedException if no proxy authentication information is contained in the request.
void setProxyCredentials( const std::string& scheme, const std::string& authInfo )
Sets the proxy authentication scheme and information for this request.
virtual void write(std::ostream& ostr) const
Writes the HTTP request to the given output stream.
virtual void read(std::istream& istr)
Reads the HTTP request from the given input stream.
void getCredentials( const std::string& header, std::string& scheme, std::string& authInfo ) const
Returns the authentication scheme and additional authentication information contained in the given header of request.
Throws a NotAuthenticatedException if no authentication information is contained in the request.
void setCredentials( const std::string& header, const std::string& scheme, const std::string& authInfo )
Writes the authentication scheme and information for this request to the given header.