hyperium / http

Rust HTTP types
Apache License 2.0
1.15k stars 285 forks source link

http::method::Method::FromStr implementation allows invalid methods, conflicting with from_str documentation #681

Closed DaniD3v closed 7 months ago

DaniD3v commented 7 months ago

The from_str method documentation says

Parses a string s to return a value of this type. If parsing succeeds, return the value inside Ok, otherwise when the string is ill-formatted return an error specific to the inside Err.
The error type is specific to the implementation of the trait.

When I use Method::from_str("post") I expect it to error for not HTTP compliant methods instead of simply complying and sending the request.

The header:

post /lti HTTP/1.1
content-type: application/x-www-form-urlencoded
accept: */*
cookie: digi4s=...}
host: kat.digi4school.at
Content-Length: 386
Connection: close

Especially for lowercase methods this can lead to errors that are hard to debug.
Partially because nginx handles wrong methods incorrectly. (See this stackoverflow thread).

seanmonstar commented 7 months ago

The thing is, lower case letters in a method aren't illegal. post is a valid method, even though it's not the same as POST.

DaniD3v commented 7 months ago

The thing is, lower case letters in a method aren't illegal. post is a valid method, even though it's not the same as POST.

What about at least adding a warning by using something like the log crate?