From 44c7ccb46de2b70518aa99011c48a025ba9f592b Mon Sep 17 00:00:00 2001 From: Cyril Plisko Date: Fri, 7 Apr 2017 17:15:14 +0300 Subject: [PATCH] Expose the final response URL --- src/response.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/response.rs b/src/response.rs index d7226a7..1b7ce03 100644 --- a/src/response.rs +++ b/src/response.rs @@ -4,6 +4,7 @@ use std::io::{self, Read}; use hyper::header::{Headers, ContentEncoding, ContentLength, Encoding, TransferEncoding}; use hyper::status::StatusCode; use hyper::version::HttpVersion; +use hyper::Url; use serde::Deserialize; use serde_json; @@ -24,13 +25,15 @@ impl fmt::Debug for Response { return match &self.inner { &Decoder::PlainText(ref hyper_response) => { f.debug_struct("Response") + .field("url", &hyper_response.url) .field("status", &hyper_response.status) .field("headers", &hyper_response.headers) .field("version", &hyper_response.version) .finish() }, - &Decoder::Gzip{ref status, ref version, ref headers, ..} => { + &Decoder::Gzip{ref url, ref status, ref version, ref headers, ..} => { f.debug_struct("Response") + .field("url", &url) .field("status", &status) .field("headers", &headers) .field("version", &version) @@ -41,6 +44,15 @@ impl fmt::Debug for Response { } impl Response { + /// Get the final `Url` of this response. + #[inline] + pub fn url(&self) -> &Url { + match &self.inner { + &Decoder::PlainText(ref hyper_response) => &hyper_response.url, + &Decoder::Gzip{ref url, ..} => url, + } + } + /// Get the `StatusCode`. #[inline] pub fn status(&self) -> &StatusCode { @@ -81,6 +93,7 @@ enum Decoder { /// A `Gzip` decoder will uncompress the gziped response content before returning it. Gzip { decoder: ::libflate::gzip::Decoder<::hyper::client::Response>, + url: ::hyper::Url, headers: ::hyper::header::Headers, version: ::hyper::version::HttpVersion, status: ::hyper::status::StatusCode, @@ -121,6 +134,7 @@ impl Decoder { } if is_gzip { return Decoder::Gzip { + url: res.url.clone(), status: res.status.clone(), version: res.version.clone(), headers: res.headers.clone(),