diff options
author | Justus Winter <teythoon@avior.uberspace.de> | 2018-03-04 16:51:49 +0100 |
---|---|---|
committer | Justus Winter <teythoon@avior.uberspace.de> | 2018-03-04 16:51:49 +0100 |
commit | c993ced88008ba7046938e46658a10e0dd624c99 (patch) | |
tree | 3c47916c3d4ac4b408a9d3c9bae9b83eb4ad6245 /net/src/lib.rs | |
parent | 2fc6905004e0bebf23658ff2a57a4ac6f04f194c (diff) |
net: Use the url crate for URL manipulation.
- The url crate is more expressive than hyper::Uri and among other
things features a 'join' operation.
- This fixes malformed URLs being created by the net module where we
naively using string operations instead of the proper join
operation.
Diffstat (limited to 'net/src/lib.rs')
-rw-r--r-- | net/src/lib.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/net/src/lib.rs b/net/src/lib.rs index 9161df53..94baaa05 100644 --- a/net/src/lib.rs +++ b/net/src/lib.rs @@ -43,21 +43,24 @@ extern crate tokio_core; extern crate tokio_io; #[macro_use] extern crate percent_encoding; +extern crate url; extern crate capnp_rpc; use hyper::client::{FutureResponse, HttpConnector}; -use hyper::{Client, Uri, Request}; +use hyper::{Client, Request}; use hyper_tls::HttpsConnector; use native_tls::Certificate; use std::convert::From; use tokio_core::reactor::Core; +use url::Url; use openpgp::KeyID; use openpgp::tpk::TPK; use sequoia_core::Context; pub mod async; +use async::url2uri; pub mod ipc; /// For accessing keyservers using HKP. @@ -111,13 +114,13 @@ impl KeyServer { } trait AClient { - fn do_get(&mut self, uri: Uri) -> FutureResponse; + fn do_get(&mut self, uri: Url) -> FutureResponse; fn do_request(&mut self, request: Request) -> FutureResponse; } impl AClient for Client<HttpConnector> { - fn do_get(&mut self, uri: Uri) -> FutureResponse { - self.get(uri) + fn do_get(&mut self, uri: Url) -> FutureResponse { + self.get(url2uri(uri)) } fn do_request(&mut self, request: Request) -> FutureResponse { self.request(request) @@ -125,8 +128,8 @@ impl AClient for Client<HttpConnector> { } impl AClient for Client<HttpsConnector<HttpConnector>> { - fn do_get(&mut self, uri: Uri) -> FutureResponse { - self.get(uri) + fn do_get(&mut self, uri: Url) -> FutureResponse { + self.get(url2uri(uri)) } fn do_request(&mut self, request: Request) -> FutureResponse { self.request(request) @@ -156,7 +159,7 @@ pub enum Error { HttpStatus(hyper::StatusCode), /// A `hyper::error::UriError` occurred. #[fail(display = "URI Error")] - UriError(hyper::error::UriError), + UriError(url::ParseError), /// A `hyper::Error` occurred. #[fail(display = "Hyper Error")] HyperError(hyper::Error), @@ -171,8 +174,8 @@ impl From<hyper::Error> for Error { } } -impl From<hyper::error::UriError> for Error { - fn from(e: hyper::error::UriError) -> Error { +impl From<url::ParseError> for Error { + fn from(e: url::ParseError) -> Error { Error::UriError(e) } } |