hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.42k stars 1.59k forks source link

Different behavior on invalid URIs between HTTP/1 and HTTP/2 #2736

Open kolbma opened 2 years ago

kolbma commented 2 years ago

Version v0.14.16

Platform Linux

Description When requesting an invalid Uri like GET %2Fhello%2Fworld on an hyper HTTP/1.1 connection the service function doesn't get called and hyper itself returns a BadRequest reponse.

In a HTTP/2 connection the hyper.uri is set to something like http://127.0.0.1:8000%2Fhello%2Fworld (without slash after port) and this gets passed to the service function.
hyper.uri.path_and_query() makes from this magically /%2Fhello%2Fworld (now with slash).

I tried this code:

https://github.com/kolbma/rocket-issues/tree/main/issue1994

I expected to see this happen: hyper should handle it with HTTP/2 the same way like with HTTP/1.1

Instead, this happened: See description

seanmonstar commented 2 years ago

To clarify, do you mean sending a request with hyper::Client? Or do you mean receiving a request with hyper::server?

kolbma commented 2 years ago

It is on server side... Webframework Rocket uses hyper as its base...
Here https://github.com/SergioBenitez/Rocket/blob/8cae077ba1d54b92cdef3e171a730b819d5eeb8e/core/lib/src/server.rs#L459-L465
the service_fn is called on an invalid URI with HTTP/2 while hyper aborts this with HTTP/1.1 with a BadRequest and doesn't call the service_fn.

olix0r commented 2 years ago

Perhaps related to https://github.com/hyperium/http/issues/507 https://github.com/hyperium/http/pull/515