File tree Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -346,11 +346,11 @@ impl HttpResponsePreamble {
346
346
}
347
347
348
348
/// Get an RFC 7231 date that represents the current time
349
- fn rfc7231_now ( ) -> String {
349
+ fn rfc7231_now ( ) -> Result < String , CodecError > {
350
350
time:: OffsetDateTime :: now_utc ( )
351
351
. format ( & time:: format_description:: well_known:: Rfc2822 )
352
- . unwrap ( )
353
- . replace ( "+0000 ", "GMT" )
352
+ . map ( |date| date . replace ( "+0000" , "GMT" ) )
353
+ . map_err ( |e| CodecError :: GenericError ( format ! ( "Failed to format RFC 7231 date: {:?} ", e ) ) )
354
354
}
355
355
356
356
/// Read from a stream until we see '\r\n\r\n', with the purpose of reading an HTTP preamble.
@@ -388,7 +388,7 @@ impl StacksMessageCodec for HttpResponsePreamble {
388
388
if !self . headers . contains_key ( "date" ) {
389
389
fd. write_all ( "Date: " . as_bytes ( ) )
390
390
. map_err ( CodecError :: WriteError ) ?;
391
- fd. write_all ( rfc7231_now ( ) . as_bytes ( ) )
391
+ fd. write_all ( rfc7231_now ( ) ? . as_bytes ( ) )
392
392
. map_err ( CodecError :: WriteError ) ?;
393
393
fd. write_all ( "\r \n " . as_bytes ( ) )
394
394
. map_err ( CodecError :: WriteError ) ?;
Original file line number Diff line number Diff line change @@ -393,16 +393,13 @@ fn test_http_response_preamble_headers() {
393
393
) ;
394
394
assert ! ( txt. find( "Date: " ) . is_some( ) , "Date header is missing" ) ;
395
395
396
- // old format
397
- // let date_regex = regex::Regex::new(
398
- // r"Date: [A-Za-z]{3}, [A-Za-z]{3} \d{1,2} \d{4} \d{2}:\d{2}:\d{2} GMT\r\n",
399
- // )
400
- // .unwrap();
401
- // new format rfc7231
402
- let date_regex =
396
+ let rfc7231_date_regex =
403
397
regex:: Regex :: new ( r"Date: [A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT\r\n" )
404
398
. unwrap ( ) ;
405
- assert ! ( date_regex. is_match( & txt) , "Date header format is incorrect" ) ;
399
+ assert ! (
400
+ rfc7231_date_regex. is_match( & txt) ,
401
+ "Date header format is incorrect"
402
+ ) ;
406
403
assert ! ( txt. find( "foo: bar\r \n " ) . is_some( ) , "foo header is missing" ) ;
407
404
assert ! (
408
405
txt. find( "Access-Control-Allow-Origin: *\r \n " ) . is_some( ) ,
You can’t perform that action at this time.
0 commit comments