pub struct EasyHttpWebClient<BodyIn, ConnResponse, L> { /* private fields */ }dns and http-backend and http and std and tcp only.Expand description
An opiniated http client that can be used to serve HTTP requests.
Use EasyHttpWebClient::connector_builder() to easily create a client with
a common Http connector setup (tcp + proxy + tls + http) or bring your
own http connector.
Default uses Rama’s default multiplexing connection pool. Build the
connector explicitly with
EasyHttpConnectorBuilder::without_connection_pool when connection reuse
is unwanted.
You can fork this http client in case you have use cases not possible with this service example. E.g. perhaps you wish to have middleware in into outbound requests, after they passed through your “connector” setup. All this and more is possible by defining your own http client. Rama is here to empower you, the building blocks are there, go crazy with your own service fork and use the full power of Rust at your fingertips ;)
Implementations§
Source§impl EasyHttpWebClient<(), (), ()>
impl EasyHttpWebClient<(), (), ()>
Sourcepub fn connector_builder() -> EasyHttpConnectorBuilder
pub fn connector_builder() -> EasyHttpConnectorBuilder
Create a EasyHttpConnectorBuilder to easily create a EasyHttpWebClient with a custom connector
Sourcepub fn try_blocking() -> Result<BlockingHttpWebClient>
pub fn try_blocking() -> Result<BlockingHttpWebClient>
Create a cloneable blocking HTTP(S) client with its own dedicated runtime thread and Rama’s default web connector stack.
use rama::http::client::EasyHttpWebClient;
let client = EasyHttpWebClient::try_blocking()?;
let client_for_worker = client.clone();
let text = client_for_worker
.get("https://example.com/")
.send()?
.try_into_string()?;Source§impl<Body> EasyHttpWebClient<Body, EstablishedClientConnection<BindBodyToConn<MultiplexedConnection<HttpClientService<Body>, HttpConnId>>, Request<Body>>, ()>
impl<Body> EasyHttpWebClient<Body, EstablishedClientConnection<BindBodyToConn<MultiplexedConnection<HttpClientService<Body>, HttpConnId>>, Request<Body>>, ()>
pub fn default_with_executor(exec: Executor) -> Self
Source§impl<BodyIn, ConnResponse> EasyHttpWebClient<BodyIn, ConnResponse, ()>where
BodyIn: Send + 'static,
impl<BodyIn, ConnResponse> EasyHttpWebClient<BodyIn, ConnResponse, ()>where
BodyIn: Send + 'static,
Sourcepub fn new<S>(connector: S) -> Self
pub fn new<S>(connector: S) -> Self
Create a new EasyHttpWebClient using the provided connector.
Custom proxy connectors must honor PlaintextHttpProxyMode and publish
EstablishedProxyRoute.
Connection wrappers must preserve that metadata through ExtensionsRef.
Source§impl<BodyIn, ConnResponse, L> EasyHttpWebClient<BodyIn, ConnResponse, L>
impl<BodyIn, ConnResponse, L> EasyHttpWebClient<BodyIn, ConnResponse, L>
Sourcepub fn try_into_blocking(self) -> Result<BlockingHttpClient<Self>>
pub fn try_into_blocking(self) -> Result<BlockingHttpClient<Self>>
Convert this asynchronous web client into a cloneable blocking client with its own dedicated runtime thread.
Sourcepub fn into_blocking_with_runtime(
self,
runtime: &Runtime,
) -> BlockingHttpClient<Self>
pub fn into_blocking_with_runtime( self, runtime: &Runtime, ) -> BlockingHttpClient<Self>
Convert this asynchronous web client into a blocking client using a caller-supplied runtime.
Sourcepub fn with_connector<S, BodyInNew, ConnResponseNew>(
self,
connector: S,
) -> EasyHttpWebClient<BodyInNew, ConnResponseNew, L>
pub fn with_connector<S, BodyInNew, ConnResponseNew>( self, connector: S, ) -> EasyHttpWebClient<BodyInNew, ConnResponseNew, L>
Set the connector that this EasyHttpWebClient will use.
Custom proxy connectors follow the metadata contract described in Self::new.
Sourcepub fn with_jit_layer<T>(
self,
jit_layers: T,
) -> EasyHttpWebClient<BodyIn, ConnResponse, T>
pub fn with_jit_layer<T>( self, jit_layers: T, ) -> EasyHttpWebClient<BodyIn, ConnResponse, T>
Layer which will be applied just in time (JIT) before the request is sent, but after
the connection has been established. Rama’s built-in forward-proxy
policy is the innermost JIT service so it can act on the actual
connection after caller middleware has processed the request, and can
isolate a proxy challenge before caller middleware sees the response.
Simplified flow of how the EasyHttpWebClient works:
- External: let response = client.serve(request)
- Internal: let http_connection = self.connector.serve(request)
- Internal: wrap the connection in Rama’s forward-proxy policy
- Internal: let response = jit_layers.layer(http_connection).serve(request)
Sourcepub fn with_forward_proxy_auth(self, enabled: bool) -> Self
pub fn with_forward_proxy_auth(self, enabled: bool) -> Self
Enable or disable automatic Basic or Bearer credentials on requests sent directly to an HTTP forward proxy.
This is enabled by default and acts only when the established connection is positively identified as an HTTP forward-proxy connection. It never adds credentials to direct, SOCKS, or HTTP CONNECT-tunneled requests.
Disabling this only disables insertion. Caller-provided
Proxy-Authorization headers are preserved on established HTTP
forward routes and always stripped on every other route, including
connections without established route metadata.
Sourcepub fn set_forward_proxy_auth(&mut self, enabled: bool) -> &mut Self
pub fn set_forward_proxy_auth(&mut self, enabled: bool) -> &mut Self
Enable or disable automatic Basic or Bearer credentials on requests sent directly to an HTTP forward proxy.
This is enabled by default and acts only when the established connection is positively identified as an HTTP forward-proxy connection. It never adds credentials to direct, SOCKS, or HTTP CONNECT-tunneled requests.
Disabling this only disables insertion. Caller-provided
Proxy-Authorization headers are preserved on established HTTP
forward routes and always stripped on every other route, including
connections without established route metadata.
Sourcepub fn without_forward_proxy_auth(self) -> Self
pub fn without_forward_proxy_auth(self) -> Self
Disable automatic Basic or Bearer credentials on HTTP forward-proxy
requests. The credential-stripping policy described by
Self::with_forward_proxy_auth still applies.
Sourcepub fn with_tunnel_plaintext_http(self, enabled: bool) -> Self
pub fn with_tunnel_plaintext_http(self, enabled: bool) -> Self
Enable or disable carrying plaintext HTTP through an HTTP(S) proxy with CONNECT instead of using ordinary forward-proxy semantics (absolute-form on HTTP/1).
If this method is not called, a request-level
PlaintextHttpProxyMode
is honored and
otherwise forwarding is the connector default. Calling this method
explicitly selects Tunnel (true) or Forward (false) for the client.
Tunneling does not encrypt the origin traffic: a plaintext http://
request remains plaintext inside the proxy tunnel.
Sourcepub fn set_tunnel_plaintext_http(&mut self, enabled: bool) -> &mut Self
pub fn set_tunnel_plaintext_http(&mut self, enabled: bool) -> &mut Self
Enable or disable carrying plaintext HTTP through an HTTP(S) proxy with CONNECT instead of using ordinary forward-proxy semantics (absolute-form on HTTP/1).
If this method is not called, a request-level
PlaintextHttpProxyMode
is honored and
otherwise forwarding is the connector default. Calling this method
explicitly selects Tunnel (true) or Forward (false) for the client.
Tunneling does not encrypt the origin traffic: a plaintext http://
request remains plaintext inside the proxy tunnel.
Sourcepub fn with_isolate_forward_proxy_auth_error(self, enabled: bool) -> Self
pub fn with_isolate_forward_proxy_auth_error(self, enabled: bool) -> Self
Enable or disable isolation of 407 Proxy Authentication Required
responses received from an established HTTP forward proxy.
Ordinary clients expose such responses by default. Intermediaries should enable this option so an upstream proxy’s challenge, headers, and body cannot be forwarded to a different downstream proxy client.
Sourcepub fn set_isolate_forward_proxy_auth_error(
&mut self,
enabled: bool,
) -> &mut Self
pub fn set_isolate_forward_proxy_auth_error( &mut self, enabled: bool, ) -> &mut Self
Enable or disable isolation of 407 Proxy Authentication Required
responses received from an established HTTP forward proxy.
Ordinary clients expose such responses by default. Intermediaries should enable this option so an upstream proxy’s challenge, headers, and body cannot be forwarded to a different downstream proxy client.
Trait Implementations§
Source§impl<BodyIn, ConnResponse, L: Clone> Clone for EasyHttpWebClient<BodyIn, ConnResponse, L>
impl<BodyIn, ConnResponse, L: Clone> Clone for EasyHttpWebClient<BodyIn, ConnResponse, L>
Source§impl<BodyIn, ConnResponse, L> Debug for EasyHttpWebClient<BodyIn, ConnResponse, L>
impl<BodyIn, ConnResponse, L> Debug for EasyHttpWebClient<BodyIn, ConnResponse, L>
Source§impl<Body, ConnectionBody, Connection, L> Service<Request<Body>> for EasyHttpWebClient<Body, EstablishedClientConnection<Connection, Request<ConnectionBody>>, L>where
Body: StreamingBody<Data: Send + 'static, Error: Into<BoxError>> + Unpin + Send + 'static,
Connection: Service<Request<ConnectionBody>, Output = Response, Error = BoxError> + ExtensionsRef,
ConnectionBody: StreamingBody<Data: Send + 'static, Error: Into<BoxError>> + Unpin + Send + 'static,
L: Layer<HttpForwardProxyService<Connection>, Service: Service<Request<ConnectionBody>, Output = Response, Error = BoxError>> + Send + Sync + 'static,
impl<Body, ConnectionBody, Connection, L> Service<Request<Body>> for EasyHttpWebClient<Body, EstablishedClientConnection<Connection, Request<ConnectionBody>>, L>where
Body: StreamingBody<Data: Send + 'static, Error: Into<BoxError>> + Unpin + Send + 'static,
Connection: Service<Request<ConnectionBody>, Output = Response, Error = BoxError> + ExtensionsRef,
ConnectionBody: StreamingBody<Data: Send + 'static, Error: Into<BoxError>> + Unpin + Send + 'static,
L: Layer<HttpForwardProxyService<Connection>, Service: Service<Request<ConnectionBody>, Output = Response, Error = BoxError>> + Send + Sync + 'static,
Source§type Error = OpaqueError
type Error = OpaqueError
Source§async fn serve(&self, req: Request<Body>) -> Result<Self::Output, Self::Error>
async fn serve(&self, req: Request<Body>) -> Result<Self::Output, Self::Error>
§fn boxed(self) -> BoxService<Input, Self::Output, Self::Error>
fn boxed(self) -> BoxService<Input, Self::Output, Self::Error>
Auto Trait Implementations§
impl<BodyIn, ConnResponse, L> !RefUnwindSafe for EasyHttpWebClient<BodyIn, ConnResponse, L>
impl<BodyIn, ConnResponse, L> !UnwindSafe for EasyHttpWebClient<BodyIn, ConnResponse, L>
impl<BodyIn, ConnResponse, L> Freeze for EasyHttpWebClient<BodyIn, ConnResponse, L>
impl<BodyIn, ConnResponse, L> Send for EasyHttpWebClient<BodyIn, ConnResponse, L>
impl<BodyIn, ConnResponse, L> Sync for EasyHttpWebClient<BodyIn, ConnResponse, L>
impl<BodyIn, ConnResponse, L> Unpin for EasyHttpWebClient<BodyIn, ConnResponse, L>
impl<BodyIn, ConnResponse, L> UnsafeUnpin for EasyHttpWebClient<BodyIn, ConnResponse, L>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T, ReqBody, ResBody> GrpcService<ReqBody> for T
impl<T, ReqBody, ResBody> GrpcService<ReqBody> for T
§type ResponseBody = ResBody
type ResponseBody = ResBody
§fn serve(
&self,
request: Request<ReqBody>,
) -> impl Future<Output = Result<Response<<T as GrpcService<ReqBody>>::ResponseBody>, <T as GrpcService<ReqBody>>::Error>> + Send
fn serve( &self, request: Request<ReqBody>, ) -> impl Future<Output = Result<Response<<T as GrpcService<ReqBody>>::ResponseBody>, <T as GrpcService<ReqBody>>::Error>> + Send
§impl<S, Body> HttpClientExt for S
impl<S, Body> HttpClientExt for S
§type ExecuteResponse = Response<Body>
type ExecuteResponse = Response<Body>
execute method.§type ExecuteError = <S as Service<Request>>::Error
type ExecuteError = <S as Service<Request>>::Error
execute method.§fn get(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn get( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
GET request to a URL. Read more§fn post(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn post( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
POST request to a URL. Read more§fn put(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn put( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
PUT request to a URL. Read more§fn patch(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn patch( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
PATCH request to a URL. Read more§fn delete(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn delete( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
DELETE request to a URL. Read more§fn head(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn head( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
HEAD request to a URL. Read more§fn connect(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn connect( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
CONNECT request to a URL. Read more§fn request(
&self,
method: Method,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn request( &self, method: Method, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
§fn build_from_request<RequestBody>(
&self,
request: Request<RequestBody>,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn build_from_request<RequestBody>( &self, request: Request<RequestBody>, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
§fn execute(
&self,
request: Request,
) -> impl Future<Output = Result<<S as HttpClientExt>::ExecuteResponse, <S as HttpClientExt>::ExecuteError>>
fn execute( &self, request: Request, ) -> impl Future<Output = Result<<S as HttpClientExt>::ExecuteResponse, <S as HttpClientExt>::ExecuteError>>
Request. Read more§impl<S, Body> HttpClientWebSocketExt<Body> for S
impl<S, Body> HttpClientWebSocketExt<Body> for S
§fn websocket(
&self,
url: impl IntoUrl,
) -> WebSocketRequestBuilder<WithService<'_, S, Body>>
fn websocket( &self, url: impl IntoUrl, ) -> WebSocketRequestBuilder<WithService<'_, S, Body>>
WebSocketRequestBuilder] to be used to establish a WebSocket connection over http/1.1.§fn websocket_h2(
&self,
url: impl IntoUrl,
) -> WebSocketRequestBuilder<WithService<'_, S, Body>>
fn websocket_h2( &self, url: impl IntoUrl, ) -> WebSocketRequestBuilder<WithService<'_, S, Body>>
WebSocketRequestBuilder to be used to establish a WebSocket connection over h2.§fn websocket_with_request<RequestBody>(
&self,
req: Request<RequestBody>,
) -> WebSocketRequestBuilder<WithService<'_, S, Body>>
fn websocket_with_request<RequestBody>( &self, req: Request<RequestBody>, ) -> WebSocketRequestBuilder<WithService<'_, S, Body>>
WebSocketRequestBuilder starting from the given request. Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<S> IntoEndpointService<(S,)> for S
impl<S> IntoEndpointService<(S,)> for S
type Service = S
§fn into_endpoint_service(self) -> <S as IntoEndpointService<(S,)>>::Service
fn into_endpoint_service(self) -> <S as IntoEndpointService<(S,)>>::Service
rama_core::Service.§impl<S, State> IntoEndpointServiceWithState<(S,), State> for S
impl<S, State> IntoEndpointServiceWithState<(S,), State> for S
type Service = S
§fn into_endpoint_service_with_state(
self,
_state: State,
) -> <S as IntoEndpointServiceWithState<(S,), State>>::Service
fn into_endpoint_service_with_state( self, _state: State, ) -> <S as IntoEndpointServiceWithState<(S,), State>>::Service
rama_core::Service with state.§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more