pub struct HttpClientLayer { /* private fields */ }
Expand description
Layer for replacing the default HTTP client with a custom one.
This layer allows users to provide their own HTTP client implementation
by implementing the HttpFetch
trait. This is useful when you need
to customize HTTP behavior, add authentication, use a different HTTP
client library, or apply custom middleware.
§Examples
use opendal::layers::HttpClientLayer;
use opendal::services;
use opendal::Operator;
use opendal::Result;
use opendal::raw::HttpClient;
// Create a custom HTTP client
let custom_client = HttpClient::new()?;
let op = Operator::new(services::S3::default())?
.layer(HttpClientLayer::new(custom_client))
.finish();
§Custom HTTP Client Implementation
use opendal::raw::{HttpFetch, HttpBody};
use opendal::Buffer;
use http::{Request, Response};
use opendal::Result;
struct CustomHttpClient {
// Your custom HTTP client fields
}
impl HttpFetch for CustomHttpClient {
async fn fetch(&self, req: Request<Buffer>) -> Result<Response<HttpBody>> {
// Your custom HTTP client implementation
todo!()
}
}
Implementations§
Source§impl HttpClientLayer
impl HttpClientLayer
Sourcepub fn new(client: HttpClient) -> Self
pub fn new(client: HttpClient) -> Self
Trait Implementations§
Source§impl Clone for HttpClientLayer
impl Clone for HttpClientLayer
Source§fn clone(&self) -> HttpClientLayer
fn clone(&self) -> HttpClientLayer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<A: Access> Layer<A> for HttpClientLayer
impl<A: Access> Layer<A> for HttpClientLayer
Source§type LayeredAccess = HttpClientAccessor<A>
type LayeredAccess = HttpClientAccessor<A>
The layered accessor that returned by this layer.
Source§fn layer(&self, inner: A) -> Self::LayeredAccess
fn layer(&self, inner: A) -> Self::LayeredAccess
Intercept the operations on the underlying storage.
Auto Trait Implementations§
impl Freeze for HttpClientLayer
impl !RefUnwindSafe for HttpClientLayer
impl Send for HttpClientLayer
impl Sync for HttpClientLayer
impl Unpin for HttpClientLayer
impl !UnwindSafe for HttpClientLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Apply a transformation to the response body. Read more
Source§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
Decompress response bodies. Read more
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using HTTP status codes. Read more
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using gRPC headers. Read more