1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! Tower-native compatibility layer for hpx.
//!
//! This module exposes hpx's internal `tower::Service` for direct composition
//! with the broader tower ecosystem, bridging the gap between hpx's convenience
//! API (`hpx::Request` / `hpx::Response`) and standard `http::Request<Body>` /
//! `http::Response<ClientResponseBody>` types.
use ;
use Request;
use BoxCloneSyncService;
use ;
use crate::;
/// Per-request configuration for hpx, stored in `http::Extensions`.
///
/// Internal convenience wrapper. Users should use `HpxRequestExt` methods
/// instead of inserting this directly.
pub
/// Extension trait for `http::Request<Body>` providing hpx-specific convenience methods.
///
/// This bridges the gap between standard HTTP request types and hpx's per-request
/// configuration system. All configuration is stored in `http::Extensions`,
/// maintaining full compatibility with the tower ecosystem.
///
/// # Example
///
/// ```ignore
/// use hpx::{Body, tower_compat::HpxRequestExt};
///
/// let req = http::Request::builder()
/// .uri("https://example.com")
/// .body(Body::empty())
/// .unwrap()
/// .skip_default_headers();
/// ```
/// The type-erased tower service returned by `TowerServiceExt`.
///
/// This is `BoxCloneSyncService<http::Request<Body>, http::Response<ClientResponseBody>, BoxError>`,
/// compatible with any tower middleware.
pub type HpxService =
;
/// Extension trait exposing hpx's inner tower::Service for direct composition.
///
/// hpx's internal middleware stack operates on standard `http::Request<Body>` and
/// `http::Response<ClientResponseBody>` types. This trait lets you extract that service
/// and compose it with any tower middleware — rate limiters, concurrency limiters,
/// tracing, circuit breakers, and more.
///
/// # Example
///
/// ```ignore
/// use tower::{Service, ServiceBuilder, ServiceExt};
/// use tower::limit::ConcurrencyLimitLayer;
/// use hpx::{Body, tower_compat::TowerServiceExt};
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let client = hpx::Client::builder().build()?;
///
/// // Extract the inner service and wrap it with standard tower middleware
/// let service = client.into_tower_service();
/// let service = ServiceBuilder::new()
/// .layer(ConcurrencyLimitLayer::new(100))
/// .service(service);
///
/// // Use standard http::Request — no hpx wrapper types needed
/// let req = http::Request::get("https://example.com")
/// .body(Body::empty())?;
/// let resp = service.oneshot(req).await?;
/// # Ok(())
/// # }
/// ```
// ── HpxAdapter ─────────────────────────────────────────────────
/// Adapter that lets any `Service<http::Request<Body>>` accept `hpx::Request`.
///
/// Use this when you have a standard tower service (or composed middleware stack)
/// and want to feed it `hpx::Request` values. The adapter converts `hpx::Request`
/// to `http::Request<Body>` via `Into`, preserving all extensions.
///
/// **Note:** The inner service must produce `http::Response<ClientResponseBody>`.
/// For services with different response bodies, add a `.map_response()` layer
/// before adapting.
///
/// # Example
///
/// ```ignore
/// use tower::{Service, ServiceBuilder, ServiceExt};
/// use tower::limit::ConcurrencyLimitLayer;
/// use hpx::{Body, tower_compat::{HpxAdapter, TowerServiceExt}};
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let client = hpx::Client::builder().build()?;
///
/// // Build a standard tower service stack
/// let inner = client.into_tower_service();
/// let adapted = HpxAdapter::new(inner);
///
/// // Now `adapted` accepts hpx::Request, while inner works on http::Request<Body>
/// let req = hpx::Request::new(http::Method::GET, "https://example.com".parse()?);
/// let resp = adapted.oneshot(req).await?;
/// # Ok(())
/// # }
/// ```