HTTP module

Request

HTTP request message with method, URI, headers, and optional body.

Request

#include <icy/http/request.h>

Inherits: Message

HTTP request message with method, URI, headers, and optional body.

In addition to the properties common to all HTTP messages, an HTTP request has a method (e.g. GET, HEAD, POST, etc.) and a request URI.

Public Methods

ReturnNameDescription
RequestCreates a GET / HTTP/1.1 HTTP request.
RequestCreates a GET / HTTP/1.x request with the given version (HTTP/1.0 or HTTP/1.1).
RequestCreates an HTTP/1.0 request with the given method and URI.
RequestCreates an HTTP request with the given method, URI and version.
~Request virtualDestroys the Request.
voidsetMethodSets the method.
const std::string &getMethod constReturns the method.
voidsetURISets the request URI.
voidappendURIAppends a fragment to the request URI. Used by the parser when llhttp splits the URL across callbacks.
const std::string &getURI constReturns the request URI.
voidsetHostSets the value of the Host header field.
voidsetHostSets the value of the Host header field.
const std::string &getHost constReturns the value of the Host header field.
voidsetCookiesAdds a Cookie header with the names and values from cookies.
voidgetCookies constFills cookies with the cookies extracted from the Cookie headers in the request.
voidgetURIParameters constReturns the request URI parameters.
boolhasCredentials constReturns true if the request contains authentication information in the form of an Authorization header.
voidgetCredentials constReturns the authentication scheme and additional authentication information contained in this request.
voidsetCredentialsSets the authentication scheme and information for this request.
boolhasProxyCredentials constReturns true if the request contains proxy authentication information in the form of an Proxy-Authorization header.
voidgetProxyCredentials constReturns the proxy authentication scheme and additional proxy authentication information contained in this request.
voidsetProxyCredentialsSets the proxy authentication scheme and information for this request.
voidwrite virtual constWrites the HTTP request to the given output stream.
voidwrite virtual constWrites the HTTP request to the given output string.
voidwrite virtual constWrites the HTTP request directly into a byte buffer.

Request

Request()

Creates a GET / HTTP/1.1 HTTP request.


Request

Request(const std::string & version)

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


Request

Request(const std::string & method, const std::string & uri)

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


Request

Request(const std::string & method, const std::string & uri, const std::string & version)

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


~Request

virtual

virtual ~Request()

Destroys the Request.


setMethod

void setMethod(const std::string & method)

Sets the method.


getMethod

const

const std::string & getMethod() const

Returns the method.


setURI

void setURI(std::string uri)

Sets the request URI.


appendURI

void appendURI(std::string_view uri)

Appends a fragment to the request URI. Used by the parser when llhttp splits the URL across callbacks.


getURI

const

const std::string & getURI() const

Returns the request URI.


setHost

void setHost(const std::string & host)

Sets the value of the Host header field.


setHost

void setHost(const std::string & host, uint16_t 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.


getHost

const

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.


setCookies

void setCookies(const NVCollection & cookies)

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


getCookies

const

void getCookies(NVCollection & cookies) const

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


getURIParameters

const

void getURIParameters(NVCollection & params) const

Returns the request URI parameters.


hasCredentials

const

bool hasCredentials() const

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


getCredentials

const

void getCredentials(std::string & scheme, std::string & authInfo) const

Returns the authentication scheme and additional authentication information contained in this request.

Throws a std::exception if no authentication information is contained in the request.


setCredentials

void setCredentials(std::string_view scheme, std::string_view authInfo)

Sets the authentication scheme and information for this request.


hasProxyCredentials

const

bool hasProxyCredentials() const

Returns true if the request contains proxy authentication information in the form of an Proxy-Authorization header.


getProxyCredentials

const

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 std::exception if no proxy authentication information is contained in the request.


setProxyCredentials

void setProxyCredentials(std::string_view scheme, std::string_view authInfo)

Sets the proxy authentication scheme and information for this request.


write

virtual const

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

Writes the HTTP request to the given output stream.


write

virtual const

virtual void write(std::string & str) const

Writes the HTTP request to the given output string.


write

virtual const

virtual void write(Buffer & buf) const

Writes the HTTP request directly into a byte buffer.

Protected Methods

ReturnNameDescription
voidgetCredentials constReturns the authentication scheme and additional authentication information contained in the given header of request.
voidsetCredentialsWrites the authentication scheme and information for this request to the given header.

getCredentials

const

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.


setCredentials

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

Writes the authentication scheme and information for this request to the given header.

Private Attributes

ReturnNameDescription
std::string_method
std::string_uri

_method

std::string _method

_uri

std::string _uri