Static Public Member Functions | Public Member Functions | List of all members
HttpClient Class Reference

A simple HTTP client. More...

#include <HttpClient.hpp>

Inheritance diagram for HttpClient:
[legend]

Static Public Member Functions

static std::unique_ptr< HttpClientnewClient (const Resource::Url &url, std::string userAgent="Balau "+BalauVersion, const char *version="1.1")
 Create a new HTTP or HTTPS client, according to the supplied URL. More...
 
static std::unique_ptr< HttpClientnewClient (const std::string &url, std::string userAgent="Balau "+BalauVersion, const char *version="1.1")
 Create a new HTTP or HTTPS client, according to the supplied URL string. More...
 

Public Member Functions

 HttpClient (std::string host_, unsigned short port_=80, std::string userAgent_="Balau "+BalauVersion, const char *version_="1.1")
 Create an HTTP client instance. More...
 
 HttpClient (const HttpClient &)=default
 Create an HTTP client by copying the supplied instance. More...
 
 HttpClient (HttpClient &&)=default
 Create an HTTP client by moving the contents of the supplied instance. More...
 
virtual ~HttpClient ()=default
 Destroy the client instance. More...
 
virtual CharVectorResponse get (const std::string_view &path)
 Perform a GET request. More...
 
virtual EmptyResponse head (const std::string_view &path)
 Perform a HEAD request. More...
 
HttpClientoperator= (const HttpClient &)=default
 Assign an HTTP client by copying the supplied instance. More...
 
HttpClientoperator= (HttpClient &&)=default
 Assign an HTTP client by moving the contents of the supplied instance. More...
 
virtual CharVectorResponse post (const std::string_view &path, const std::string_view &body)
 Perform a POST request. More...
 

Detailed Description

A simple HTTP client.

Todo:
Add chunked transfer.

Constructor & Destructor Documentation

◆ HttpClient() [1/3]

HttpClient ( std::string  host_,
unsigned short  port_ = 80,
std::string  userAgent_ = "Balau " + BalauVersion,
const char *  version_ = "1.1" 
)
inlineexplicit

Create an HTTP client instance.

Parameters
host_the host name to connect to
port_the port number to connect to
userAgent_the user agent string to send
version_either "1.0" or "1.1" (the default)

◆ HttpClient() [2/3]

HttpClient ( const HttpClient )
default

Create an HTTP client by copying the supplied instance.

◆ HttpClient() [3/3]

HttpClient ( HttpClient &&  )
default

Create an HTTP client by moving the contents of the supplied instance.

◆ ~HttpClient()

virtual ~HttpClient ( )
virtualdefault

Destroy the client instance.

Member Function Documentation

◆ get()

virtual CharVectorResponse get ( const std::string_view &  path)
inlinevirtual

Perform a GET request.

Exceptions
NetworkExceptionif an invalid HTTP version was supplied to the client

Reimplemented in HttpsClient.

◆ head()

virtual EmptyResponse head ( const std::string_view &  path)
inlinevirtual

Perform a HEAD request.

Exceptions
NetworkExceptionif an invalid HTTP version was supplied to the client

Reimplemented in HttpsClient.

◆ newClient() [1/2]

static std::unique_ptr<HttpClient> newClient ( const Resource::Url url,
std::string  userAgent = "Balau "+BalauVersion,
const char *  version = "1.1" 
)
static

Create a new HTTP or HTTPS client, according to the supplied URL.

Parameters
urlthe url containing the scheme, host, and port information
userAgentthe user agent string to send
versioneither "1.0" or "1.1" (the default)
Exceptions
InvalidUriExceptionif the URI is not well formed
NetworkExceptionif host information is not provided in the URI or the scheme is not "http" or "https"

◆ newClient() [2/2]

static std::unique_ptr<HttpClient> newClient ( const std::string &  url,
std::string  userAgent = "Balau "+BalauVersion,
const char *  version = "1.1" 
)
static

Create a new HTTP or HTTPS client, according to the supplied URL string.

Parameters
urlthe url string containing the scheme, host, and port information
userAgentthe user agent string to send
versioneither "1.0" or "1.1" (the default)
Exceptions
InvalidUriExceptionif the URI is not well formed
NetworkExceptionif host information is not provided in the URI or the scheme is not "http" or "https"

◆ operator=() [1/2]

HttpClient& operator= ( const HttpClient )
default

Assign an HTTP client by copying the supplied instance.

◆ operator=() [2/2]

HttpClient& operator= ( HttpClient &&  )
default

Assign an HTTP client by moving the contents of the supplied instance.

◆ post()

virtual CharVectorResponse post ( const std::string_view &  path,
const std::string_view &  body 
)
inlinevirtual

Perform a POST request.

Exceptions
NetworkExceptionif an invalid HTTP version was supplied to the client

Reimplemented in HttpsClient.


The documentation for this class was generated from the following file: