pub struct HttpClientBuilder<L = Identity> { /* private fields */ }
Expand description
HTTP client builder.
§Examples
use jsonrpsee_http_client::{HttpClientBuilder, HeaderMap, HeaderValue};
#[tokio::main]
async fn main() {
// Build custom headers used for every submitted request.
let mut headers = HeaderMap::new();
headers.insert("Any-Header-You-Like", HeaderValue::from_static("42"));
// Build client
let client = HttpClientBuilder::default()
.set_headers(headers)
.build("http://localhost")
.unwrap();
// use client....
}
Implementations§
source§impl<L> HttpClientBuilder<L>
impl<L> HttpClientBuilder<L>
sourcepub fn max_request_size(self, size: u32) -> Self
pub fn max_request_size(self, size: u32) -> Self
Set the maximum size of a request body in bytes. Default is 10 MiB.
sourcepub fn max_response_size(self, size: u32) -> Self
pub fn max_response_size(self, size: u32) -> Self
Set the maximum size of a response in bytes. Default is 10 MiB.
sourcepub fn request_timeout(self, timeout: Duration) -> Self
pub fn request_timeout(self, timeout: Duration) -> Self
Set request timeout (default is 60 seconds).
sourcepub fn max_concurrent_requests(self, max_concurrent_requests: usize) -> Self
pub fn max_concurrent_requests(self, max_concurrent_requests: usize) -> Self
Set the maximum number of concurrent requests. Default disabled.
sourcepub fn with_custom_cert_store(self, cfg: CustomCertStore) -> Self
pub fn with_custom_cert_store(self, cfg: CustomCertStore) -> Self
Force to use the rustls native certificate store.
Since multiple certificate stores can be optionally enabled, this option will
force the native certificate store
to be used.
§Optional
This requires the optional tls
feature.
§Example
use jsonrpsee_http_client::{HttpClientBuilder, CustomCertStore};
use rustls::{
client::danger::{self, HandshakeSignatureValid, ServerCertVerified},
pki_types::{CertificateDer, ServerName, UnixTime},
Error,
};
#[derive(Debug)]
struct NoCertificateVerification;
impl rustls::client::danger::ServerCertVerifier for NoCertificateVerification {
fn verify_server_cert(
&self,
_: &CertificateDer<'_>,
_: &[CertificateDer<'_>],
_: &ServerName<'_>,
_: &[u8],
_: UnixTime,
) -> Result<ServerCertVerified, Error> {
Ok(ServerCertVerified::assertion())
}
fn supported_verify_schemes(&self) -> Vec<rustls::SignatureScheme> {
vec![rustls::SignatureScheme::ECDSA_NISTP256_SHA256]
}
fn verify_tls12_signature(
&self,
_: &[u8],
_: &CertificateDer<'_>,
_: &rustls::DigitallySignedStruct,
) -> Result<rustls::client::danger::HandshakeSignatureValid, Error> {
Ok(HandshakeSignatureValid::assertion())
}
fn verify_tls13_signature(
&self,
_: &[u8],
_: &CertificateDer<'_>,
_: &rustls::DigitallySignedStruct,
) -> Result<HandshakeSignatureValid, Error> {
Ok(HandshakeSignatureValid::assertion())
}
}
let tls_cfg = CustomCertStore::builder()
.dangerous()
.with_custom_certificate_verifier(std::sync::Arc::new(NoCertificateVerification))
.with_no_client_auth();
// client builder with disabled certificate verification.
let client_builder = HttpClientBuilder::new().with_custom_cert_store(tls_cfg);
sourcepub fn id_format(self, id_kind: IdKind) -> Self
pub fn id_format(self, id_kind: IdKind) -> Self
Configure the data type of the request object ID (default is number).
sourcepub fn set_max_logging_length(self, max: u32) -> Self
pub fn set_max_logging_length(self, max: u32) -> Self
Max length for logging for requests and responses in number characters.
Logs bigger than this limit will be truncated.
sourcepub fn set_headers(self, headers: HeaderMap) -> Self
pub fn set_headers(self, headers: HeaderMap) -> Self
Set a custom header passed to the server with every request (default is none).
The caller is responsible for checking that the headers do not conflict or are duplicated.
sourcepub fn set_tcp_no_delay(self, no_delay: bool) -> Self
pub fn set_tcp_no_delay(self, no_delay: bool) -> Self
Configure TCP_NODELAY
on the socket to the supplied value nodelay
.
Default is true
.
sourcepub fn set_http_middleware<T>(
self,
service_builder: ServiceBuilder<T>,
) -> HttpClientBuilder<T>
pub fn set_http_middleware<T>( self, service_builder: ServiceBuilder<T>, ) -> HttpClientBuilder<T>
Set custom tower middleware.
source§impl<B, S, L> HttpClientBuilder<L>
impl<B, S, L> HttpClientBuilder<L>
source§impl HttpClientBuilder<Identity>
impl HttpClientBuilder<Identity>
sourcepub fn new() -> HttpClientBuilder<Identity>
pub fn new() -> HttpClientBuilder<Identity>
Create a new builder.