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))]
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
23mod layers;
24#[cfg(all(not(target_family = "wasm"), feature = "jwt-auth"))]
25pub use layers::{AuthLayer, AuthService};
26#[cfg(all(not(target_family = "wasm"), feature = "traceparent"))]
27pub use layers::{TraceParentLayer, TraceParentService};
28
29#[cfg(all(not(target_family = "wasm"), feature = "hyper"))]
30mod hyper_transport;
31#[cfg(all(not(target_family = "wasm"), feature = "hyper"))]
32#[doc(inline)]
33pub use hyper_transport::{HyperClient, HyperResponse, HyperResponseFut, HyperTransport};
34
35use alloy_transport::utils::guess_local_url;
36use core::str::FromStr;
37use std::marker::PhantomData;
38use url::Url;
39
40#[derive(Clone, Debug, PartialEq, Eq, Hash)]
42#[doc(hidden)]
43pub struct HttpConnect<T> {
44 url: Url,
46
47 _pd: PhantomData<T>,
48}
49
50impl<T> HttpConnect<T> {
51 pub const fn new(url: Url) -> Self {
53 Self { url, _pd: PhantomData }
54 }
55
56 pub const fn url(&self) -> &Url {
58 &self.url
59 }
60}
61
62impl<T> FromStr for HttpConnect<T> {
63 type Err = url::ParseError;
64
65 fn from_str(s: &str) -> Result<Self, Self::Err> {
66 Ok(Self::new(s.parse()?))
67 }
68}
69
70#[cfg_attr(feature = "reqwest", doc = " - [`reqwest`](::reqwest::Client)")]
80#[cfg_attr(feature = "hyper", doc = " - [`hyper`](hyper_util::client::legacy::Client)")]
81#[derive(Clone, Debug)]
82pub struct Http<T> {
83 client: T,
84 url: Url,
85}
86
87impl<T> Http<T> {
88 pub const fn with_client(client: T, url: Url) -> Self {
90 Self { client, url }
91 }
92
93 pub fn set_url(&mut self, url: Url) {
95 self.url = url;
96 }
97
98 pub fn set_client(&mut self, client: T) {
100 self.client = client;
101 }
102
103 pub fn guess_local(&self) -> bool {
109 guess_local_url(&self.url)
110 }
111
112 pub const fn client(&self) -> &T {
114 &self.client
115 }
116
117 pub fn url(&self) -> &str {
119 self.url.as_ref()
120 }
121}