Skip to content

Commit d1ec7c4

Browse files
派卡 (pi-cla)Ruben2424
派卡 (pi-cla)
andauthored
Ensure authority and/or host fields are not empty (#232)
* Ensure authority and/or host fields are not empty * Move doc comment --------- Co-authored-by: ruben <[email protected]>
1 parent 793bd17 commit d1ec7c4

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

h3/src/proto/headers.rs

+39-5
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ impl Header {
7575
//# request MUST contain either an :authority pseudo-header field or a
7676
//# Host header field.
7777

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-
8378
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
8479
//= type=TODO
8580
//# If the scheme does not have a mandatory authority component and none
@@ -99,6 +94,10 @@ impl Header {
9994

10095
Ok((
10196
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.
102101
uri.build().map_err(HeaderError::InvalidRequest)?,
103102
self.pseudo.protocol,
104103
self.fields,
@@ -291,6 +290,9 @@ impl Field {
291290

292291
Ok(match name {
293292
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.
294296
b":authority" => Field::Authority(try_value(name, value)?),
295297
b":path" => Field::Path(try_value(name, value)?),
296298
b":method" => Field::Method(
@@ -498,6 +500,38 @@ mod tests {
498500
);
499501
}
500502

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+
501535
#[test]
502536
fn request_has_authority() {
503537
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1

0 commit comments

Comments
 (0)