Skip to content

Avoid dependency on serde-serialize feature #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ winreg = "0.7"

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3.45"
wasm-bindgen = { version = "0.2.68", features = ["serde-serialize"] }
serde_json = "1.0"
wasm-bindgen = "0.2.68"
wasm-bindgen-futures = "0.4.18"

[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
Expand All @@ -169,6 +170,7 @@ features = [
]

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen = { version = "0.2.68", features = ["serde-serialize"] }
wasm-bindgen-test = "0.3"

[[example]]
Expand Down
13 changes: 7 additions & 6 deletions src/wasm/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use http::{HeaderMap, Method};
use js_sys::Promise;
use js_sys::{Promise, JSON};
use std::{fmt, future::Future, sync::Arc};
use url::Url;
use wasm_bindgen::prelude::{wasm_bindgen, UnwrapThrowExt as _};
Expand Down Expand Up @@ -238,11 +238,12 @@ async fn fetch(req: Request) -> crate::Result<Response> {

for item in js_iter {
let item = item.expect_throw("headers iterator doesn't throw");
let v: Vec<String> = item.into_serde().expect_throw("headers into_serde");
resp = resp.header(
v.get(0).expect_throw("headers name"),
v.get(1).expect_throw("headers value"),
);
let serialized_headers: String = JSON::stringify(&item)
.expect_throw("serialized headers")
.into();
let [name, value]: [String; 2] = serde_json::from_str(&serialized_headers)
.expect_throw("deserializable serialized headers");
resp = resp.header(name, value);
}

resp.body(js_resp)
Expand Down