Class HTTP::Request#

Nested Relationships#

This class is a nested type of Class HTTP.

Class Documentation#

class Request

Define a HTTP request.

Public Types

enum class Method

Enumerate the available HTTP methods for a request.

Values:

enumerator GET
enumerator POST
enumerator HEAD
enumerator PUT
enumerator DELETE

Public Functions

explicit Request(std::string uri = "/", Method method = Method::GET, std::string body = "")

Constructor.

This constructor creates a GET request, with the root URI (“/”) and an empty body.

Parameters:
  • uri – Target URI.

  • method – Method to use for the request.

  • body – Content of the request’s body.

Request(const Request&) = default

Copy constructor.

Request &operator=(const Request&) = default

Copy assignment operator.

Request(Request&&) noexcept = default

Move constructor.

Request &operator=(Request&&) noexcept = default

Move assignment operator.

~Request() = default

Destructor.

void SetField(const std::string &field, const std::string &value)

Set the value of a field.

The field is created if it doesn’t exist. The name of the field is case-insensitive. By default, a request doesn’t contain any field (but the mandatory fields are added later by the HTTP client when sending the request).

Parameters:
  • field – Name of the field to set.

  • value – Value of the field.

constexpr void SetMethod(Method method) noexcept

Set the request method.

See the Method enumeration for a complete list of all the available methods. The method is HTTP::Request::GET by default.

Parameters:

method – Method to use for the request.

constexpr void SetURI(std::string uri)

Set the requested URI.

The URI is the resource (usually a web page or a file) that you want to get or post. The URI is “/” (the root page) by default.

Parameters:

uri – URI to request, relative to the host.

constexpr void SetHTTPVersion(u32 major, u32 minor) noexcept

Set the HTTP version for the request.

The HTTP version is 1.0 by default.

Parameters:
  • major – Major HTTP version number.

  • minor – Minor HTTP version number.

constexpr void SetBody(std::string body)

Set the body of the request.

The body of a request is optional and only makes sense for POST requests. It is ignored for all other methods. The body is empty by default.

Parameters:

body – Content of the body.