Expose the final response URL
This commit is contained in:
@@ -4,6 +4,7 @@ use std::io::{self, Read};
|
|||||||
use hyper::header::{Headers, ContentEncoding, ContentLength, Encoding, TransferEncoding};
|
use hyper::header::{Headers, ContentEncoding, ContentLength, Encoding, TransferEncoding};
|
||||||
use hyper::status::StatusCode;
|
use hyper::status::StatusCode;
|
||||||
use hyper::version::HttpVersion;
|
use hyper::version::HttpVersion;
|
||||||
|
use hyper::Url;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
@@ -24,13 +25,15 @@ impl fmt::Debug for Response {
|
|||||||
return match &self.inner {
|
return match &self.inner {
|
||||||
&Decoder::PlainText(ref hyper_response) => {
|
&Decoder::PlainText(ref hyper_response) => {
|
||||||
f.debug_struct("Response")
|
f.debug_struct("Response")
|
||||||
|
.field("url", &hyper_response.url)
|
||||||
.field("status", &hyper_response.status)
|
.field("status", &hyper_response.status)
|
||||||
.field("headers", &hyper_response.headers)
|
.field("headers", &hyper_response.headers)
|
||||||
.field("version", &hyper_response.version)
|
.field("version", &hyper_response.version)
|
||||||
.finish()
|
.finish()
|
||||||
},
|
},
|
||||||
&Decoder::Gzip{ref status, ref version, ref headers, ..} => {
|
&Decoder::Gzip{ref url, ref status, ref version, ref headers, ..} => {
|
||||||
f.debug_struct("Response")
|
f.debug_struct("Response")
|
||||||
|
.field("url", &url)
|
||||||
.field("status", &status)
|
.field("status", &status)
|
||||||
.field("headers", &headers)
|
.field("headers", &headers)
|
||||||
.field("version", &version)
|
.field("version", &version)
|
||||||
@@ -41,6 +44,15 @@ impl fmt::Debug for Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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`.
|
/// Get the `StatusCode`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn status(&self) -> &StatusCode {
|
pub fn status(&self) -> &StatusCode {
|
||||||
@@ -81,6 +93,7 @@ enum Decoder {
|
|||||||
/// A `Gzip` decoder will uncompress the gziped response content before returning it.
|
/// A `Gzip` decoder will uncompress the gziped response content before returning it.
|
||||||
Gzip {
|
Gzip {
|
||||||
decoder: ::libflate::gzip::Decoder<::hyper::client::Response>,
|
decoder: ::libflate::gzip::Decoder<::hyper::client::Response>,
|
||||||
|
url: ::hyper::Url,
|
||||||
headers: ::hyper::header::Headers,
|
headers: ::hyper::header::Headers,
|
||||||
version: ::hyper::version::HttpVersion,
|
version: ::hyper::version::HttpVersion,
|
||||||
status: ::hyper::status::StatusCode,
|
status: ::hyper::status::StatusCode,
|
||||||
@@ -121,6 +134,7 @@ impl Decoder {
|
|||||||
}
|
}
|
||||||
if is_gzip {
|
if is_gzip {
|
||||||
return Decoder::Gzip {
|
return Decoder::Gzip {
|
||||||
|
url: res.url.clone(),
|
||||||
status: res.status.clone(),
|
status: res.status.clone(),
|
||||||
version: res.version.clone(),
|
version: res.version.clone(),
|
||||||
headers: res.headers.clone(),
|
headers: res.headers.clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user