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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//! Hyperdriver
//!
//! Building the missing middle for network services in Rust.
//!
//! This crate is an alternative to [hyper-util][], providing a more fully-featured
//! interface for building Clients and Servers on top of the [hyper][] crate. It
//! is developed more speadily, but this means that it has a less stable interface
//! between minor versions than [hyper-util][], which is trying to carefully consider
//! some of the available design choices.
//!
//! This crate supports HTTP/1.1 and HTTP/2, as well as a pluggable transport mechanism
//! so that you can implement your own transports. Out of the box, it supports TCP,
//! Unix Domain Sockets, and in-memory byte streams, all with TLS support.
//!
//! The TLS support here should be additionally general enough to wrap any byte stream
//! which implements [`AsyncRead + AsyncWrite`][tokio::io], so you can use it with other libraries.
//!
//! # A tour
//!
//! Hyperdriver provides [`Client`] and [`Server`] types, which are the main entry points for
//! most high level use cases. The [`Client`] type is designed for making requests to servers,
//! and is similar to the one found in [reqwest][], but with a bit more pluggability and flexibility.
//!
//! The server is modeled after the features provided by the [hyper][] pre-1.0 server, and the [axum][]
//! server, but again with a more pluggable and composable design.
//!
//! Both are heavily reliant on the [tower][] [`tower::Service`] trait, and should compose well with
//! other tower-based services, such as those from [tower-http][].
//!
//! When you don't need that much customization, the defaults and regular implementations of both
//! [`Client`] and `Server` should be sufficient, and will help to avoid the type complexity that
//! comes with using layers of [`tower::Layer`]s.
//!
//! # Using [`tower::Service`] based types
//!
//! The [`tower::Service`] based types implemented for this crate are almost exclucively provided
//! in the [`crate::service`] module.
//!
//! When assembling a [`tower::Service`], it is often useful to do so with a [`tower::ServiceBuilder`]
//! and a collection of [`tower::Layer`]s. This is a common pattern in the tower ecosystem, and
//! hyperdriver is no exception. It is important to note that typing for these kinds of services
//! can be a bit tricky and unweildy. For instance, you can't dynamically decide to apply a [`Layer`](tower::Layer)
//! to a builder, you have to use an `Option` so that they type of the resulting layer is effectively
//! `Option<Layer>`. Alternatively, you can use [`tower::ServiceBuilder::boxed`] to create a boxed
//! service.
//!
//! Hyperdriver provides a helpful [`crate::service::OptionLayer`] type which can be used to wrap
//! layers without box-ing the error type (as the one from
//! [`tower` does](tower::ServiceBuilder::option_layer)). See
//! [`crate::service::OptionLayerExt`] for an ergomic way to use this with the [`tower::ServiceBuilder`]
//! type.
//!
//! ## Building Servers
//!
//! A server ends up being a "double service". Each [`http::Request`] is handled by a service, and returns
//! a [`http::Response`]. The server itself requires a service which can create a new service for each request,
//! which is often called a `MakeService` in the tower ecosystem. This two-layer design can be confusing.
//!
//! If your server's service is clone-able, you can use [`SharedService`](crate::service::SharedService) to wrap it.
//! This will mean that the [`Server`] will clone the service for each incoming connection. Otherwise, you should
//! implement a [`MakeService`](tower::MakeService), which is a service that accepts a reference to a connection
//! type, and returns an appropriate service for handling the ensuing request.
//!
//! See the [`crate::server`] module for more information on building servers.
//!
//! ## Building Clients
//!
//! A client can also be composed of services. In this case, there is only one "service", it must accept
//! a [`http::Request`] and return a [`http::Response`]. At the inner-most level, there is a connection step,
//! where the [`http::Request`] is coupled with a connection, to be used to send the request. At this point,
//! the service will switch from accepting a [`http::Request`] to accepting a tuple of the connection and request.
//!
//! The default way to do this in `hyperdriver` is to use the [`crate::client::ConnectionPoolService`] type,
//! which implements connections and connection pooling. Many middleware services can be applied both above
//! (when the service only has an [`http::Request`]) and below (when the service has an [`ClientExecutorService`]) this
//! type. Some middleware might have slightly different behavior. For example, the [`SetHostHeader`] middleware
//! will apply the `Host` header to the request based on the version of the request if the connection is not
//! available yet. Usually this is not desired, since an HTTP/1.1 request might be internally upgraded to
//! HTTP/2, and the `Host` header should be removed. In this case, the [`SetHostHeader`]
//! middleware should be applied after the [`ConnectionPoolService`](crate::client::ConnectionPoolService).
//!
//! # Bodies
//!
//! The [`hyper`] ecosystem relies on the [`http_body::Body`] trait to represent the body of a request or response.
//! This is implemented for many types, and so can be tricky to unify. Many ecosystem crates ([axum][], [reqwest][],
//! [tonic][], etc.) implement their own body type, which sometimes can be used to encapsulate other bodies.
//!
//! Hyperdriver provides a [`Body`] type which is a wrapper around a [`http_body::Body`] type, but it is intentionally
//! minimal. If you need a unifying body type, you can reach for [`http_body_util::combinators::UnsyncBoxBody`] or
//! [`http_body_util::combinators::BoxBody`], which provide dynamic dispact bodies over any implementor of the [`http_body::Body`]
//! type. The [`Body`] is most useful for simple cases where you want to unify a request and response
//! body. `hyper` provides the [`hyper::body::Incoming`] type, which is what all incoming bodies are provided
//! as by both `hyper` and this crate. [`Body`] is a wrapper around this type and known, in memory
//! bodies, which can be convenient for simple services, but notably do not support streaming or chunked-encoded
//! bodies.
//!
//! [hyper]: https://docs.rs/hyper
//! [hyper-util]: https://docs.rs/hyper-util
//! [http]: https://docs.rs/http
//! [http-body]: https://docs.rs/http-body
//! [reqwest]: https://docs.rs/reqwest
//! [axum]: https://docs.rs/axum
//! [tower]: https://docs.rs/tower
//! [tower-http]: https://docs.rs/tower-http
//! [tonic]: https://docs.rs/tonic
//! [tokio::io]: https://docs.rs/tokio/1/tokio/io/index.html
//!
//! [`ClientExecutorService`]: chateau::client::conn::service::ClientExecutorService
//! [`SetHostHeader`]: crate::service::SetHostHeader
use ;
use dispatcher;
pub
pub use Body;
pub use Client;
pub use Server;
pub use IntoRequestParts;
type BoxFuture<'a, T> = ;
type BoxError = ;
/// Utility struct for formatting a `Display` type in a `Debug` context.
pub ;
/// Utility function for attaching a `follows_from` relationship to the current span
/// in a polling context.
pub
pub
/// Helpers to turn URI-like items into empty request parts
pub
/// Test fixtures for the `hyperdriver` crate.
pub