Sese Framework  3.0.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::net::http::HttpClient Class Reference

HttpClient. More...

#include <HttpClient.h>

Classes

class  Impl
 HTTP/1.1 client based on ASIO. More...
 
class  SSLImpl
 HTTP/1.1 client based on ASIO. More...
 

Public Types

using WriteCallback = std::function<int64_t(const void *, size_t)>
 
using ReadCallback = std::function<int64_t(void *, size_t)>
 
using Ptr = std::unique_ptr<HttpClient>
 

Public Member Functions

 ~HttpClient ()
 
bool request () const
 
int getLastError () const
 
std::string getLastErrorString () const
 
int64_t read (void *buf, size_t len) const
 
int64_t write (const void *buf, size_t len) const
 
Request::PtrgetRequest () const
 
Response::PtrgetResponse () const
 
void setReadData (io::PeekableStream *read_data, size_t expect_total) const
 
void setWriteData (io::OutputStream *write_data) const
 
void setReadCallback (const ReadCallback &read_callback, size_t expect_total) const
 
void setWriteCallback (const WriteCallback &write_callback) const
 

Static Public Member Functions

static Ptr create (const std::string &url, const std::string &proxy="")
 

Private Member Functions

 HttpClient ()=default
 

Private Attributes

std::unique_ptr< Implimpl
 

Detailed Description

Member Typedef Documentation

◆ Ptr

using sese::net::http::HttpClient::Ptr = std::unique_ptr<HttpClient>

◆ ReadCallback

using sese::net::http::HttpClient::ReadCallback = std::function<int64_t(void *, size_t)>

◆ WriteCallback

using sese::net::http::HttpClient::WriteCallback = std::function<int64_t(const void *, size_t)>

Constructor & Destructor Documentation

◆ ~HttpClient()

sese::net::http::HttpClient::~HttpClient ( )

◆ HttpClient()

sese::net::http::HttpClient::HttpClient ( )
privatedefault

Member Function Documentation

◆ create()

HttpClient::Ptr sese::net::http::HttpClient::create ( const std::string & url,
const std::string & proxy = "" )
static

Create a new HttpClient

Parameters
urlURL to request
proxyProxy to use, empty string for no proxy
Returns
New HttpClient, nullptr if failed

References MAKE_UNIQUE_PRIVATE, sese::net::http::RequestParser::parse(), and sese::strcmpDoNotCase().

◆ getLastError()

int sese::net::http::HttpClient::getLastError ( ) const

Get the last error

Returns
Last error

References impl.

◆ getLastErrorString()

std::string sese::net::http::HttpClient::getLastErrorString ( ) const

Get the last error string

Returns
Last error string

References impl.

◆ getRequest()

Request::Ptr & sese::net::http::HttpClient::getRequest ( ) const

Get request headers

Returns
Request headers

References impl.

◆ getResponse()

Response::Ptr & sese::net::http::HttpClient::getResponse ( ) const

Get response headers

Returns
Response headers

References impl.

◆ read()

int64_t sese::net::http::HttpClient::read ( void * buf,
size_t len ) const

References impl.

◆ request()

bool sese::net::http::HttpClient::request ( ) const

Execute request

Returns
Request status

References impl.

◆ setReadCallback()

void sese::net::http::HttpClient::setReadCallback ( const ReadCallback & read_callback,
size_t expect_total ) const

Set the external source of the request body, this option will reset after the request is completed

Parameters
read_callbackCallback function to read the body, returns the size read, if incomplete reading, the transfer stops
expect_totalExpected size of the body

References impl.

◆ setReadData()

void sese::net::http::HttpClient::setReadData ( io::PeekableStream * read_data,
size_t expect_total ) const

Set the external source of the request body, this option will reset after the request is completed

Parameters
read_dataSource of the body to read
expect_totalExpected size of the body

References impl.

◆ setWriteCallback()

void sese::net::http::HttpClient::setWriteCallback ( const WriteCallback & write_callback) const

Set the external destination of the response body, this option will reset after the request is completed

Parameters
write_callbackCallback function to receive the body, returns the size written, if incomplete writing, the transfer stops

References impl.

◆ setWriteData()

void sese::net::http::HttpClient::setWriteData ( io::OutputStream * write_data) const

Set the external destination of the response body, this option will reset after the request is completed

Parameters
write_dataDestination to receive the body

References impl.

◆ write()

int64_t sese::net::http::HttpClient::write ( const void * buf,
size_t len ) const

References impl.

Member Data Documentation

◆ impl

std::unique_ptr<Impl> sese::net::http::HttpClient::impl
private

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