Set the path and query string before making a request.
This commit is contained in:
parent
3b059d1735
commit
da5ce8ee11
10
src/error.rs
10
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<HyperError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UriError> for Error {
|
||||
fn from(error: UriError) -> Error {
|
||||
Error::Uri(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ParseError> for Error {
|
||||
fn from(error: ParseError) -> Error {
|
||||
Error::Url(error)
|
||||
|
17
src/lib.rs
17
src/lib.rs
@ -106,11 +106,28 @@ where
|
||||
E: Endpoint,
|
||||
<E as 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user