From e9bbde6832722cff9bac0069cd33bb7e801f2005 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 29 Mar 2019 16:27:18 -0700 Subject: [PATCH] allow to override request's uri --- awc/CHANGES.md | 2 ++ awc/src/request.rs | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/awc/CHANGES.md b/awc/CHANGES.md index cd97ed86a..e0e832144 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -15,6 +15,8 @@ ### Changed +* Allow to override request's uri + * Export `ws` sub-module with websockets related types diff --git a/awc/src/request.rs b/awc/src/request.rs index a29c3e607..bdde6faf5 100644 --- a/awc/src/request.rs +++ b/awc/src/request.rs @@ -73,25 +73,31 @@ impl ClientRequest { where Uri: HttpTryFrom, { - let mut err = None; - let mut head = RequestHead::default(); - head.method = method; - - match Uri::try_from(uri) { - Ok(uri) => head.uri = uri, - Err(e) => err = Some(e.into()), - } - ClientRequest { - head, - err, config, + head: RequestHead::default(), + err: None, #[cfg(feature = "cookies")] cookies: None, timeout: None, default_headers: true, response_decompress: true, } + .method(method) + .uri(uri) + } + + /// Set HTTP URI of request. + #[inline] + pub fn uri(mut self, uri: U) -> Self + where + Uri: HttpTryFrom, + { + match Uri::try_from(uri) { + Ok(uri) => self.head.uri = uri, + Err(e) => self.err = Some(e.into()), + } + self } /// Set HTTP method of this request.