hyperdriver 0.12.3

The missing middle for Hyper - Servers and Clients with ergonomic APIs
Documentation
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
use std::sync::Arc;
use std::time::Duration;

use chateau::client::conn::service::ClientExecutorService;

#[cfg(feature = "tls")]
use crate::client::conn::Stream;
use http::HeaderValue;
use http_body::Body;
#[cfg(feature = "tls")]
use rustls::ClientConfig;
#[cfg(feature = "tls")]
use tokio::io::{AsyncRead, AsyncWrite};
use tower::ServiceBuilder;
use tower::layer::util::{Identity, Stack};
use tower_http::follow_redirect::FollowRedirectLayer;
use tower_http::follow_redirect::policy;
use tower_http::set_header::SetRequestHeaderLayer;

use super::conn::dns::GaiResolver;
use super::conn::protocol::auto;
use crate::BoxError;
use crate::client::UriKey;
#[cfg(feature = "tls")]
use crate::client::conn::{AutoTlsTransport, tls::future::TransportBraidFuture};
#[cfg(feature = "tls")]
use crate::client::default_tls_config;
use crate::client::{Client, conn::protocol::auto::AlpnHttpConnectionBuilder};
use crate::service::IncomingResponseLayer;
use crate::service::OptionLayerExt;
use crate::service::TimeoutLayer;
use crate::service::{Http1ChecksLayer, Http2ChecksLayer, HttpConnectionInfo, SetHostHeaderLayer};
use chateau::client::ConnectionPoolLayer;
use chateau::client::conn::Connection;
use chateau::client::conn::Protocol;
use chateau::client::conn::Transport;
#[cfg(feature = "tls")]
use chateau::client::conn::transport::TlsConnectionError;
use chateau::client::conn::transport::tcp::{TcpTransport, TcpTransportConfig};
use chateau::client::pool::{PoolableConnection, PoolableStream};
use chateau::info::HasConnectionInfo;
use chateau::services::SharedService;

/// A builder for a client.
#[derive(Debug)]
pub struct Builder<T, P, RP = policy::Standard, S = Identity, BIn = crate::Body, BOut = crate::Body>
{
    transport: T,
    protocol: P,
    builder: ServiceBuilder<S>,
    user_agent: Option<String>,
    redirect: Option<RP>,
    timeout: Option<Duration>,
    #[cfg(feature = "tls")]
    tls: Option<ClientConfig>,
    pool: Option<chateau::client::PoolConfig>,
    body: std::marker::PhantomData<fn(BIn) -> BOut>,
}

impl Builder<(), (), policy::Standard> {
    /// Create a new, empty builder
    pub fn new() -> Self {
        Self {
            transport: (),
            protocol: (),
            builder: ServiceBuilder::new(),
            user_agent: None,
            redirect: None,
            timeout: None,
            #[cfg(feature = "tls")]
            tls: None,
            pool: None,
            body: std::marker::PhantomData,
        }
    }
}

impl Default
    for Builder<
        TcpTransport<GaiResolver>,
        AlpnHttpConnectionBuilder<crate::Body>,
        policy::Standard,
        Identity,
        crate::Body,
        crate::Body,
    >
{
    fn default() -> Self {
        Self {
            transport: Default::default(),
            protocol: Default::default(),
            builder: ServiceBuilder::new(),
            user_agent: None,
            redirect: Some(policy::Standard::default()),
            timeout: Some(Duration::from_secs(30)),
            #[cfg(feature = "tls")]
            tls: Some(default_tls_config()),
            pool: Some(Default::default()),
            body: std::marker::PhantomData,
        }
    }
}

impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut> {
    /// Use the provided TCP configuration.
    pub fn with_tcp(
        self,
        config: TcpTransportConfig,
    ) -> Builder<TcpTransport<GaiResolver>, P, RP, S, BIn, BOut> {
        Builder {
            transport: TcpTransport::new(GaiResolver::new(), Arc::new(config)),
            protocol: self.protocol,
            builder: self.builder,
            user_agent: self.user_agent,
            redirect: self.redirect,
            timeout: self.timeout,
            #[cfg(feature = "tls")]
            tls: self.tls,
            pool: self.pool,
            body: self.body,
        }
    }

    /// Provide a custom transport
    pub fn with_transport<T2>(self, transport: T2) -> Builder<T2, P, RP, S, BIn, BOut> {
        Builder {
            transport,
            protocol: self.protocol,
            builder: self.builder,
            user_agent: self.user_agent,
            redirect: self.redirect,
            timeout: self.timeout,
            #[cfg(feature = "tls")]
            tls: self.tls,
            pool: self.pool,
            body: self.body,
        }
    }

    /// Get a mutable reference to the transport configuration
    pub fn transport(&mut self) -> &mut T {
        &mut self.transport
    }
}

#[cfg(feature = "tls")]
impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut> {
    /// Disable TLS
    pub fn without_tls(mut self) -> Self {
        self.tls = None;
        self
    }

    /// Use the provided TLS configuration.
    pub fn with_tls(mut self, config: ClientConfig) -> Self {
        self.tls = Some(config);
        self
    }

    /// Use the default TLS configuration with native root certificates.
    pub fn with_default_tls(mut self) -> Self {
        self.tls = Some(default_tls_config());
        self
    }

    /// TLS configuration.
    pub fn tls(&mut self) -> &mut Option<ClientConfig> {
        &mut self.tls
    }
}

#[cfg(not(feature = "tls"))]
impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut> {
    /// Disable TLS
    pub fn without_tls(self) -> Self {
        self
    }
}

impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut> {
    /// Connection pool configuration.
    pub fn pool(&mut self) -> Option<&mut chateau::client::PoolConfig> {
        self.pool.as_mut()
    }

    /// Use the provided connection pool configuration.
    pub fn with_pool(mut self, pool: chateau::client::PoolConfig) -> Self {
        self.pool = Some(pool);
        self
    }

    /// Configure the default pool settings
    pub fn with_default_pool(mut self) -> Self {
        self.pool = Some(Default::default());
        self
    }

    /// Disable connection pooling.
    pub fn without_pool(mut self) -> Self {
        self.pool = None;
        self
    }
}

impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut> {
    /// Use the auto-HTTP Protocol
    pub fn with_auto_http(
        self,
    ) -> Builder<T, auto::AlpnHttpConnectionBuilder<BIn>, RP, S, BIn, BOut> {
        Builder {
            transport: self.transport,
            protocol: auto::AlpnHttpConnectionBuilder::default(),
            builder: self.builder,
            user_agent: self.user_agent,
            redirect: self.redirect,
            timeout: self.timeout,
            #[cfg(feature = "tls")]
            tls: self.tls,
            pool: self.pool,
            body: self.body,
        }
    }

    /// Use the provided HTTP connection configuration.
    pub fn with_protocol<P2>(self, protocol: P2) -> Builder<T, P2, RP, S, BIn, BOut> {
        Builder {
            transport: self.transport,
            protocol,
            builder: self.builder,
            user_agent: self.user_agent,
            redirect: self.redirect,
            timeout: self.timeout,
            #[cfg(feature = "tls")]
            tls: self.tls,
            pool: self.pool,
            body: self.body,
        }
    }

    /// HTTP connection configuration.
    pub fn protocol(&mut self) -> &mut P {
        &mut self.protocol
    }
}

impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut> {
    /// Set the User-Agent header.
    pub fn with_user_agent(mut self, user_agent: String) -> Self {
        self.user_agent = Some(user_agent);
        self
    }

    /// Get the user agent currently configured
    pub fn user_agent(&self) -> Option<&str> {
        self.user_agent.as_deref()
    }
}

impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut> {
    /// Set the redirect policy. See [`policy`] for more information.
    pub fn with_redirect_policy<RP2>(self, policy: RP2) -> Builder<T, P, RP2, S, BIn, BOut> {
        Builder {
            transport: self.transport,
            protocol: self.protocol,
            builder: self.builder,
            user_agent: self.user_agent,
            redirect: Some(policy),
            timeout: self.timeout,
            #[cfg(feature = "tls")]
            tls: self.tls,
            pool: self.pool,
            body: self.body,
        }
    }

    /// Disable redirects.
    pub fn without_redirects(self) -> Builder<T, P, policy::Standard, S, BIn, BOut> {
        Builder {
            transport: self.transport,
            protocol: self.protocol,
            user_agent: self.user_agent,
            builder: self.builder,
            redirect: None,
            timeout: self.timeout,
            #[cfg(feature = "tls")]
            tls: self.tls,
            pool: self.pool,
            body: self.body,
        }
    }

    /// Set the standard redirect policy. See [`policy::Standard`] for more information.
    pub fn with_standard_redirect_policy(self) -> Builder<T, P, policy::Standard, S, BIn, BOut> {
        Builder {
            transport: self.transport,
            protocol: self.protocol,
            builder: self.builder,
            user_agent: self.user_agent,
            redirect: Some(policy::Standard::default()),
            timeout: self.timeout,
            #[cfg(feature = "tls")]
            tls: self.tls,
            pool: self.pool,
            body: self.body,
        }
    }

    /// Configured redirect policy.
    pub fn redirect_policy(&mut self) -> Option<&mut RP> {
        self.redirect.as_mut()
    }
}

impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut> {
    /// Set the timeout for requests.
    pub fn with_timeout(mut self, timeout: Duration) -> Self {
        self.timeout = Some(timeout);
        self
    }

    /// Get the timeout for requests.
    pub fn timeout(&self) -> Option<Duration> {
        self.timeout
    }

    /// Disable request timeouts.
    pub fn without_timeout(mut self) -> Self {
        self.timeout = None;
        self
    }

    /// Set the timeout for requests with an Option.
    pub fn with_optional_timeout(mut self, timeout: Option<Duration>) -> Self {
        self.timeout = timeout;
        self
    }
}

impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut> {
    /// Add a layer to the service under construction
    pub fn with_body<B2In, B2Out>(self) -> Builder<T, P, RP, S, B2In, B2Out>
    where
        B2In: Default + Body + Unpin + Send + 'static,
        <B2In as Body>::Data: Send,
        <B2In as Body>::Error: Into<BoxError>,
        B2Out: From<hyper::body::Incoming> + Body + Unpin + Send + 'static,
    {
        Builder {
            transport: self.transport,
            protocol: self.protocol,
            builder: self.builder,
            user_agent: self.user_agent,
            redirect: self.redirect,
            timeout: self.timeout,
            #[cfg(feature = "tls")]
            tls: self.tls,
            pool: self.pool,
            body: std::marker::PhantomData,
        }
    }
}

impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut> {
    /// Add a layer to the service under construction
    pub fn layer<L>(self, layer: L) -> Builder<T, P, RP, Stack<L, S>, BIn, BOut> {
        Builder {
            transport: self.transport,
            protocol: self.protocol,
            builder: self.builder.layer(layer),
            user_agent: self.user_agent,
            redirect: self.redirect,
            timeout: self.timeout,
            #[cfg(feature = "tls")]
            tls: self.tls,
            pool: self.pool,
            body: self.body,
        }
    }
}

#[cfg(not(feature = "tls"))]
impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut>
where
    T: Transport<http::Request<BIn>> + Clone + Send + Sync + 'static,
    T::Error: Into<BoxError>,
    <T as Transport<http::Request<BIn>>>::IO:
        PoolableStream + tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin,
    <<T as Transport<http::Request<BIn>>>::IO as HasConnectionInfo>::Addr: Unpin + Clone + Send,
    P: Protocol<<T as Transport<http::Request<BIn>>>::IO, http::Request<BIn>>
        + Clone
        + Send
        + Sync
        + 'static,
    <P as Protocol<<T as Transport<http::Request<BIn>>>::IO, http::Request<BIn>>>::Error:
        Into<BoxError>,
    <P as Protocol<<T as Transport<http::Request<BIn>>>::IO, http::Request<BIn>>>::Connection:
        Connection<http::Request<BIn>, Response = http::Response<hyper::body::Incoming>>
            + HttpConnectionInfo<BIn>
            + PoolableConnection<http::Request<BIn>>,
    <<P as chateau::client::conn::Protocol<
        <T as Transport<http::Request<BIn>>>::IO,
        http::Request<BIn>,
    >>::Connection as Connection<http::Request<BIn>>>::Error: Into<BoxError>,
    RP: policy::Policy<BIn, super::Error> + Clone + Send + Sync + 'static,
    S: tower::Layer<SharedService<http::Request<BIn>, http::Response<BOut>, super::Error>>,
    S::Service: tower::Service<http::Request<BIn>, Response = http::Response<BOut>, Error = super::Error>
        + Clone
        + Send
        + Sync
        + 'static,
    <S::Service as tower::Service<http::Request<BIn>>>::Future: Send + 'static,
    BIn: Default + Body + Unpin + Send + 'static,
    <BIn as Body>::Data: Send,
    <BIn as Body>::Error: Into<BoxError>,
    BOut: From<hyper::body::Incoming> + Body + Unpin + Send + 'static,
{
    /// Build a client service with the configured layers
    pub fn build_service(
        self,
    ) -> SharedService<http::Request<BIn>, http::Response<BOut>, super::Error> {
        let user_agent = if let Some(ua) = self.user_agent {
            HeaderValue::from_str(&ua).expect("user-agent should be a valid http header")
        } else {
            HeaderValue::from_static(concat!(
                env!("CARGO_PKG_NAME"),
                "/",
                env!("CARGO_PKG_VERSION")
            ))
        };

        let executor = ServiceBuilder::new()
            .layer(SetHostHeaderLayer::new())
            .layer(Http2ChecksLayer::new())
            .layer(Http1ChecksLayer::new())
            .service(ClientExecutorService::new());

        let middleware = self
            .builder
            .layer(SharedService::layer())
            .check_service::<_, _, _, super::Error>()
            .optional(
                self.timeout
                    .map(|d| TimeoutLayer::new(|| super::Error::RequestTimeout, d)),
            )
            .optional(self.redirect.map(FollowRedirectLayer::with_policy))
            .layer(SetRequestHeaderLayer::if_not_present(
                http::header::USER_AGENT,
                user_agent,
            ))
            .layer(IncomingResponseLayer::new());

        let service = SharedService::new(
            middleware
                .map_err(super::Error::from)
                .layer(
                    ConnectionPoolLayer::<_, _, http::Request<BIn>, UriKey>::new(
                        self.transport,
                        self.protocol,
                    )
                    .with_optional_pool(self.pool.clone()),
                )
                .service(executor),
        );

        service
    }
}

#[cfg(feature = "tls")]
impl<T, P, RP, S, BIn, BOut> Builder<T, P, RP, S, BIn, BOut>
where
    T: Transport<http::Request<BIn>> + Clone + Send + Sync + 'static,
    T::Error: Into<BoxError>,
    <T as Transport<http::Request<BIn>>>::IO: PoolableStream + HasConnectionInfo + AsyncRead + AsyncWrite + Unpin,
    <<T as Transport<http::Request<BIn>>>::IO as HasConnectionInfo>::Addr: Clone + Send + Unpin,
    P: Protocol<Stream<<T as Transport<http::Request<BIn>>>::IO>, http::Request<BIn>> + Clone + Send + Sync + 'static,
    <P as Protocol<Stream<<T as Transport<http::Request<BIn>>>::IO>, http::Request<BIn>>>::Error: Into<BoxError>,
    <P as Protocol<Stream<<T as Transport<http::Request<BIn>>>::IO>, http::Request<BIn>>>::Connection: Connection<http::Request<BIn>, Response = http::Response<hyper::body::Incoming>>
        + HttpConnectionInfo<BIn>
        + PoolableConnection<http::Request<BIn>>,
    <<P as chateau::client::conn::Protocol<Stream<<T as Transport<http::Request<BIn>>>::IO>, http::Request<BIn>>>::Connection as Connection<http::Request<BIn>>>::Error: Into<BoxError>,
    RP: policy::Policy<BIn, super::Error> + Clone + Send + Sync + 'static,
    S: tower::Layer<SharedService<http::Request<BIn>, http::Response<BOut>, super::Error>>,
    S::Service: tower::Service<http::Request<BIn>, Response = http::Response<BOut>, Error = super::Error>
        + Clone
        + Send
        + Sync
        + 'static,
    <S::Service as tower::Service<http::Request<BIn>>>::Future: Send + 'static,
    BIn: Default + Body + Unpin + Send + 'static,
    <BIn as Body>::Data: Send,
    // <BIn as Body>::Error: Into<BoxError>,
    BOut: From<hyper::body::Incoming> + Body + Unpin + Send + 'static,
{
    /// Build a client service with the configured layers
    pub fn build_service(
        self,
    ) -> SharedService<http::Request<BIn>, http::Response<BOut>, super::Error> {
        let user_agent = if let Some(ua) = self.user_agent {
            HeaderValue::from_str(&ua).expect("user-agent should be a valid http header")
        } else {
            HeaderValue::from_static(concat!(
                env!("CARGO_PKG_NAME"),
                "/",
                env!("CARGO_PKG_VERSION")
            ))
        };

        let middleware = self
            .builder
            .layer(SharedService::layer())
            .optional(
                self.timeout
                    .map(|d| TimeoutLayer::new(|| super::Error::RequestTimeout, d)),
            )
            .optional(self.redirect.map(FollowRedirectLayer::with_policy))
            .layer(SetRequestHeaderLayer::if_not_present(
                http::header::USER_AGENT,
                user_agent,
            ))
            .layer(IncomingResponseLayer::new());

        let executor = ServiceBuilder::new()
            .layer(SetHostHeaderLayer::new())
            .layer(Http2ChecksLayer::new())
            .layer(Http1ChecksLayer::new())
            .service(ClientExecutorService::new());

        SharedService::new(
                middleware
                    .check_service::<_, http::Request<BIn>, http::Response<BOut>, super::Error>()
                    .map_err(super::Error::from)
                    .layer(
                        ConnectionPoolLayer::< _, _, http::Request<BIn>, UriKey>::new(
                            AutoTlsTransport::new(self.transport).with_optional_tls(self.tls.map(Arc::new)),
                            self.protocol,
                        )
                        .with_optional_pool(self.pool.clone()),
                    )
                    .service(executor),
            )

    }
}

#[cfg(not(feature = "tls"))]
impl< T, P, RP, S> Builder<T, P, RP, S, crate::Body, crate::Body>
where
    T: Transport<http::Request<crate::Body>> + Clone + Send + Sync + 'static,
    T::Error: Into<BoxError>,
    <T as Transport<http::Request<crate::Body>>>::IO: PoolableStream + tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin,
    <<T as Transport<http::Request<crate::Body>>>::IO as HasConnectionInfo>::Addr: Unpin + Clone + Send,
    P: Protocol<<T as Transport<http::Request<crate::Body>>>::IO, http::Request<crate::Body>> + Clone + Send + Sync + 'static,
    <P as Protocol<<T as Transport<http::Request<crate::Body>>>::IO, http::Request<crate::Body>>>::Error: Into<BoxError>,
    <P as Protocol<<T as Transport<http::Request<crate::Body>>>::IO, http::Request<crate::Body>>>::Connection: Connection<http::Request<crate::Body>, Response = http::Response<hyper::body::Incoming>>
        + HttpConnectionInfo<crate::Body>
        + PoolableConnection<http::Request<crate::Body>>,
    <<P as chateau::client::conn::Protocol<<T as Transport<http::Request<crate::Body>>>::IO, http::Request<crate::Body>>>::Connection as Connection<http::Request<crate::Body>>>::Error: Into<BoxError>,
    RP: policy::Policy<crate::Body, super::Error> + Clone + Send + Sync + 'static,
    S: tower::Layer<SharedService<http::Request<crate::Body>, http::Response<crate::Body>, super::Error>>,
    S::Service: tower::Service<http::Request<crate::Body>, Response = http::Response<crate::Body>, Error=super::Error>
        + Clone
        + Send
        + Sync
        + 'static,
    <S::Service as tower::Service<http::Request<crate::Body>>>::Future: Send + 'static,
{
    /// Build the client.
    pub fn build(self) -> Client {
        Client::new_from_service(self.build_service())
    }
}

#[cfg(feature = "tls")]
impl<T, P, RP, S> Builder<T, P, RP, S, crate::Body, crate::Body>
where
    T: Transport<http::Request<crate::Body>> + Clone + Send + Sync + 'static,
    T::Error: Into<BoxError>,
    AutoTlsTransport<T>: Transport<
            http::Request<crate::Body>,
            Error = TlsConnectionError<<T as Transport<http::Request<crate::Body>>>::Error>,
            Future = TransportBraidFuture<T, http::Request<crate::Body>>,
            IO = Stream<<T as Transport<http::Request<crate::Body>>>::IO>,
        >,
    <T as Transport<http::Request<crate::Body>>>::IO:
        PoolableStream + HasConnectionInfo + AsyncRead + AsyncWrite + Unpin,
    <<T as Transport<http::Request<crate::Body>>>::IO as HasConnectionInfo>::Addr:
        Clone + Send + Unpin,
    P: Protocol<
            Stream<<T as Transport<http::Request<crate::Body>>>::IO>,
            http::Request<crate::Body>,
        > + Clone
        + Send
        + Sync
        + 'static,
    <P as Protocol<
        Stream<<T as Transport<http::Request<crate::Body>>>::IO>,
        http::Request<crate::Body>,
    >>::Error: Into<BoxError>,
    <P as Protocol<
        Stream<<T as Transport<http::Request<crate::Body>>>::IO>,
        http::Request<crate::Body>,
    >>::Connection: Connection<http::Request<crate::Body>, Response = http::Response<hyper::body::Incoming>>
        + HttpConnectionInfo<crate::Body>
        + PoolableConnection<http::Request<crate::Body>>,
    <<P as chateau::client::conn::Protocol<
        Stream<<T as Transport<http::Request<crate::Body>>>::IO>,
        http::Request<crate::Body>,
    >>::Connection as Connection<http::Request<crate::Body>>>::Error: Into<BoxError>,
    RP: policy::Policy<crate::Body, super::Error> + Clone + Send + Sync + 'static,
    S: tower::Layer<
            SharedService<http::Request<crate::Body>, http::Response<crate::Body>, super::Error>,
        >,
    S::Service: tower::Service<
            http::Request<crate::Body>,
            Response = http::Response<crate::Body>,
            Error = super::Error,
        > + Clone
        + Send
        + Sync
        + 'static,
    <S::Service as tower::Service<http::Request<crate::Body>>>::Future: Send + 'static,
{
    /// Build the client.
    pub fn build(self) -> Client {
        Client::new_from_service(self.build_service())
    }
}

#[cfg(test)]
mod tests {
    use super::Builder;

    #[test]
    fn build_default_compiles() {
        #[cfg(feature = "tls")]
        {
            crate::fixtures::tls_install_default();
        }

        let _ = Builder::default().build();
    }
}