Add support for getting HTTP version of a response
This commit is contained in:
		
				
					committed by
					
						 Sean McArthur
						Sean McArthur
					
				
			
			
				
	
			
			
			
						parent
						
							a52520941f
						
					
				
				
					commit
					12cfbafc28
				
			| @@ -8,7 +8,7 @@ use tokio_io::AsyncRead; | |||||||
| use tokio_io::io as async_io; | use tokio_io::io as async_io; | ||||||
| use futures::{Async, Future, Poll, Stream}; | use futures::{Async, Future, Poll, Stream}; | ||||||
| use futures::stream::Concat2; | use futures::stream::Concat2; | ||||||
| use hyper::StatusCode; | use hyper::{StatusCode, Version}; | ||||||
| use serde::de::DeserializeOwned; | use serde::de::DeserializeOwned; | ||||||
| use serde_json; | use serde_json; | ||||||
| use url::Url; | use url::Url; | ||||||
| @@ -24,6 +24,7 @@ pub struct Response { | |||||||
|     headers: HeaderMap, |     headers: HeaderMap, | ||||||
|     url: Url, |     url: Url, | ||||||
|     body: Decoder, |     body: Decoder, | ||||||
|  |     version: Version, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl Response { | impl Response { | ||||||
| @@ -71,6 +72,12 @@ impl Response { | |||||||
|         &mut self.body |         &mut self.body | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Get the `Version` of this `Response`. | ||||||
|  |     #[inline] | ||||||
|  |     pub fn version(&self) -> &Version { | ||||||
|  |         &self.version | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     /// Try to deserialize the response body as JSON using `serde`. |     /// Try to deserialize the response body as JSON using `serde`. | ||||||
|     #[inline] |     #[inline] | ||||||
| @@ -154,6 +161,7 @@ impl<T> fmt::Debug for Json<T> { | |||||||
|  |  | ||||||
| pub fn new(mut res: ::hyper::Response<::hyper::Body>, url: Url, gzip: bool) -> Response { | pub fn new(mut res: ::hyper::Response<::hyper::Body>, url: Url, gzip: bool) -> Response { | ||||||
|     let status = res.status(); |     let status = res.status(); | ||||||
|  |     let version = res.version(); | ||||||
|     let mut headers = mem::replace(res.headers_mut(), HeaderMap::new()); |     let mut headers = mem::replace(res.headers_mut(), HeaderMap::new()); | ||||||
|     let decoder = decoder::detect(&mut headers, body::wrap(res.into_body()), gzip); |     let decoder = decoder::detect(&mut headers, body::wrap(res.into_body()), gzip); | ||||||
|     debug!("Response: '{}' for {}", status, url); |     debug!("Response: '{}' for {}", status, url); | ||||||
| @@ -162,5 +170,6 @@ pub fn new(mut res: ::hyper::Response<::hyper::Body>, url: Url, gzip: bool) -> R | |||||||
|         headers: headers, |         headers: headers, | ||||||
|         url: url, |         url: url, | ||||||
|         body: decoder, |         body: decoder, | ||||||
|  |         version: version, | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -152,7 +152,7 @@ extern crate uuid; | |||||||
|  |  | ||||||
| pub use hyper::header; | pub use hyper::header; | ||||||
| pub use hyper::Method; | pub use hyper::Method; | ||||||
| pub use hyper::StatusCode; | pub use hyper::{StatusCode, Version}; | ||||||
| pub use url::Url; | pub use url::Url; | ||||||
| pub use url::ParseError as UrlError; | pub use url::ParseError as UrlError; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ use serde_json; | |||||||
|  |  | ||||||
| use client::KeepCoreThreadAlive; | use client::KeepCoreThreadAlive; | ||||||
| use hyper::header::HeaderMap; | use hyper::header::HeaderMap; | ||||||
| use {async_impl, StatusCode, Url, wait}; | use {async_impl, StatusCode, Url, Version, wait}; | ||||||
|  |  | ||||||
| /// A Response to a submitted `Request`. | /// A Response to a submitted `Request`. | ||||||
| pub struct Response { | pub struct Response { | ||||||
| @@ -122,6 +122,12 @@ impl Response { | |||||||
|         self.inner.headers() |         self.inner.headers() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Get the `Version` of this `Response`. | ||||||
|  |     #[inline] | ||||||
|  |     pub fn version(&self) -> &Version { | ||||||
|  |         self.inner.version() | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /// Try and deserialize the response body as JSON using `serde`. |     /// Try and deserialize the response body as JSON using `serde`. | ||||||
|     /// |     /// | ||||||
|     /// # Examples |     /// # Examples | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user