Poco::Net

class HTTPRequest

Library: Net
Package: HTTP
Header: Poco/Net/HTTPRequest.h

Description

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.

Inheritance

Direct Base Classes: HTTPMessage

All Base Classes: HTTPMessage, MessageHeader, NameValueCollection

Known Derived Classes: HTTPServerRequestImpl, HTTPServerRequest

Member Summary

Member Functions: getCookies, getCredentials, getHost, getMethod, getURI, hasCredentials, read, setCookies, setCredentials, setHost, setMethod, setURI, write

Inherited Functions: add, begin, clear, empty, end, erase, find, get, getChunkedTransferEncoding, getContentLength, getContentType, getKeepAlive, getTransferEncoding, getVersion, has, operator, operator =, quote, read, set, setChunkedTransferEncoding, setContentLength, setContentType, setKeepAlive, setTransferEncoding, setVersion, size, splitElements, splitParameters, swap, write

Constructors

HTTPRequest

HTTPRequest();

Creates a GET / HTTP/1.0 HTTP request.

HTTPRequest

HTTPRequest(
    const std::string & version
);

Creates a GET / HTTP/1.x request with the given version (HTTP/1.0 or HTTP/1.1).

HTTPRequest

HTTPRequest(
    const std::string & method,
    const std::string & uri
);

Creates a HTTP/1.0 request with the given method and URI.

HTTPRequest

HTTPRequest(
    const std::string & method,
    const std::string & uri,
    const std::string & version
);

Creates a HTTP request with the given method, URI and version.

Destructor

~HTTPRequest virtual

virtual ~HTTPRequest();

Destroys the HTTPRequest.

Member Functions

getCookies

void getCookies(
    NameValueCollection & cookies
) const;

Fills cookies with the cookies extracted from the Cookie headers in the request.

getCredentials

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.

getHost

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.

getMethod inline

const std::string & getMethod() const;

Returns the method.

getURI inline

const std::string & getURI() const;

Returns the request URI.

hasCredentials

bool hasCredentials() const;

Returns true iff the request contains authentication information in the form of an Authorization header.

read virtual

void read(
    std::istream & istr
);

Reads the HTTP request from the given input stream.

See also: Poco::Net::MessageHeader::read()

setCookies

void setCookies(
    const NameValueCollection & cookies
);

Adds a Cookie header with the names and values from cookies.

setCredentials

void setCredentials(
    const std::string & scheme,
    const std::string & authInfo
);

Sets the authentication scheme and information for this request.

setHost

void setHost(
    const std::string & host
);

Sets the value of the Host header field.

setHost

void setHost(
    const std::string & host,
    Poco::UInt16 port
);

Sets the value of the Host header field.

setMethod

void setMethod(
    const std::string & method
);

Sets the method.

setURI

void setURI(
    const std::string & uri
);

Sets the request URI.

write virtual

void write(
    std::ostream & ostr
) const;

Writes the HTTP request to the given output stream.

See also: Poco::Net::MessageHeader::write()

Variables

AUTHORIZATION static

static const std::string AUTHORIZATION;

COOKIE static

static const std::string COOKIE;

HOST static

static const std::string HOST;

HTTP_CONNECT static

static const std::string HTTP_CONNECT;

HTTP_DELETE static

static const std::string HTTP_DELETE;

HTTP_GET static

static const std::string HTTP_GET;

HTTP_HEAD static

static const std::string HTTP_HEAD;

HTTP_OPTIONS static

static const std::string HTTP_OPTIONS;

HTTP_POST static

static const std::string HTTP_POST;

HTTP_PUT static

static const std::string HTTP_PUT;

HTTP_TRACE static

static const std::string HTTP_TRACE;