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 ruma_api::Error as RumaApiError;
|
||||||
use serde_json::Error as SerdeJsonError;
|
use serde_json::Error as SerdeJsonError;
|
||||||
use serde_urlencoded::ser::Error as SerdeUrlEncodedSerializeError;
|
use serde_urlencoded::ser::Error as SerdeUrlEncodedSerializeError;
|
||||||
@ -11,6 +11,8 @@ pub enum Error {
|
|||||||
AuthenticationRequired,
|
AuthenticationRequired,
|
||||||
/// An error at the HTTP layer.
|
/// An error at the HTTP layer.
|
||||||
Hyper(HyperError),
|
Hyper(HyperError),
|
||||||
|
/// An error when parsing a string as a URI.
|
||||||
|
Uri(UriError),
|
||||||
/// An error when parsing a string as a URL.
|
/// An error when parsing a string as a URL.
|
||||||
Url(ParseError),
|
Url(ParseError),
|
||||||
/// An error converting between ruma_client_api types and Hyper types.
|
/// 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 {
|
impl From<ParseError> for Error {
|
||||||
fn from(error: ParseError) -> Error {
|
fn from(error: ParseError) -> Error {
|
||||||
Error::Url(error)
|
Error::Url(error)
|
||||||
|
17
src/lib.rs
17
src/lib.rs
@ -106,11 +106,28 @@ where
|
|||||||
E: Endpoint,
|
E: Endpoint,
|
||||||
<E as Endpoint>::Response: 'a,
|
<E as Endpoint>::Response: 'a,
|
||||||
{
|
{
|
||||||
|
let mut url = self.homeserver_url.clone();
|
||||||
|
|
||||||
request
|
request
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.into_future()
|
.into_future()
|
||||||
.and_then(move |hyper_request| {
|
.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
|
self.hyper
|
||||||
.clone()
|
.clone()
|
||||||
.request(hyper_request)
|
.request(hyper_request)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user