alloy_transport_http/
lib.rs1#![doc = include_str!("../README.md")]
2#![doc(
3    html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
4    html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
5)]
6#![cfg_attr(not(test), warn(unused_crate_dependencies))]
7#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
8
9#[cfg(feature = "reqwest")]
10pub use reqwest;
11#[cfg(feature = "reqwest")]
12mod reqwest_transport;
13
14#[cfg(feature = "reqwest")]
15#[doc(inline)]
16pub use reqwest_transport::*;
17
18#[cfg(all(not(target_family = "wasm"), feature = "hyper"))]
19pub use hyper;
20#[cfg(all(not(target_family = "wasm"), feature = "hyper"))]
21pub use hyper_util;
22
23#[cfg(all(not(target_family = "wasm"), feature = "hyper", feature = "jwt-auth"))]
24mod layers;
25#[cfg(all(not(target_family = "wasm"), feature = "hyper", feature = "jwt-auth"))]
26pub use layers::{AuthLayer, AuthService};
27
28#[cfg(all(not(target_family = "wasm"), feature = "hyper"))]
29mod hyper_transport;
30#[cfg(all(not(target_family = "wasm"), feature = "hyper"))]
31#[doc(inline)]
32pub use hyper_transport::{HyperClient, HyperResponse, HyperResponseFut, HyperTransport};
33
34use alloy_transport::utils::guess_local_url;
35use core::str::FromStr;
36use std::marker::PhantomData;
37use url::Url;
38
39#[derive(Clone, Debug, PartialEq, Eq, Hash)]
41#[doc(hidden)]
42pub struct HttpConnect<T> {
43    url: Url,
45
46    _pd: PhantomData<T>,
47}
48
49impl<T> HttpConnect<T> {
50    pub const fn new(url: Url) -> Self {
52        Self { url, _pd: PhantomData }
53    }
54
55    pub const fn url(&self) -> &Url {
57        &self.url
58    }
59}
60
61impl<T> FromStr for HttpConnect<T> {
62    type Err = url::ParseError;
63
64    fn from_str(s: &str) -> Result<Self, Self::Err> {
65        Ok(Self::new(s.parse()?))
66    }
67}
68
69#[cfg_attr(feature = "reqwest", doc = " - [`reqwest`](::reqwest::Client)")]
79#[cfg_attr(feature = "hyper", doc = " - [`hyper`](hyper_util::client::legacy::Client)")]
80#[derive(Clone, Debug)]
81pub struct Http<T> {
82    client: T,
83    url: Url,
84}
85
86impl<T> Http<T> {
87    pub const fn with_client(client: T, url: Url) -> Self {
89        Self { client, url }
90    }
91
92    pub fn set_url(&mut self, url: Url) {
94        self.url = url;
95    }
96
97    pub fn set_client(&mut self, client: T) {
99        self.client = client;
100    }
101
102    pub fn guess_local(&self) -> bool {
108        guess_local_url(&self.url)
109    }
110
111    pub const fn client(&self) -> &T {
113        &self.client
114    }
115
116    pub fn url(&self) -> &str {
118        self.url.as_ref()
119    }
120}