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(
scope: impl Into<WeakScope>,
) -> EasyHttpConnectorBuilder
pub fn connector_builder( scope: impl Into<WeakScope>, ) -> EasyHttpConnectorBuilder
Create a EasyHttpConnectorBuilder to easily create a EasyHttpWebClient with a
custom connector, whose connections and tunnels run in scope.
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<AltSvc<BindBodyToConn<MultiplexedConnection<MaybeForwardedConnection<HttpClientService<Body>, <HttpForwardProxyConnector<ProxyDialer<MapEstablishedConnection<HttpsService<HttpServiceConnector<BindBodyToConnector<PooledConnector<HttpConnector<HttpTransportConnector<TlsConnector<DnsConnector<TcpConnector>>, DnsConnector<Http3Connector>>, ProxyRequestBody<Body>>, MultiplexPool<<HttpConnector<HttpTransportConnector<TlsConnector<DnsConnector<TcpConnector>>, DnsConnector<Http3Connector>>, ProxyRequestBody<Body>> as ConnectorService<ConnectRequest>>::Connection, HttpConnId>, HttpConnIdentifier>>>, BoxDnsResolver>, ProxyAltSvcConnectionLayer>>> as ConnectorService<ConnectRequest>>::Connection>, HttpConnId>>>, Request<Body>>, ()>
impl<Body> EasyHttpWebClient<Body, EstablishedClientConnection<AltSvc<BindBodyToConn<MultiplexedConnection<MaybeForwardedConnection<HttpClientService<Body>, <HttpForwardProxyConnector<ProxyDialer<MapEstablishedConnection<HttpsService<HttpServiceConnector<BindBodyToConnector<PooledConnector<HttpConnector<HttpTransportConnector<TlsConnector<DnsConnector<TcpConnector>>, DnsConnector<Http3Connector>>, ProxyRequestBody<Body>>, MultiplexPool<<HttpConnector<HttpTransportConnector<TlsConnector<DnsConnector<TcpConnector>>, DnsConnector<Http3Connector>>, ProxyRequestBody<Body>> as ConnectorService<ConnectRequest>>::Connection, HttpConnId>, HttpConnIdentifier>>>, BoxDnsResolver>, ProxyAltSvcConnectionLayer>>> as ConnectorService<ConnectRequest>>::Connection>, HttpConnId>>>, Request<Body>>, ()>
Sourcepub fn default_with_scope(scope: impl Into<WeakScope>) -> Self
pub fn default_with_scope(scope: impl Into<WeakScope>) -> Self
Rama’s default client stack, with its connections and tunnels in scope.
Sourcepub fn default_using_proxies(
scope: impl Into<WeakScope>,
proxies: DefaultProxyConnector<TcpConnector, Body>,
) -> Self
pub fn default_using_proxies( scope: impl Into<WeakScope>, proxies: DefaultProxyConnector<TcpConnector, Body>, ) -> Self
Rama’s default client stack over proxies, the connector towards proxies,
such as a ProxyConnector which isolates the 407 of an upstream proxy
for the client of a proxy.
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.
Forward credentials and challenge isolation come from ProxyConnector: a
connection which does not report EstablishedProxyRoute::Forward carries no
Proxy-Authorization at all.
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. A forwarded request’s proxy policy (credentials,
challenge isolation) is part of that connection, so it runs inside these layers: after
caller middleware has processed the request, and before it sees the response.
That credential is the one of the request’s own ProxyRoute, which has to name the
proxy its connection reaches. A layer here which rewrites that route leaves the
request without credentials, rather than sending another proxy’s.
Simplified flow of how the EasyHttpWebClient works:
- External: let response = client.serve(request)
- Internal: let http_connection = self.connector.serve(request)
- Internal: let response = jit_layers.layer(http_connection).serve(request)
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.
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, IncomingBody, 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<IncomingBody>, Error = BoxError> + ExtensionsRef,
IncomingBody: Send + Sync + 'static,
Body: From<IncomingBody>,
ConnectionBody: StreamingBody<Data: Send + 'static, Error: Into<BoxError>> + Unpin + Send + 'static,
L: Layer<MapResponseBody<ConnectionEgress<Connection>, fn(IncomingBody) -> Body>, Service: Service<Request<ConnectionBody>, Output = Response, Error = BoxError>> + Send + Sync + 'static,
impl<Body, ConnectionBody, Connection, IncomingBody, 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<IncomingBody>, Error = BoxError> + ExtensionsRef,
IncomingBody: Send + Sync + 'static,
Body: From<IncomingBody>,
ConnectionBody: StreamingBody<Data: Send + 'static, Error: Into<BoxError>> + Unpin + Send + 'static,
L: Layer<MapResponseBody<ConnectionEgress<Connection>, fn(IncomingBody) -> Body>, 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> Forget for EasyHttpWebClient<BodyIn, ConnResponse, L>
impl<BodyIn, ConnResponse, L> Freeze for EasyHttpWebClient<BodyIn, ConnResponse, L>where
*const ArcInner<dyn DynService<Request<BodyIn>, Error = OpaqueError, Output = ConnResponse> + Sync + Send> is !null: Freeze,
PhantomData<ArcInner<dyn DynService<Request<BodyIn>, Error = OpaqueError, Output = ConnResponse> + Sync + Send>>: Freeze,
L: Freeze,
impl<BodyIn, ConnResponse, L> Move 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>where
*const ArcInner<dyn DynService<Request<BodyIn>, Error = OpaqueError, Output = ConnResponse> + Sync + Send> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn DynService<Request<BodyIn>, Error = OpaqueError, Output = ConnResponse> + Sync + Send>>: UnsafeUnpin,
L: UnsafeUnpin,
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 query(
&self,
url: impl IntoUrl,
) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
fn query( &self, url: impl IntoUrl, ) -> RequestBuilder<'_, S, <S as HttpClientExt>::ExecuteResponse>
QUERY 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_auto(
&self,
url: impl IntoUrl,
) -> WebSocketRequestBuilder<WithService<'_, S, Body>>
fn websocket_auto( &self, url: impl IntoUrl, ) -> WebSocketRequestBuilder<WithService<'_, S, Body>>
WebSocketRequestBuilder to be used to establish a WebSocket connection
over the HTTP version the client stack selects.§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_h3(
&self,
url: impl IntoUrl,
) -> WebSocketRequestBuilder<WithService<'_, S, Body>>
fn websocket_h3( &self, url: impl IntoUrl, ) -> WebSocketRequestBuilder<WithService<'_, S, Body>>
WebSocketRequestBuilder to be used to establish a WebSocket connection over h3.§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<Io, S> MakeMockServer<Io, ServerClone> for S
impl<Io, S> MakeMockServer<Io, ServerClone> for S
type Server = S
fn make_server(&self, _: &ConnectRequest) -> S
§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