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_core::layers::HttpClientLayer;
use opendal_core::services;
use opendal_core::Operator;
use opendal_core::Result;
use opendal_core::raw::HttpClient;
// Create a custom HTTP client
let custom_client = HttpClient::new()?;
let op = Operator::new(services::Memory::default())?
.layer(HttpClientLayer::new(custom_client))
.finish();§Custom HTTP Client Implementation
use opendal_core::raw::{HttpFetch, HttpBody};
use opendal_core::Buffer;
use http::{Request, Response};
use opendal_core::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
Create a new HttpClientLayer with the given HTTP client.
§Arguments
client- The HTTP client to use for all HTTP requests
§Examples
use opendal_core::layers::HttpClientLayer;
use opendal_core::raw::HttpClient;
use opendal_core::Result;
let client = HttpClient::new()?;
let layer = HttpClientLayer::new(client);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