@@ -15,7 +15,10 @@ use bytes::Bytes;
15
15
use crate :: body:: { Body , Incoming as IncomingBody } ;
16
16
use crate :: proto;
17
17
use crate :: service:: HttpService ;
18
- use crate :: { common:: time:: Time , rt:: Timer } ;
18
+ use crate :: {
19
+ common:: time:: { Dur , Time } ,
20
+ rt:: Timer ,
21
+ } ;
19
22
20
23
type Http1Dispatcher < T , B , S > = proto:: h1:: Dispatcher <
21
24
proto:: h1:: dispatch:: Server < S , IncomingBody > ,
@@ -70,7 +73,7 @@ pub struct Builder {
70
73
h1_keep_alive : bool ,
71
74
h1_title_case_headers : bool ,
72
75
h1_preserve_header_case : bool ,
73
- h1_header_read_timeout : Option < Duration > ,
76
+ h1_header_read_timeout : Dur ,
74
77
h1_writev : Option < bool > ,
75
78
max_buf_size : Option < usize > ,
76
79
pipeline_flush : bool ,
@@ -237,7 +240,7 @@ impl Builder {
237
240
h1_keep_alive : true ,
238
241
h1_title_case_headers : false ,
239
242
h1_preserve_header_case : false ,
240
- h1_header_read_timeout : None ,
243
+ h1_header_read_timeout : Dur :: Default ( None ) ,
241
244
h1_writev : None ,
242
245
max_buf_size : None ,
243
246
pipeline_flush : false ,
@@ -293,8 +296,8 @@ impl Builder {
293
296
/// transmit the entire header within this time, the connection is closed.
294
297
///
295
298
/// Default is None.
296
- pub fn header_read_timeout ( & mut self , read_timeout : Duration ) -> & mut Self {
297
- self . h1_header_read_timeout = Some ( read_timeout) ;
299
+ pub fn header_read_timeout ( & mut self , read_timeout : impl Into < Option < Duration > > ) -> & mut Self {
300
+ self . h1_header_read_timeout = Dur :: Configured ( read_timeout. into ( ) ) ;
298
301
self
299
302
}
300
303
@@ -355,6 +358,11 @@ impl Builder {
355
358
/// This returns a Future that must be polled in order for HTTP to be
356
359
/// driven on the connection.
357
360
///
361
+ /// # Panics
362
+ ///
363
+ /// If a timeout option has been configured, but a `timer` has not been
364
+ /// provided, calling `serve_connection` will panic.
365
+ ///
358
366
/// # Example
359
367
///
360
368
/// ```
@@ -400,9 +408,9 @@ impl Builder {
400
408
if self . h1_preserve_header_case {
401
409
conn. set_preserve_header_case ( ) ;
402
410
}
403
- if let Some ( header_read_timeout ) = self . h1_header_read_timeout {
404
- conn. set_http1_header_read_timeout ( header_read_timeout ) ;
405
- }
411
+ check_timer ! ( self . h1_header_read_timeout, timer , |dur| {
412
+ conn. set_http1_header_read_timeout( dur ) ;
413
+ } ) ;
406
414
if let Some ( writev) = self . h1_writev {
407
415
if writev {
408
416
conn. set_write_strategy_queue ( ) ;
0 commit comments