@@ -18,6 +18,7 @@ use crate::service::HttpServerState;
18
18
use crate :: service:: SignallingRc ;
19
19
use crate :: websocket_upgrade:: WebSocketUpgrade ;
20
20
use crate :: LocalExecutor ;
21
+ use crate :: Options ;
21
22
use cache_control:: CacheControl ;
22
23
use deno_core:: external;
23
24
use deno_core:: futures:: future:: poll_fn;
@@ -821,10 +822,16 @@ fn serve_http11_unconditional(
821
822
io : impl HttpServeStream ,
822
823
svc : impl HttpService < Incoming , ResBody = HttpRecordResponse > + ' static ,
823
824
cancel : Rc < CancelHandle > ,
825
+ http1_builder_hook : Option < fn ( http1:: Builder ) -> http1:: Builder > ,
824
826
) -> impl Future < Output = Result < ( ) , hyper:: Error > > + ' static {
825
- let conn = http1:: Builder :: new ( )
826
- . keep_alive ( true )
827
- . writev ( * USE_WRITEV )
827
+ let mut builder = http1:: Builder :: new ( ) ;
828
+ builder. keep_alive ( true ) . writev ( * USE_WRITEV ) ;
829
+
830
+ if let Some ( http1_builder_hook) = http1_builder_hook {
831
+ builder = http1_builder_hook ( builder) ;
832
+ }
833
+
834
+ let conn = builder
828
835
. serve_connection ( TokioIo :: new ( io) , svc)
829
836
. with_upgrades ( ) ;
830
837
@@ -843,9 +850,17 @@ fn serve_http2_unconditional(
843
850
io : impl HttpServeStream ,
844
851
svc : impl HttpService < Incoming , ResBody = HttpRecordResponse > + ' static ,
845
852
cancel : Rc < CancelHandle > ,
853
+ http2_builder_hook : Option <
854
+ fn ( http2:: Builder < LocalExecutor > ) -> http2:: Builder < LocalExecutor > ,
855
+ > ,
846
856
) -> impl Future < Output = Result < ( ) , hyper:: Error > > + ' static {
847
- let conn =
848
- http2:: Builder :: new ( LocalExecutor ) . serve_connection ( TokioIo :: new ( io) , svc) ;
857
+ let mut builder = http2:: Builder :: new ( LocalExecutor ) ;
858
+
859
+ if let Some ( http2_builder_hook) = http2_builder_hook {
860
+ builder = http2_builder_hook ( builder) ;
861
+ }
862
+
863
+ let conn = builder. serve_connection ( TokioIo :: new ( io) , svc) ;
849
864
async {
850
865
match conn. or_abort ( cancel) . await {
851
866
Err ( mut conn) => {
@@ -861,15 +876,16 @@ async fn serve_http2_autodetect(
861
876
io : impl HttpServeStream ,
862
877
svc : impl HttpService < Incoming , ResBody = HttpRecordResponse > + ' static ,
863
878
cancel : Rc < CancelHandle > ,
879
+ options : Options ,
864
880
) -> Result < ( ) , HttpNextError > {
865
881
let prefix = NetworkStreamPrefixCheck :: new ( io, HTTP2_PREFIX ) ;
866
882
let ( matches, io) = prefix. match_prefix ( ) . await ?;
867
883
if matches {
868
- serve_http2_unconditional ( io, svc, cancel)
884
+ serve_http2_unconditional ( io, svc, cancel, options . http2_builder_hook )
869
885
. await
870
886
. map_err ( HttpNextError :: Hyper )
871
887
} else {
872
- serve_http11_unconditional ( io, svc, cancel)
888
+ serve_http11_unconditional ( io, svc, cancel, options . http1_builder_hook )
873
889
. await
874
890
. map_err ( HttpNextError :: Hyper )
875
891
}
@@ -880,6 +896,7 @@ fn serve_https(
880
896
request_info : HttpConnectionProperties ,
881
897
lifetime : HttpLifetime ,
882
898
tx : tokio:: sync:: mpsc:: Sender < Rc < HttpRecord > > ,
899
+ options : Options ,
883
900
) -> JoinHandle < Result < ( ) , HttpNextError > > {
884
901
let HttpLifetime {
885
902
server_state,
@@ -891,21 +908,31 @@ fn serve_https(
891
908
handle_request ( req, request_info. clone ( ) , server_state. clone ( ) , tx. clone ( ) )
892
909
} ) ;
893
910
spawn (
894
- async {
911
+ async move {
895
912
let handshake = io. handshake ( ) . await ?;
896
913
// If the client specifically negotiates a protocol, we will use it. If not, we'll auto-detect
897
914
// based on the prefix bytes
898
915
let handshake = handshake. alpn ;
899
916
if Some ( TLS_ALPN_HTTP_2 ) == handshake. as_deref ( ) {
900
- serve_http2_unconditional ( io, svc, listen_cancel_handle)
901
- . await
902
- . map_err ( HttpNextError :: Hyper )
917
+ serve_http2_unconditional (
918
+ io,
919
+ svc,
920
+ listen_cancel_handle,
921
+ options. http2_builder_hook ,
922
+ )
923
+ . await
924
+ . map_err ( HttpNextError :: Hyper )
903
925
} else if Some ( TLS_ALPN_HTTP_11 ) == handshake. as_deref ( ) {
904
- serve_http11_unconditional ( io, svc, listen_cancel_handle)
905
- . await
906
- . map_err ( HttpNextError :: Hyper )
926
+ serve_http11_unconditional (
927
+ io,
928
+ svc,
929
+ listen_cancel_handle,
930
+ options. http1_builder_hook ,
931
+ )
932
+ . await
933
+ . map_err ( HttpNextError :: Hyper )
907
934
} else {
908
- serve_http2_autodetect ( io, svc, listen_cancel_handle) . await
935
+ serve_http2_autodetect ( io, svc, listen_cancel_handle, options ) . await
909
936
}
910
937
}
911
938
. try_or_cancel ( connection_cancel_handle) ,
@@ -917,6 +944,7 @@ fn serve_http(
917
944
request_info : HttpConnectionProperties ,
918
945
lifetime : HttpLifetime ,
919
946
tx : tokio:: sync:: mpsc:: Sender < Rc < HttpRecord > > ,
947
+ options : Options ,
920
948
) -> JoinHandle < Result < ( ) , HttpNextError > > {
921
949
let HttpLifetime {
922
950
server_state,
@@ -928,7 +956,7 @@ fn serve_http(
928
956
handle_request ( req, request_info. clone ( ) , server_state. clone ( ) , tx. clone ( ) )
929
957
} ) ;
930
958
spawn (
931
- serve_http2_autodetect ( io, svc, listen_cancel_handle)
959
+ serve_http2_autodetect ( io, svc, listen_cancel_handle, options )
932
960
. try_or_cancel ( connection_cancel_handle) ,
933
961
)
934
962
}
@@ -938,6 +966,7 @@ fn serve_http_on<HTTP>(
938
966
listen_properties : & HttpListenProperties ,
939
967
lifetime : HttpLifetime ,
940
968
tx : tokio:: sync:: mpsc:: Sender < Rc < HttpRecord > > ,
969
+ options : Options ,
941
970
) -> JoinHandle < Result < ( ) , HttpNextError > >
942
971
where
943
972
HTTP : HttpPropertyExtractor ,
@@ -949,14 +978,14 @@ where
949
978
950
979
match network_stream {
951
980
NetworkStream :: Tcp ( conn) => {
952
- serve_http ( conn, connection_properties, lifetime, tx)
981
+ serve_http ( conn, connection_properties, lifetime, tx, options )
953
982
}
954
983
NetworkStream :: Tls ( conn) => {
955
- serve_https ( conn, connection_properties, lifetime, tx)
984
+ serve_https ( conn, connection_properties, lifetime, tx, options )
956
985
}
957
986
#[ cfg( unix) ]
958
987
NetworkStream :: Unix ( conn) => {
959
- serve_http ( conn, connection_properties, lifetime, tx)
988
+ serve_http ( conn, connection_properties, lifetime, tx, options )
960
989
}
961
990
}
962
991
}
@@ -1045,6 +1074,11 @@ where
1045
1074
1046
1075
let lifetime = resource. lifetime ( ) ;
1047
1076
1077
+ let options = {
1078
+ let state = state. borrow ( ) ;
1079
+ * state. borrow :: < Options > ( )
1080
+ } ;
1081
+
1048
1082
let listen_properties_clone: HttpListenProperties = listen_properties. clone ( ) ;
1049
1083
let handle = spawn ( async move {
1050
1084
loop {
@@ -1057,6 +1091,7 @@ where
1057
1091
& listen_properties_clone,
1058
1092
lifetime. clone ( ) ,
1059
1093
tx. clone ( ) ,
1094
+ options,
1060
1095
) ;
1061
1096
}
1062
1097
#[ allow( unreachable_code) ]
@@ -1093,11 +1128,17 @@ where
1093
1128
let ( tx, rx) = tokio:: sync:: mpsc:: channel ( 10 ) ;
1094
1129
let resource: Rc < HttpJoinHandle > = Rc :: new ( HttpJoinHandle :: new ( rx) ) ;
1095
1130
1131
+ let options = {
1132
+ let state = state. borrow ( ) ;
1133
+ * state. borrow :: < Options > ( )
1134
+ } ;
1135
+
1096
1136
let handle = serve_http_on :: < HTTP > (
1097
1137
connection,
1098
1138
& listen_properties,
1099
1139
resource. lifetime ( ) ,
1100
1140
tx,
1141
+ options,
1101
1142
) ;
1102
1143
1103
1144
// Set the handle after we start the future
0 commit comments