Skip to content

Commit

Permalink
fix: Allow characters #, $, %, &, ' in Method (#713)
Browse files Browse the repository at this point in the history
* Allow characters `#`, `$`, `%,` `&,` `'` in HTTP method
* Update method character docomentation to RFC 9110
  • Loading branch information
franfastly authored Aug 7, 2024
1 parent f4e8c0c commit af5df31
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ mod extension {
}
}

// From the HTTP spec section 5.1.1, the HTTP method is case-sensitive and can
// From the RFC 9110 HTTP Semantics, section 9.1, the HTTP method is case-sensitive and can
// contain the following characters:
//
// ```
Expand All @@ -366,7 +366,7 @@ mod extension {
// "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
// ```
//
// https://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01#Method
// https://datatracker.ietf.org/doc/html/rfc9110#section-9.1
//
// Note that this definition means that any &[u8] that consists solely of valid
// characters is also valid UTF-8 because the valid method characters are a
Expand All @@ -377,7 +377,7 @@ mod extension {
b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', // x
b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', // 1x
b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', // 2x
b'\0', b'\0', b'\0', b'!', b'\0', b'\0', b'\0', b'\0', b'\0', b'\0', // 3x
b'\0', b'\0', b'\0', b'!', b'\0', b'#', b'$', b'%', b'&', b'\'', // 3x
b'\0', b'\0', b'*', b'+', b'\0', b'-', b'.', b'\0', b'0', b'1', // 4x
b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'\0', b'\0', // 5x
b'\0', b'\0', b'\0', b'\0', b'\0', b'A', b'B', b'C', b'D', b'E', // 6x
Expand Down Expand Up @@ -466,4 +466,20 @@ mod test {
let long_method = "This_is_a_very_long_method.It_is_valid_but_unlikely.";
assert_eq!(Method::from_str(long_method).unwrap(), long_method);
}

#[test]
fn test_extension_method_chars() {
const VALID_METHOD_CHARS: &str =
"!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

for c in VALID_METHOD_CHARS.chars() {
let c = c.to_string();

assert_eq!(
Method::from_str(&c).unwrap(),
c.as_str(),
"testing {c} is a valid method character"
);
}
}
}

0 comments on commit af5df31

Please sign in to comment.