Revert incoming request URI and header parsing to more closely match 0.4.

This commit is contained in:
Jeb Rosen 2019-12-15 11:01:10 -08:00 committed by Sergio Benitez
parent c2da8a21d8
commit 571e2ac845
3 changed files with 10 additions and 11 deletions

View File

@ -17,7 +17,7 @@
#[doc(hidden)] pub use http::request::Parts as RequestParts;
#[doc(hidden)] pub use http::response::Builder as ResponseBuilder;
#[doc(hidden)] pub use http::status::StatusCode;
#[doc(hidden)] pub use http::uri::Uri;
#[doc(hidden)] pub use http::uri::{Uri, Parts as UriParts};
/// Reexported http header types.
pub mod header {

View File

@ -822,13 +822,14 @@ impl<'r> Request<'r> {
rocket: &'r Rocket,
h_method: hyper::Method,
h_headers: hyper::HeaderMap<hyper::HeaderValue>,
h_uri: hyper::Uri,
h_uri: &'r hyper::Uri,
h_addr: SocketAddr,
) -> Result<Request<'r>, String> {
// TODO.async: Can we avoid this allocation?
// TODO.async: Assert that uri is "absolute"
// Get a copy of the URI for later use.
let uri = h_uri.to_string();
// Get a copy of the URI (only supports path-and-query) for later use.
let uri = match (h_uri.scheme(), h_uri.authority(), h_uri.path_and_query()) {
(None, None, Some(paq)) => paq.as_str(),
_ => return Err(format!("Bad URI: {}", h_uri)),
};
// Ensure that the method is known. TODO: Allow made-up methods?
let method = match Method::from_hyp(&h_method) {
@ -837,7 +838,7 @@ impl<'r> Request<'r> {
};
// We need to re-parse the URI since we don't trust Hyper... :(
let uri = Origin::parse_owned(format!("{}", uri)).map_err(|e| e.to_string())?;
let uri = Origin::parse(uri).map_err(|e| e.to_string())?;
// Construct the request object.
let mut request = Request::new(rocket, method, uri);
@ -846,9 +847,7 @@ impl<'r> Request<'r> {
// Set the request cookies, if they exist.
let mut cookie_jar = CookieJar::new();
for header in h_headers.get_all("Cookie") {
// TODO.async: This used to only allow UTF-8 but now only allows ASCII
// (needs verification)
let raw_str = match header.to_str() {
let raw_str = match std::str::from_utf8(header.as_bytes()) {
Ok(string) => string,
Err(_) => continue
};

View File

@ -65,7 +65,7 @@ fn hyper_service_fn(
let (h_parts, h_body) = hyp_req.into_parts();
// Convert the Hyper request into a Rocket request.
let req_res = Request::from_hyp(&rocket, h_parts.method, h_parts.headers, h_parts.uri, h_addr);
let req_res = Request::from_hyp(&rocket, h_parts.method, h_parts.headers, &h_parts.uri, h_addr);
let mut req = match req_res {
Ok(req) => req,
Err(e) => {