From da5ce8ee117ceecc591ba99bfa456a789ab04101 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Fri, 7 Jul 2017 23:36:05 -0700 Subject: [PATCH] Set the path and query string before making a request. --- src/error.rs | 10 +++++++++- src/lib.rs | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 1cc80fb7..91fdccbb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,4 @@ -use hyper::Error as HyperError; +use hyper::error::{Error as HyperError, UriError}; use ruma_api::Error as RumaApiError; use serde_json::Error as SerdeJsonError; use serde_urlencoded::ser::Error as SerdeUrlEncodedSerializeError; @@ -11,6 +11,8 @@ pub enum Error { AuthenticationRequired, /// An error at the HTTP layer. Hyper(HyperError), + /// An error when parsing a string as a URI. + Uri(UriError), /// An error when parsing a string as a URL. Url(ParseError), /// An error converting between ruma_client_api types and Hyper types. @@ -27,6 +29,12 @@ impl From for Error { } } +impl From for Error { + fn from(error: UriError) -> Error { + Error::Uri(error) + } +} + impl From for Error { fn from(error: ParseError) -> Error { Error::Url(error) diff --git a/src/lib.rs b/src/lib.rs index e221c88c..9afdaf52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,11 +106,28 @@ where E: Endpoint, ::Response: 'a, { + let mut url = self.homeserver_url.clone(); + request .try_into() .map_err(Error::from) .into_future() .and_then(move |hyper_request| { + { + let uri = hyper_request.uri(); + + url.set_path(uri.path()); + url.set_query(uri.query()); + } + + url.into_string() + .parse() + .map(move |uri| (uri, hyper_request)) + .map_err(Error::from) + }) + .and_then(move |(uri, mut hyper_request)| { + hyper_request.set_uri(uri); + self.hyper .clone() .request(hyper_request)