Github   Telegram
Loading...
Searching...
No Matches
Public Member Functions | List of all members
clients::http::Client Class Referencefinal

HTTP client that returns a HTTP request builder from CreateRequest(). More...

#include <userver/clients/http/client.hpp>

Public Member Functions

 Client (ClientSettings settings, engine::TaskProcessor &fs_task_processor)
 
std::shared_ptr< RequestCreateRequest ()
 Returns a HTTP request builder type with preset values of User-Agent, Proxy and some of the Testsuite suff (if any).
 
std::shared_ptr< RequestCreateNotSignedRequest ()
 Providing CreateNonSignedRequest() function for the clients::Http alias. More...
 
void ResetUserAgent (std::optional< std::string > user_agent=std::nullopt)
 Sets User-Agent headers for all the requests or removes that header. More...
 
std::string GetProxy () const
 Returns the current proxy that is automatically used for each request. More...
 
void SetDnsResolver (clients::dns::Resolver *resolver)
 Sets the DNS resolver to use. More...
 

Detailed Description

HTTP client that returns a HTTP request builder from CreateRequest().

Usually retrieved from components::HttpClient component.

Example usage:

const auto response = http_client.CreateRequest()
->post(url, data)
->timeout(std::chrono::seconds(1))
->perform();
EXPECT_TRUE(response->IsOk());
Examples
samples/flatbuf_service/flatbuf_service.cpp, and samples/http_caching/http_caching.cpp.

Definition at line 67 of file client.hpp.

Member Function Documentation

◆ CreateNotSignedRequest()

std::shared_ptr< Request > clients::http::Client::CreateNotSignedRequest ( )
inline

Providing CreateNonSignedRequest() function for the clients::Http alias.

Definition at line 77 of file client.hpp.

◆ GetProxy()

std::string clients::http::Client::GetProxy ( ) const

Returns the current proxy that is automatically used for each request.

Warning
The value may become immediately obsole as the proxy could be concurrently changed from runtime config.

◆ ResetUserAgent()

void clients::http::Client::ResetUserAgent ( std::optional< std::string >  user_agent = std::nullopt)

Sets User-Agent headers for all the requests or removes that header.

By default User-Agent is set by components::HttpClient to the userver identity string.

◆ SetDnsResolver()

void clients::http::Client::SetDnsResolver ( clients::dns::Resolver resolver)

Sets the DNS resolver to use.

If given nullptr, the default resolver will be used (most likely getaddrinfo).


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