Skip to content

Commit 4b211dd

Browse files
committed
Fix compilation on wasm32-unknown-unknown
1 parent 0cf1f9f commit 4b211dd

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ wasm_client = ["js-sys", "web-sys", "wasm-bindgen", "wasm-bindgen-futures"]
2525

2626
[dependencies]
2727
futures = { version = "0.3.1" }
28-
http-types = "2.0.1"
28+
http-types = "2.1.0"
2929
log = "0.4.7"
3030

3131
# h1-client

src/wasm.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::{Body, HttpClient, Request, Response};
55
use futures::future::BoxFuture;
66
use futures::prelude::*;
77

8+
use std::convert::TryFrom;
89
use std::io;
910
use std::pin::Pin;
1011
use std::task::{Context, Poll};
@@ -33,17 +34,19 @@ impl HttpClient for WasmClient {
3334

3435
fn send(&self, req: Request) -> BoxFuture<'static, Result<Response, Self::Error>> {
3536
let fut = Box::pin(async move {
36-
let url = format!("{}", req.uri());
37-
let req = fetch::new(req.method().as_str(), &url);
37+
let req = fetch::new(req.method(), req.url());
3838
let mut res = req.send().await?;
3939

4040
let body = res.body_bytes();
41-
let mut response = Response::new(Body::from(body));
42-
*response.status_mut() = http::StatusCode::from_u16(res.status()).unwrap();
43-
41+
let mut response =
42+
Response::new(http_types::StatusCode::try_from(res.status()).unwrap());
43+
response.set_body(Body::from(body));
4444
for (name, value) in res.headers() {
45-
let name: http::header::HeaderName = name.parse().unwrap();
46-
response.headers_mut().insert(name, value.parse().unwrap());
45+
let name: http_types::headers::HeaderName = name.parse().unwrap();
46+
response.insert_header(
47+
&name,
48+
value.parse::<http_types::headers::HeaderValue>().unwrap(),
49+
);
4750
}
4851

4952
Ok(response)

0 commit comments

Comments
 (0)