1#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
2
3#![doc = include_utils::include_md!("README.md:description")]
6
7use bytes::Bytes;
8use http_body::Body as HttpBody;
9use http_body_util::BodyDataStream;
10use tower_layer::Layer;
11
12#[doc(inline)]
13pub use crate::error::Error;
14
15mod adapters;
16pub mod error;
17
18#[cfg(feature = "auth")]
19pub mod auth;
20#[cfg(feature = "set-header")]
21pub mod set_header;
22
23pub type Result<T, E = crate::Error> = std::result::Result<T, E>;
25
26#[derive(Debug, Clone)]
28pub struct HttpClientService<S>(S);
29
30impl<S> HttpClientService<S> {
31 pub const fn new(inner: S) -> Self {
33 Self(inner)
34 }
35}
36
37#[doc = include_utils::include_md!("README.md:description")]
42#[derive(Debug, Clone, Copy)]
44pub struct HttpClientLayer;
45
46impl<S> Layer<S> for HttpClientLayer {
47 type Service = HttpClientService<S>;
48
49 fn layer(&self, service: S) -> Self::Service {
50 HttpClientService(service)
51 }
52}
53
54pub fn into_reqwest_body<B>(body: B) -> reqwest::Body
56where
57 B: HttpBody + Send + Sync + 'static,
58 B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
59 Bytes: From<B::Data>,
60{
61 let stream = BodyDataStream::new(body);
62 reqwest::Body::wrap_stream(stream)
63}