@@ -57,7 +57,7 @@ pub struct Error {
57
57
kind : ErrorKind ,
58
58
source : Option < Box < dyn StdError + Send + Sync > > ,
59
59
#[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
60
- connect_info : Option < Connected > ,
60
+ connect_info : Option < ErroredConnectInfo > ,
61
61
}
62
62
63
63
#[ derive( Debug ) ]
@@ -71,6 +71,34 @@ enum ErrorKind {
71
71
SendRequest ,
72
72
}
73
73
74
+ /// Extra information about a failed connection.
75
+ pub struct ErroredConnectInfo {
76
+ conn_info : Connected ,
77
+ is_reused : bool ,
78
+ }
79
+
80
+ impl ErroredConnectInfo {
81
+ /// Determines if the connected transport is to an HTTP proxy.
82
+ pub fn is_proxied ( & self ) -> bool {
83
+ self . conn_info . is_proxied ( )
84
+ }
85
+
86
+ /// Copies the extra connection information into an `Extensions` map.
87
+ pub fn get_extras ( & self , extensions : & mut http:: Extensions ) {
88
+ self . conn_info . get_extras ( extensions) ;
89
+ }
90
+
91
+ /// Determines if the connected transport negotiated HTTP/2 as its next protocol.
92
+ pub fn is_negotiated_h2 ( & self ) -> bool {
93
+ self . conn_info . is_negotiated_h2 ( )
94
+ }
95
+
96
+ /// Determines if the connection is a reused one from the connection pool.
97
+ pub fn is_reused ( & self ) -> bool {
98
+ self . is_reused
99
+ }
100
+ }
101
+
74
102
macro_rules! e {
75
103
( $kind: ident) => {
76
104
Error {
@@ -282,7 +310,7 @@ where
282
310
if req. version ( ) == Version :: HTTP_2 {
283
311
warn ! ( "Connection is HTTP/1, but request requires HTTP/2" ) ;
284
312
return Err ( TrySendError :: Nope (
285
- e ! ( UserUnsupportedVersion ) . with_connect_info ( pooled. conn_info . clone ( ) ) ,
313
+ e ! ( UserUnsupportedVersion ) . with_connect_info ( & pooled) ,
286
314
) ) ;
287
315
}
288
316
@@ -317,14 +345,12 @@ where
317
345
Err ( mut err) => {
318
346
return if let Some ( req) = err. take_message ( ) {
319
347
Err ( TrySendError :: Retryable {
320
- error : e ! ( Canceled , err. into_error( ) )
321
- . with_connect_info ( pooled. conn_info . clone ( ) ) ,
348
+ error : e ! ( Canceled , err. into_error( ) ) . with_connect_info ( & pooled) ,
322
349
req,
323
350
} )
324
351
} else {
325
352
Err ( TrySendError :: Nope (
326
- e ! ( SendRequest , err. into_error( ) )
327
- . with_connect_info ( pooled. conn_info . clone ( ) ) ,
353
+ e ! ( SendRequest , err. into_error( ) ) . with_connect_info ( & pooled) ,
328
354
) )
329
355
}
330
356
}
@@ -1619,14 +1645,20 @@ impl Error {
1619
1645
1620
1646
/// Returns the info of the client connection on which this error occurred.
1621
1647
#[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
1622
- pub fn connect_info ( & self ) -> Option < & Connected > {
1648
+ pub fn connect_info ( & self ) -> Option < & ErroredConnectInfo > {
1623
1649
self . connect_info . as_ref ( )
1624
1650
}
1625
1651
1626
1652
#[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
1627
- fn with_connect_info ( self , connect_info : Connected ) -> Self {
1653
+ fn with_connect_info < B > ( self , pooled : & pool:: Pooled < PoolClient < B > , PoolKey > ) -> Self
1654
+ where
1655
+ B : Send + ' static ,
1656
+ {
1628
1657
Self {
1629
- connect_info : Some ( connect_info) ,
1658
+ connect_info : Some ( ErroredConnectInfo {
1659
+ conn_info : pooled. conn_info . clone ( ) ,
1660
+ is_reused : pooled. is_reused ( ) ,
1661
+ } ) ,
1630
1662
..self
1631
1663
}
1632
1664
}
0 commit comments