userver: clients::http::Client Class Reference
Loading...
Searching...
No Matches
clients::http::Client Class Referencefinal

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

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.

Public Member Functions

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

Member Function Documentation

◆ CreateNotSignedRequest()

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 83 of file client.hpp.

◆ CreateRequest()

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: