@@ -13,22 +13,17 @@ use std::{
1313 future:: Future ,
1414 pin:: Pin ,
1515 task:: { Context , Poll } ,
16- time:: Duration ,
1716} ;
1817use tower:: { util:: ServiceExt , Service } ;
19- use tracing:: { debug, info_span, trace } ;
18+ use tracing:: { debug, info_span} ;
2019use tracing_futures:: Instrument ;
2120
2221type Server = hyper:: server:: conn:: Http < trace:: Executor > ;
2322
24- #[ derive( Copy , Clone , Debug ) ]
25- pub struct DetectTimeout ( ( ) ) ;
26-
2723#[ derive( Clone , Debug ) ]
2824pub struct DetectHttp < F , H > {
2925 tcp : F ,
3026 http : H ,
31- timeout : Duration ,
3227 server : Server ,
3328 drain : drain:: Watch ,
3429}
@@ -45,7 +40,6 @@ pub struct DetectHttp<F, H> {
4540pub struct AcceptHttp < F , H > {
4641 tcp : F ,
4742 http : H ,
48- timeout : Duration ,
4943 server : hyper:: server:: conn:: Http < trace:: Executor > ,
5044 drain : drain:: Watch ,
5145}
@@ -54,14 +48,13 @@ pub struct AcceptHttp<F, H> {
5448
5549impl < F , H > DetectHttp < F , H > {
5650 /// Creates a new `AcceptHttp`.
57- pub fn new ( h2 : H2Settings , timeout : Duration , http : H , tcp : F , drain : drain:: Watch ) -> Self {
51+ pub fn new ( h2 : H2Settings , http : H , tcp : F , drain : drain:: Watch ) -> Self {
5852 let mut server = hyper:: server:: conn:: Http :: new ( ) . with_executor ( trace:: Executor :: new ( ) ) ;
5953 server
6054 . http2_initial_stream_window_size ( h2. initial_stream_window_size )
6155 . http2_initial_connection_window_size ( h2. initial_connection_window_size ) ;
6256
6357 Self {
64- timeout,
6558 server,
6659 tcp,
6760 http,
8174 fn new_service ( & mut self , target : T ) -> Self :: Service {
8275 AcceptHttp :: new (
8376 self . server . clone ( ) ,
84- self . timeout ,
8577 self . http . new_service ( target. clone ( ) ) ,
8678 self . tcp . new_service ( target) ,
8779 self . drain . clone ( ) ,
@@ -115,34 +107,32 @@ where
115107 let tcp = self . tcp . clone ( ) ;
116108 let http = self . http . clone ( ) ;
117109 let server = self . server . clone ( ) ;
118- let timeout = self . timeout ;
119110
120111 Box :: pin ( async move {
121112 let ( tcp, http) = futures:: try_join!(
122113 tcp. oneshot( target. clone( ) ) . map_err( Into :: <Error >:: into) ,
123114 http. oneshot( target) . map_err( Into :: <Error >:: into)
124115 ) ?;
125116
126- Ok ( AcceptHttp :: new ( server, timeout , http, tcp, drain) )
117+ Ok ( AcceptHttp :: new ( server, http, tcp, drain) )
127118 } )
128119 }
129120}
130121
131122// === impl AcceptHttp ===
132123
133124impl < F , H > AcceptHttp < F , H > {
134- pub fn new ( server : Server , timeout : Duration , http : H , tcp : F , drain : drain:: Watch ) -> Self {
125+ pub fn new ( server : Server , http : H , tcp : F , drain : drain:: Watch ) -> Self {
135126 Self {
136127 server,
137- timeout,
138128 tcp,
139129 http,
140130 drain,
141131 }
142132 }
143133}
144134
145- impl < I , F , S > Service < I > for AcceptHttp < F , S >
135+ impl < I , F , S > Service < PrefixedIo < I > > for AcceptHttp < F , S >
146136where
147137 I : io:: AsyncRead + io:: AsyncWrite + Send + Unpin + ' static ,
148138 F : tower:: Service < PrefixedIo < I > , Response = ( ) > + Clone + Send + ' static ,
@@ -164,22 +154,14 @@ where
164154 Poll :: Ready ( Ok ( ( ) . into ( ) ) )
165155 }
166156
167- fn call ( & mut self , io : I ) -> Self :: Future {
157+ fn call ( & mut self , io : PrefixedIo < I > ) -> Self :: Future {
168158 let drain = self . drain . clone ( ) ;
169159 let tcp = self . tcp . clone ( ) ;
170160 let http = self . http . clone ( ) ;
171161 let mut server = self . server . clone ( ) ;
172162
173- let timeout = tokio :: time :: delay_for ( self . timeout ) ;
163+ let version = HttpVersion :: from_prefix ( io . prefix ( ) ) ;
174164 Box :: pin ( async move {
175- trace ! ( "Detecting" ) ;
176- let ( version, io) = tokio:: select! {
177- res = HttpVersion :: detect( io) => { res? }
178- ( ) = timeout => {
179- return Err ( DetectTimeout ( ( ) ) . into( ) ) ;
180- }
181- } ;
182-
183165 match version {
184166 Some ( HttpVersion :: Http1 ) => {
185167 debug ! ( "Handling as HTTP" ) ;
@@ -220,11 +202,3 @@ where
220202 } )
221203 }
222204}
223-
224- impl std:: fmt:: Display for DetectTimeout {
225- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
226- write ! ( f, "HTTP detection timeout" )
227- }
228- }
229-
230- impl std:: error:: Error for DetectTimeout { }
0 commit comments