Open Nemo157 opened 4 years ago
Hey @Nemo157; thanks for opening this. Just like Node.js http_types
uses the WHATWG URL spec and only works with fully qualified URLs. The following code should work:
use std::convert::TryFrom;
fn main() {
let request = http::Request::builder()
.method("GET")
.uri("http://localhost:8080/")
.header("Host", "localhost")
.body(http_types::Body::empty())
.unwrap();
http_types::Request::try_from(request).unwrap();
}
We realize this is different from what people may be used to, but being able to rely on every part of the URL being populated after it being constructed makes it significantly easier to work with throughout the code.
This was just an example url of the form provided by hyper
's server component. On the server side a request does not have a fully resolved url associated with it, it only has the path component. I hacked around it for now by injecting an arbitrary scheme and host, but this seems like something that should be part of the builtin conversion given that hyper::Request
is expected to have a relative url.
If I do have to inject this myself, then what is expected from an http-service
consumers point-of-view? http-service-h1
appears to inject the bind address, but this is not something I have access to.
When converting an
http::Request
fromhyper
to anhttp_types::Request
theurl
fails to convert with an error:small example problem showing the failure: