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, impl::PluginPipeline &&plugin_pipeline)
 
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). More...
 
std::shared_ptr< RequestCreateNotSignedRequest ()
 
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...
 
void SetTracingManager (const tracing::TracingManagerBase &)
 

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 79 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.

Note
This method is thread-safe despite being non-const.

Definition at line 94 of file client.hpp.

◆ CreateRequest()

std::shared_ptr< Request > clients::http::Client::CreateRequest ( )

Returns a HTTP request builder type with preset values of User-Agent, Proxy and some of the Testsuite suff (if any).

Note
This method is thread-safe despite being non-const.

◆ 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: