@@ -75,11 +75,6 @@ impl Header {
75
75
//# request MUST contain either an :authority pseudo-header field or a
76
76
//# Host header field.
77
77
78
- //= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
79
- //= type=TODO
80
- //# If these fields are present, they MUST NOT be
81
- //# empty.
82
-
83
78
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
84
79
//= type=TODO
85
80
//# If the scheme does not have a mandatory authority component and none
@@ -99,6 +94,10 @@ impl Header {
99
94
100
95
Ok ( (
101
96
self . pseudo . method . ok_or ( HeaderError :: MissingMethod ) ?,
97
+ // When empty host field is built into a uri it fails
98
+ //= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
99
+ //# If these fields are present, they MUST NOT be
100
+ //# empty.
102
101
uri. build ( ) . map_err ( HeaderError :: InvalidRequest ) ?,
103
102
self . pseudo . protocol ,
104
103
self . fields ,
@@ -291,6 +290,9 @@ impl Field {
291
290
292
291
Ok ( match name {
293
292
b":scheme" => Field :: Scheme ( try_value ( name, value) ?) ,
293
+ //= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
294
+ //# If these fields are present, they MUST NOT be
295
+ //# empty.
294
296
b":authority" => Field :: Authority ( try_value ( name, value) ?) ,
295
297
b":path" => Field :: Path ( try_value ( name, value) ?) ,
296
298
b":method" => Field :: Method (
@@ -498,6 +500,38 @@ mod tests {
498
500
) ;
499
501
}
500
502
503
+ #[ test]
504
+ fn request_has_empty_authority ( ) {
505
+ //= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
506
+ //= type=test
507
+ //# If these fields are present, they MUST NOT be
508
+ //# empty.
509
+ assert_matches ! (
510
+ Header :: try_from( vec![
511
+ ( b":method" , Method :: GET . as_str( ) ) . into( ) ,
512
+ ( b":authority" , b"" ) . into( ) ,
513
+ ] ) ,
514
+ Err ( HeaderError :: InvalidHeaderValue ( _) )
515
+ ) ;
516
+ }
517
+
518
+ #[ test]
519
+ fn request_has_empty_host ( ) {
520
+ //= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
521
+ //= type=test
522
+ //# If these fields are present, they MUST NOT be
523
+ //# empty.
524
+ let headers = Header :: try_from ( vec ! [
525
+ ( b":method" , Method :: GET . as_str( ) ) . into( ) ,
526
+ ( b"host" , b"" ) . into( ) ,
527
+ ] )
528
+ . unwrap ( ) ;
529
+ assert_matches ! (
530
+ headers. into_request_parts( ) ,
531
+ Err ( HeaderError :: InvalidRequest ( _) )
532
+ ) ;
533
+ }
534
+
501
535
#[ test]
502
536
fn request_has_authority ( ) {
503
537
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
0 commit comments