pub trait HttpClient:
Send
+ Sync
+ Debug {
// Required method
fn http_connector(
&self,
settings: &HttpConnectorSettings,
components: &RuntimeComponents,
) -> SharedHttpConnector;
// Provided methods
fn validate_base_client_config(
&self,
runtime_components: &RuntimeComponentsBuilder,
cfg: &ConfigBag,
) -> Result<(), Box<dyn Error + Sync + Send>> { ... }
fn validate_final_config(
&self,
runtime_components: &RuntimeComponents,
cfg: &ConfigBag,
) -> Result<(), Box<dyn Error + Sync + Send>> { ... }
fn connector_metadata(&self) -> Option<ConnectorMetadata> { ... }
}
Expand description
HTTP client abstraction.
A HTTP client implementation must apply connect/read timeout settings, and must maintain a connection pool.
Required Methods§
Sourcefn http_connector(
&self,
settings: &HttpConnectorSettings,
components: &RuntimeComponents,
) -> SharedHttpConnector
fn http_connector( &self, settings: &HttpConnectorSettings, components: &RuntimeComponents, ) -> SharedHttpConnector
Returns a HTTP connector based on the requested connector settings.
The settings include connector timeouts, which should be incorporated
into the connector. The HttpClient
is responsible for caching
the connector across requests.
In the future, the settings may have additional parameters added, such as HTTP version, or TLS certificate paths.
Provided Methods§
Sourcefn validate_base_client_config(
&self,
runtime_components: &RuntimeComponentsBuilder,
cfg: &ConfigBag,
) -> Result<(), Box<dyn Error + Sync + Send>>
fn validate_base_client_config( &self, runtime_components: &RuntimeComponentsBuilder, cfg: &ConfigBag, ) -> Result<(), Box<dyn Error + Sync + Send>>
Validate the base client configuration.
This gets called upon client construction. The full config may not be available at
this time (hence why it has RuntimeComponentsBuilder
as an argument rather
than RuntimeComponents
). Any error returned here will become a panic
in the client constructor.
Sourcefn validate_final_config(
&self,
runtime_components: &RuntimeComponents,
cfg: &ConfigBag,
) -> Result<(), Box<dyn Error + Sync + Send>>
fn validate_final_config( &self, runtime_components: &RuntimeComponents, cfg: &ConfigBag, ) -> Result<(), Box<dyn Error + Sync + Send>>
Validate the final client configuration.
This gets called immediately after the Intercept::read_before_execution
trait hook
when the final configuration has been resolved. Any error returned here will
cause the operation to return that error.
Sourcefn connector_metadata(&self) -> Option<ConnectorMetadata>
fn connector_metadata(&self) -> Option<ConnectorMetadata>
Provide metadata about the crate that this HttpClient uses to make connectors.
If this is implemented and returns metadata, interceptors may inspect it for the purpose of inserting that data into the user agent string when making a request with this client.