@@ -14,10 +14,12 @@ use http::{
1414use http_body_util:: BodyExt ;
1515use hyper:: {
1616 body:: { Bytes , Incoming } ,
17- server:: conn:: { http1, http2} ,
1817 service:: service_fn,
1918} ;
20- use hyper_util:: rt:: { TokioExecutor , TokioIo } ;
19+ use hyper_util:: {
20+ rt:: { TokioExecutor , TokioIo } ,
21+ server:: conn:: auto:: Builder ,
22+ } ;
2123use spin_app:: { APP_DESCRIPTION_KEY , APP_NAME_KEY } ;
2224use spin_factor_outbound_http:: { OutboundHttpFactor , SelfRequestOrigin } ;
2325use spin_factors:: RuntimeFactors ;
@@ -206,7 +208,7 @@ impl<F: RuntimeFactors> HttpServer<F> {
206208 loop {
207209 let ( stream, client_addr) = listener. accept ( ) . await ?;
208210 self . clone ( )
209- . http1_serve_connection ( stream, Scheme :: HTTP , client_addr) ;
211+ . serve_connection ( stream, Scheme :: HTTP , client_addr) ;
210212 }
211213 }
212214
@@ -220,15 +222,9 @@ impl<F: RuntimeFactors> HttpServer<F> {
220222 loop {
221223 let ( stream, client_addr) = listener. accept ( ) . await ?;
222224 match acceptor. accept ( stream) . await {
223- Ok ( stream) => {
224- if stream. get_ref ( ) . 1 . alpn_protocol ( ) == Some ( b"h2" ) {
225- self . clone ( )
226- . http2_serve_connection ( stream, Scheme :: HTTPS , client_addr)
227- } else {
228- self . clone ( )
229- . http1_serve_connection ( stream, Scheme :: HTTPS , client_addr)
230- }
231- }
225+ Ok ( stream) => self
226+ . clone ( )
227+ . serve_connection ( stream, Scheme :: HTTPS , client_addr) ,
232228 Err ( err) => tracing:: error!( ?err, "Failed to start TLS session" ) ,
233229 }
234230 }
@@ -409,40 +405,14 @@ impl<F: RuntimeFactors> HttpServer<F> {
409405 . body ( body:: empty ( ) ) ?)
410406 }
411407
412- fn http1_serve_connection < S : AsyncRead + AsyncWrite + Unpin + Send + ' static > (
413- self : Arc < Self > ,
414- stream : S ,
415- server_scheme : Scheme ,
416- client_addr : SocketAddr ,
417- ) {
418- task:: spawn ( async move {
419- if let Err ( err) = http1:: Builder :: new ( )
420- . keep_alive ( true )
421- . serve_connection (
422- TokioIo :: new ( stream) ,
423- service_fn ( move |request| {
424- self . clone ( ) . instrumented_service_fn (
425- server_scheme. clone ( ) ,
426- client_addr,
427- request,
428- )
429- } ) ,
430- )
431- . await
432- {
433- tracing:: warn!( "Error serving HTTP1 connection: {err:?}" ) ;
434- }
435- } ) ;
436- }
437-
438- fn http2_serve_connection < S : AsyncRead + AsyncWrite + Unpin + Send + ' static > (
408+ fn serve_connection < S : AsyncRead + AsyncWrite + Unpin + Send + ' static > (
439409 self : Arc < Self > ,
440410 stream : S ,
441411 server_scheme : Scheme ,
442412 client_addr : SocketAddr ,
443413 ) {
444414 task:: spawn ( async move {
445- if let Err ( err) = http2 :: Builder :: new ( TokioExecutor :: new ( ) )
415+ if let Err ( err) = Builder :: new ( TokioExecutor :: new ( ) )
446416 . serve_connection (
447417 TokioIo :: new ( stream) ,
448418 service_fn ( move |request| {
0 commit comments