116
116
//! [`TcpListener`]: https://docs.rs/tokio-core/0.1/tokio_core/net/struct.TcpListener.html
117
117
118
118
use crate :: codec:: { Codec , RecvError , UserError } ;
119
- use crate :: frame:: { self , Pseudo , PushPromiseHeaderError , Reason , Settings , StreamId } ;
119
+ use crate :: frame:: {
120
+ self , Pseudo , PushPromiseHeaderError , Reason , Settings , StreamId ,
121
+ } ;
120
122
use crate :: proto:: { self , Config , Prioritized } ;
121
123
use crate :: { FlowControl , PingPong , RecvStream , SendStream } ;
122
124
@@ -396,15 +398,18 @@ where
396
398
/// Accept the next incoming request on this connection.
397
399
pub async fn accept (
398
400
& mut self ,
399
- ) -> Option < Result < ( Request < RecvStream > , SendResponse < B > ) , crate :: Error > > {
401
+ ) -> Option < Result < ( Request < RecvStream > , SendResponse < B > ) , crate :: Error > >
402
+ {
400
403
futures_util:: future:: poll_fn ( move |cx| self . poll_accept ( cx) ) . await
401
404
}
402
405
403
406
#[ doc( hidden) ]
404
407
pub fn poll_accept (
405
408
& mut self ,
406
409
cx : & mut Context < ' _ > ,
407
- ) -> Poll < Option < Result < ( Request < RecvStream > , SendResponse < B > ) , crate :: Error > > > {
410
+ ) -> Poll <
411
+ Option < Result < ( Request < RecvStream > , SendResponse < B > ) , crate :: Error > > ,
412
+ > {
408
413
// Always try to advance the internal state. Getting Pending also is
409
414
// needed to allow this function to return Pending.
410
415
if let Poll :: Ready ( _) = self . poll_closed ( cx) ? {
@@ -416,7 +421,8 @@ where
416
421
if let Some ( inner) = self . connection . next_incoming ( ) {
417
422
tracing:: trace!( "received incoming" ) ;
418
423
let ( head, _) = inner. take_request ( ) . into_parts ( ) ;
419
- let body = RecvStream :: new ( FlowControl :: new ( inner. clone_to_opaque ( ) ) ) ;
424
+ let body =
425
+ RecvStream :: new ( FlowControl :: new ( inner. clone_to_opaque ( ) ) ) ;
420
426
421
427
let request = Request :: from_parts ( head, body) ;
422
428
let respond = SendResponse { inner } ;
@@ -462,7 +468,10 @@ where
462
468
///
463
469
/// Returns an error if a previous call is still pending acknowledgement
464
470
/// from the remote endpoint.
465
- pub fn set_initial_window_size ( & mut self , size : u32 ) -> Result < ( ) , crate :: Error > {
471
+ pub fn set_initial_window_size (
472
+ & mut self ,
473
+ size : u32 ,
474
+ ) -> Result < ( ) , crate :: Error > {
466
475
assert ! ( size <= proto:: MAX_WINDOW_SIZE ) ;
467
476
self . connection . set_initial_window_size ( size) ?;
468
477
Ok ( ( ) )
@@ -481,13 +490,19 @@ where
481
490
/// [`poll_accept`]: struct.Connection.html#method.poll_accept
482
491
/// [`RecvStream`]: ../struct.RecvStream.html
483
492
/// [`SendStream`]: ../struct.SendStream.html
484
- pub fn poll_closed ( & mut self , cx : & mut Context ) -> Poll < Result < ( ) , crate :: Error > > {
493
+ pub fn poll_closed (
494
+ & mut self ,
495
+ cx : & mut Context ,
496
+ ) -> Poll < Result < ( ) , crate :: Error > > {
485
497
self . connection . poll ( cx) . map_err ( Into :: into)
486
498
}
487
499
488
500
#[ doc( hidden) ]
489
501
#[ deprecated( note = "renamed to poll_closed" ) ]
490
- pub fn poll_close ( & mut self , cx : & mut Context ) -> Poll < Result < ( ) , crate :: Error > > {
502
+ pub fn poll_close (
503
+ & mut self ,
504
+ cx : & mut Context ,
505
+ ) -> Poll < Result < ( ) , crate :: Error > > {
491
506
self . poll_closed ( cx)
492
507
}
493
508
@@ -539,7 +554,10 @@ where
539
554
{
540
555
type Item = Result < ( Request < RecvStream > , SendResponse < B > ) , crate :: Error > ;
541
556
542
- fn poll_next ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
557
+ fn poll_next (
558
+ mut self : Pin < & mut Self > ,
559
+ cx : & mut Context < ' _ > ,
560
+ ) -> Poll < Option < Self :: Item > > {
543
561
self . poll_accept ( cx)
544
562
}
545
563
}
@@ -586,7 +604,9 @@ impl Builder {
586
604
/// ```
587
605
pub fn new ( ) -> Builder {
588
606
Builder {
589
- reset_stream_duration : Duration :: from_secs ( proto:: DEFAULT_RESET_STREAM_SECS ) ,
607
+ reset_stream_duration : Duration :: from_secs (
608
+ proto:: DEFAULT_RESET_STREAM_SECS ,
609
+ ) ,
590
610
reset_stream_max : proto:: DEFAULT_RESET_STREAM_MAX ,
591
611
settings : Settings :: default ( ) ,
592
612
initial_target_connection_window_size : None ,
@@ -1023,7 +1043,10 @@ impl<B: Buf> SendResponse<B> {
1023
1043
///
1024
1044
/// Calling this method after having called `send_response` will return
1025
1045
/// a user error.
1026
- pub fn poll_reset ( & mut self , cx : & mut Context ) -> Poll < Result < Reason , crate :: Error > > {
1046
+ pub fn poll_reset (
1047
+ & mut self ,
1048
+ cx : & mut Context ,
1049
+ ) -> Poll < Result < Reason , crate :: Error > > {
1027
1050
self . inner . poll_reset ( cx, proto:: PollReset :: AwaitingHeaders )
1028
1051
}
1029
1052
@@ -1095,7 +1118,10 @@ impl<B: Buf> SendPushedResponse<B> {
1095
1118
///
1096
1119
/// Calling this method after having called `send_response` will return
1097
1120
/// a user error.
1098
- pub fn poll_reset ( & mut self , cx : & mut Context ) -> Poll < Result < Reason , crate :: Error > > {
1121
+ pub fn poll_reset (
1122
+ & mut self ,
1123
+ cx : & mut Context ,
1124
+ ) -> Poll < Result < Reason , crate :: Error > > {
1099
1125
self . inner . poll_reset ( cx)
1100
1126
}
1101
1127
@@ -1124,9 +1150,13 @@ where
1124
1150
{
1125
1151
type Output = Result < Codec < T , B > , crate :: Error > ;
1126
1152
1127
- fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
1153
+ fn poll (
1154
+ mut self : Pin < & mut Self > ,
1155
+ cx : & mut Context < ' _ > ,
1156
+ ) -> Poll < Self :: Output > {
1128
1157
// Flush the codec
1129
- ready ! ( self . codec. as_mut( ) . unwrap( ) . flush( cx) ) . map_err ( crate :: Error :: from_io) ?;
1158
+ ready ! ( self . codec. as_mut( ) . unwrap( ) . flush( cx) )
1159
+ . map_err ( crate :: Error :: from_io) ?;
1130
1160
1131
1161
// Return the codec
1132
1162
Poll :: Ready ( Ok ( self . codec . take ( ) . unwrap ( ) ) )
@@ -1153,18 +1183,23 @@ where
1153
1183
{
1154
1184
type Output = Result < Codec < T , B > , crate :: Error > ;
1155
1185
1156
- fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
1186
+ fn poll (
1187
+ mut self : Pin < & mut Self > ,
1188
+ cx : & mut Context < ' _ > ,
1189
+ ) -> Poll < Self :: Output > {
1157
1190
let mut buf = [ 0 ; 24 ] ;
1158
1191
let mut rem = PREFACE . len ( ) - self . pos ;
1159
1192
1160
1193
while rem > 0 {
1161
1194
let n = ready ! ( Pin :: new( self . inner_mut( ) ) . poll_read( cx, & mut buf[ ..rem] ) )
1162
1195
. map_err ( crate :: Error :: from_io) ?;
1163
1196
if n == 0 {
1164
- return Poll :: Ready ( Err ( crate :: Error :: from_io ( io:: Error :: new (
1165
- io:: ErrorKind :: UnexpectedEof ,
1166
- "connection closed before reading preface" ,
1167
- ) ) ) ) ;
1197
+ return Poll :: Ready ( Err ( crate :: Error :: from_io (
1198
+ io:: Error :: new (
1199
+ io:: ErrorKind :: UnexpectedEof ,
1200
+ "connection closed before reading preface" ,
1201
+ ) ,
1202
+ ) ) ) ;
1168
1203
}
1169
1204
1170
1205
if PREFACE [ self . pos ..self . pos + n] != buf[ ..n] {
@@ -1190,7 +1225,10 @@ where
1190
1225
{
1191
1226
type Output = Result < Connection < T , B > , crate :: Error > ;
1192
1227
1193
- fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
1228
+ fn poll (
1229
+ mut self : Pin < & mut Self > ,
1230
+ cx : & mut Context < ' _ > ,
1231
+ ) -> Poll < Self :: Output > {
1194
1232
let span = self . span . clone ( ) ; // XXX(eliza): T_T
1195
1233
let _e = span. enter ( ) ;
1196
1234
tracing:: trace!( state = ?self . state) ;
@@ -1245,7 +1283,8 @@ where
1245
1283
1246
1284
tracing:: trace!( "connection established!" ) ;
1247
1285
let mut c = Connection { connection } ;
1248
- if let Some ( sz) = self . builder . initial_target_connection_window_size {
1286
+ if let Some ( sz) = self . builder . initial_target_connection_window_size
1287
+ {
1249
1288
c. set_target_window_size ( sz) ;
1250
1289
}
1251
1290
Ok ( c)
@@ -1383,7 +1422,9 @@ impl proto::Peer for Peer {
1383
1422
1384
1423
// Specifying :status for a request is a protocol error
1385
1424
if pseudo. status . is_some ( ) {
1386
- tracing:: trace!( "malformed headers: :status field on request; PROTOCOL_ERROR" ) ;
1425
+ tracing:: trace!(
1426
+ "malformed headers: :status field on request; PROTOCOL_ERROR"
1427
+ ) ;
1387
1428
return Err ( RecvError :: Connection ( Reason :: PROTOCOL_ERROR ) ) ;
1388
1429
}
1389
1430
@@ -1393,14 +1434,21 @@ impl proto::Peer for Peer {
1393
1434
// A request translated from HTTP/1 must not include the :authority
1394
1435
// header
1395
1436
if let Some ( authority) = pseudo. authority {
1396
- let maybe_authority = uri:: Authority :: from_maybe_shared ( authority. clone ( ) . into_inner ( ) ) ;
1397
- parts. authority = Some ( maybe_authority. or_else ( |why| {
1398
- malformed ! (
1399
- "malformed headers: malformed authority ({:?}): {}" ,
1400
- authority,
1401
- why,
1402
- )
1403
- } ) ?) ;
1437
+ // When connecting to a UNIX Domain Socket (UDS), then we might get a path for the
1438
+ // authority field. If it's a local path and exists, then we do not error in that case
1439
+ // and assume an UDS.
1440
+ if !authority. as_str ( ) . ends_with ( ".sock" ) {
1441
+ let maybe_authority = uri:: Authority :: from_maybe_shared (
1442
+ authority. clone ( ) . into_inner ( ) ,
1443
+ ) ;
1444
+ parts. authority = Some ( maybe_authority. or_else ( |why| {
1445
+ malformed ! (
1446
+ "malformed headers: malformed authority ({:?}): {}" ,
1447
+ authority,
1448
+ why,
1449
+ )
1450
+ } ) ?) ;
1451
+ }
1404
1452
}
1405
1453
1406
1454
// A :scheme is required, except CONNECT.
@@ -1437,9 +1485,14 @@ impl proto::Peer for Peer {
1437
1485
malformed ! ( "malformed headers: missing path" ) ;
1438
1486
}
1439
1487
1440
- let maybe_path = uri:: PathAndQuery :: from_maybe_shared ( path. clone ( ) . into_inner ( ) ) ;
1488
+ let maybe_path =
1489
+ uri:: PathAndQuery :: from_maybe_shared ( path. clone ( ) . into_inner ( ) ) ;
1441
1490
parts. path_and_query = Some ( maybe_path. or_else ( |why| {
1442
- malformed ! ( "malformed headers: malformed path ({:?}): {}" , path, why, )
1491
+ malformed ! (
1492
+ "malformed headers: malformed path ({:?}): {}" ,
1493
+ path,
1494
+ why,
1495
+ )
1443
1496
} ) ?) ;
1444
1497
}
1445
1498
@@ -1474,7 +1527,9 @@ where
1474
1527
fn fmt ( & self , f : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
1475
1528
match * self {
1476
1529
Handshaking :: Flushing ( _) => write ! ( f, "Handshaking::Flushing(_)" ) ,
1477
- Handshaking :: ReadingPreface ( _) => write ! ( f, "Handshaking::ReadingPreface(_)" ) ,
1530
+ Handshaking :: ReadingPreface ( _) => {
1531
+ write ! ( f, "Handshaking::ReadingPreface(_)" )
1532
+ }
1478
1533
Handshaking :: Empty => write ! ( f, "Handshaking::Empty" ) ,
1479
1534
}
1480
1535
}
@@ -1498,7 +1553,9 @@ where
1498
1553
{
1499
1554
#[ inline]
1500
1555
fn from ( read : ReadPreface < T , Prioritized < B > > ) -> Self {
1501
- Handshaking :: ReadingPreface ( read. instrument ( tracing:: trace_span!( "read_preface" ) ) )
1556
+ Handshaking :: ReadingPreface (
1557
+ read. instrument ( tracing:: trace_span!( "read_preface" ) ) ,
1558
+ )
1502
1559
}
1503
1560
}
1504
1561
0 commit comments