Skip to content

Commit 3cfde64

Browse files
committed
Clean up http type conversions
1 parent 6d312f6 commit 3cfde64

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

src/reqwest.rs

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,9 @@ mod blocking {
7272

7373
#[cfg(feature = "reqwest-010")]
7474
{
75-
let headers = response
76-
.headers()
77-
.iter()
78-
.map(|(name, value)| {
79-
(
80-
http::header::HeaderName::from_bytes(name.as_str().as_ref())
81-
.expect("failed to convert HeaderName from http 0.2 to 0.1"),
82-
http::HeaderValue::from_bytes(value.as_bytes())
83-
.expect("failed to convert HeaderValue from http 0.2 to 0.1"),
84-
)
85-
})
86-
.collect::<http::HeaderMap>();
8775
Ok(HttpResponse {
88-
status_code: http::StatusCode::from_u16(response.status().as_u16())
89-
.expect("failed to convert StatusCode from http 0.2 to 0.1"),
90-
headers,
76+
status_code: response.status(),
77+
headers: response.headers().to_owned(),
9178
body,
9279
})
9380
}
@@ -99,10 +86,7 @@ mod async_client {
9986
use super::Error;
10087

10188
pub use reqwest_0_10 as reqwest;
102-
use reqwest_0_10::redirect::Policy as RediretPolicy;
103-
104-
use http::header::HeaderName;
105-
use http::{HeaderMap, HeaderValue, StatusCode};
89+
use reqwest_0_10::redirect::Policy as RedirectPolicy;
10690

10791
///
10892
/// Asynchronous HTTP client.
@@ -112,7 +96,7 @@ mod async_client {
11296
) -> Result<HttpResponse, Error<reqwest::Error>> {
11397
let client = reqwest::Client::builder()
11498
// Following redirects opens the client up to SSRF vulnerabilities.
115-
.redirect(RediretPolicy::none())
99+
.redirect(RedirectPolicy::none())
116100
.build()
117101
.map_err(Error::Reqwest)?;
118102

@@ -127,22 +111,10 @@ mod async_client {
127111
let response = client.execute(request).await.map_err(Error::Reqwest)?;
128112

129113
let status_code = response.status();
130-
let headers = response
131-
.headers()
132-
.iter()
133-
.map(|(name, value)| {
134-
(
135-
HeaderName::from_bytes(name.as_str().as_ref())
136-
.expect("failed to convert HeaderName from http 0.2 to 0.1"),
137-
HeaderValue::from_bytes(value.as_bytes())
138-
.expect("failed to convert HeaderValue from http 0.2 to 0.1"),
139-
)
140-
})
141-
.collect::<HeaderMap>();
114+
let headers = response.headers().to_owned();
142115
let chunks = response.bytes().await.map_err(Error::Reqwest)?;
143116
Ok(HttpResponse {
144-
status_code: StatusCode::from_u16(status_code.as_u16())
145-
.expect("failed to convert StatusCode from http 0.2 to 0.1"),
117+
status_code,
146118
headers,
147119
body: chunks.to_vec(),
148120
})

0 commit comments

Comments
 (0)