join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicHttpClient< Protocol > Class Template Reference

basic HTTP client. More...

#include <httpclient.hpp>

Inheritance diagram for join::BasicHttpClient< Protocol >:
Collaboration diagram for join::BasicHttpClient< Protocol >:

Public Types

using Endpoint = typename Protocol::Endpoint
 

Public Member Functions

 BasicHttpClient (const char *host, uint16_t port=80, bool keepAlive=true)
 create the basic HTTP client instance.
 
 BasicHttpClient (const std::string &host, uint16_t port=80, bool keepAlive=true)
 create the basic HTTP client instance.
 
 BasicHttpClient (const BasicHttpClient &other)=delete
 create the basic HTTP client instance by copy.
 
BasicHttpClientoperator= (const BasicHttpClient &other)=delete
 assign the basic HTTP client instance by copy.
 
 BasicHttpClient (BasicHttpClient &&other)
 create the basic HTTP client instance by move.
 
BasicHttpClientoperator= (BasicHttpClient &&other)
 assign the basic HTTP client instance by move.
 
virtual ~BasicHttpClient ()
 destroy the basic HTTP client instance.
 
void close () override
 close the connection.
 
virtual std::string scheme () const
 get HTTP scheme.
 
const std::string & host () const
 get host.
 
uint16_t port () const
 get port.
 
std::string authority () const
 get authority.
 
std::string url () const
 get URL.
 
bool keepAlive () const
 checks if HTTP keep alive is supported.
 
void keepAlive (bool keep)
 enable/disable HTTP keep alive support.
 
std::chrono::seconds keepAliveTimeout () const
 get HTTP keep alive timeout.
 
int keepAliveMax () const
 get HTTP keep alive max.
 
int send (HttpRequest &request)
 send HTTP request.
 
int receive (HttpResponse &response)
 receive HTTP response.
 

Protected Member Functions

void setEncoding (const std::vector< std::string > &encodings)
 set stream encoding.
 
void clearEncoding ()
 clear stream encoding.
 
bool expired () const
 check if HTTP keep alive is expired.
 
bool needReconnection ()
 check if client must reconnect.
 
virtual void reconnect (const Endpoint &endpoint)
 perform reconnection to the given endpoint.
 

Protected Attributes

std::streambuf * _streambuf = nullptr
 HTTP stream buffer.
 
bool _wrapped = false
 HTTP stream status.
 
std::chrono::time_point< std::chrono::steady_clock > _timestamp
 HTTP timestamp.
 
std::string _host
 HTTP host.
 
uint16_t _port
 HTTP port.
 
bool _keep
 HTTP keep alive.
 
std::chrono::seconds _keepTimeout
 HTTP keep alive timeout.
 
int _keepMax = -1
 HTTP keep alive max.
 

Detailed Description

template<class Protocol>
class join::BasicHttpClient< Protocol >

basic HTTP client.

Member Typedef Documentation

◆ Endpoint

template<class Protocol >
using join::BasicHttpClient< Protocol >::Endpoint = typename Protocol::Endpoint

Constructor & Destructor Documentation

◆ BasicHttpClient() [1/4]

template<class Protocol >
join::BasicHttpClient< Protocol >::BasicHttpClient ( const char * host,
uint16_t port = 80,
bool keepAlive = true )
inline

create the basic HTTP client instance.

Parameters
hosthost.
portport (default: 80).
keepAliveuse a persistent connection.

◆ BasicHttpClient() [2/4]

template<class Protocol >
join::BasicHttpClient< Protocol >::BasicHttpClient ( const std::string & host,
uint16_t port = 80,
bool keepAlive = true )
inline

create the basic HTTP client instance.

Parameters
hosthost.
portport (default: 80).
keepAliveuse a persistent connection.

◆ BasicHttpClient() [3/4]

template<class Protocol >
join::BasicHttpClient< Protocol >::BasicHttpClient ( const BasicHttpClient< Protocol > & other)
delete

create the basic HTTP client instance by copy.

Parameters
otherrequest to copy.

◆ BasicHttpClient() [4/4]

template<class Protocol >
join::BasicHttpClient< Protocol >::BasicHttpClient ( BasicHttpClient< Protocol > && other)
inline

create the basic HTTP client instance by move.

Parameters
otherrequest to move.

◆ ~BasicHttpClient()

template<class Protocol >
virtual join::BasicHttpClient< Protocol >::~BasicHttpClient ( )
inlinevirtual

destroy the basic HTTP client instance.

Member Function Documentation

◆ authority()

template<class Protocol >
std::string join::BasicHttpClient< Protocol >::authority ( ) const
inline

get authority.

Returns
authority.

◆ clearEncoding()

template<class Protocol >
void join::BasicHttpClient< Protocol >::clearEncoding ( )
inlineprotected

clear stream encoding.

◆ close()

template<class Protocol >
void join::BasicHttpClient< Protocol >::close ( )
inlineoverride

close the connection.

Exceptions
std::ios_base::failure.

◆ expired()

template<class Protocol >
bool join::BasicHttpClient< Protocol >::expired ( ) const
inlineprotected

check if HTTP keep alive is expired.

Returns
true if HTTP keep alive is expired.

◆ host()

template<class Protocol >
const std::string & join::BasicHttpClient< Protocol >::host ( ) const
inline

get host.

Returns
host.

◆ keepAlive() [1/2]

template<class Protocol >
bool join::BasicHttpClient< Protocol >::keepAlive ( ) const
inline

checks if HTTP keep alive is supported.

Returns
true if supported, false otherwise.

◆ keepAlive() [2/2]

template<class Protocol >
void join::BasicHttpClient< Protocol >::keepAlive ( bool keep)
inline

enable/disable HTTP keep alive support.

Parameters
keeptrue if supported, false otherwise.

◆ keepAliveMax()

template<class Protocol >
int join::BasicHttpClient< Protocol >::keepAliveMax ( ) const
inline

get HTTP keep alive max.

Returns
HTTP keep alive max.

◆ keepAliveTimeout()

template<class Protocol >
std::chrono::seconds join::BasicHttpClient< Protocol >::keepAliveTimeout ( ) const
inline

get HTTP keep alive timeout.

Returns
HTTP keep alive timeout.

◆ needReconnection()

template<class Protocol >
bool join::BasicHttpClient< Protocol >::needReconnection ( )
inlineprotected

check if client must reconnect.

Returns
true if reconnection is required.

◆ operator=() [1/2]

template<class Protocol >
BasicHttpClient & join::BasicHttpClient< Protocol >::operator= ( BasicHttpClient< Protocol > && other)
inline

assign the basic HTTP client instance by move.

Parameters
otherrequest to move.
Returns
a reference of the current object.

◆ operator=() [2/2]

template<class Protocol >
BasicHttpClient & join::BasicHttpClient< Protocol >::operator= ( const BasicHttpClient< Protocol > & other)
delete

assign the basic HTTP client instance by copy.

Parameters
otherrequest to copy.
Returns
a reference of the current object.

◆ port()

template<class Protocol >
uint16_t join::BasicHttpClient< Protocol >::port ( ) const
inline

get port.

Returns
port.

◆ receive()

template<class Protocol >
int join::BasicHttpClient< Protocol >::receive ( HttpResponse & response)
inline

receive HTTP response.

Parameters
responseHTTP response received.
Returns
0 on success, -1 on failure.

◆ reconnect()

template<class Protocol >
virtual void join::BasicHttpClient< Protocol >::reconnect ( const Endpoint & endpoint)
inlineprotectedvirtual

perform reconnection to the given endpoint.

Parameters
endpointendpoint to connect to.

Reimplemented in join::BasicHttpSecureClient< Protocol >.

◆ scheme()

template<class Protocol >
virtual std::string join::BasicHttpClient< Protocol >::scheme ( ) const
inlinevirtual

get HTTP scheme.

Returns
htpp or https.

Reimplemented in join::BasicHttpSecureClient< Protocol >.

◆ send()

template<class Protocol >
int join::BasicHttpClient< Protocol >::send ( HttpRequest & request)
inline

send HTTP request.

Parameters
requestHTTP request to send.
Returns
0 on success, -1 on failure.

◆ setEncoding()

template<class Protocol >
void join::BasicHttpClient< Protocol >::setEncoding ( const std::vector< std::string > & encodings)
inlineprotected

set stream encoding.

Parameters
encodingsencodings applied to the stream.

◆ url()

template<class Protocol >
std::string join::BasicHttpClient< Protocol >::url ( ) const
inline

get URL.

Returns
URL.

Member Data Documentation

◆ _host

template<class Protocol >
std::string join::BasicHttpClient< Protocol >::_host
protected

HTTP host.

◆ _keep

template<class Protocol >
bool join::BasicHttpClient< Protocol >::_keep
protected

HTTP keep alive.

◆ _keepMax

template<class Protocol >
int join::BasicHttpClient< Protocol >::_keepMax = -1
protected

HTTP keep alive max.

◆ _keepTimeout

template<class Protocol >
std::chrono::seconds join::BasicHttpClient< Protocol >::_keepTimeout
protected

HTTP keep alive timeout.

◆ _port

template<class Protocol >
uint16_t join::BasicHttpClient< Protocol >::_port
protected

HTTP port.

◆ _streambuf

template<class Protocol >
std::streambuf* join::BasicHttpClient< Protocol >::_streambuf = nullptr
protected

HTTP stream buffer.

◆ _timestamp

template<class Protocol >
std::chrono::time_point<std::chrono::steady_clock> join::BasicHttpClient< Protocol >::_timestamp
protected

HTTP timestamp.

◆ _wrapped

template<class Protocol >
bool join::BasicHttpClient< Protocol >::_wrapped = false
protected

HTTP stream status.


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