From eca9d42da6cbd6ce99a959bdec3ae93cabd4f258 Mon Sep 17 00:00:00 2001 From: Toshit Chawda Date: Mon, 8 Jul 2024 13:50:54 -0700 Subject: [PATCH] fix readablestream bodies --- Cargo.lock | 2 +- client/Cargo.toml | 2 +- client/demo.js | 10 ++++++++++ client/package.json | 2 +- client/src/utils.rs | 8 ++++---- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e467dfa..2a649ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -511,7 +511,7 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "epoxy-client" -version = "2.0.3" +version = "2.0.4" dependencies = [ "async-compression", "async-trait", diff --git a/client/Cargo.toml b/client/Cargo.toml index 55ea77e..b2c3670 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "epoxy-client" -version = "2.0.3" +version = "2.0.4" edition = "2021" [lib] diff --git a/client/demo.js b/client/demo.js index 0979918..6212777 100644 --- a/client/demo.js +++ b/client/demo.js @@ -63,10 +63,20 @@ onmessage = async (msg) => { return t1 - t0; }; + const readableStream = (buffer) => { + return new ReadableStream({ + start(controller) { + controller.enqueue(buffer); + controller.close(); + } + }); + }; + if (should_feature_test) { let formdata = new FormData(); formdata.append("a", "b"); for (const url of [ + ["https://httpbin.org/post", { method: "POST", body: readableStream((new TextEncoder()).encode("abc")) }], ["https://httpbin.org/get", {}], ["https://httpbin.org/gzip", {}], ["https://httpbin.org/brotli", {}], diff --git a/client/package.json b/client/package.json index caf4fcf..da51ed1 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "@mercuryworkshop/epoxy-tls", - "version": "2.0.3-5", + "version": "2.0.4-1", "description": "A wasm library for using raw encrypted tls/ssl/https/websocket streams on the browser", "scripts": { "build": "./build.sh" diff --git a/client/src/utils.rs b/client/src/utils.rs index 86d9b31..e841a14 100644 --- a/client/src/utils.rs +++ b/client/src/utils.rs @@ -102,10 +102,10 @@ pub fn object_set(obj: &Object, key: &JsValue, value: &JsValue) -> Result<(), Ep } pub async fn convert_body(val: JsValue) -> Result<(Uint8Array, web_sys::Request), JsValue> { - let req = web_sys::Request::new_with_str_and_init( - "/", - web_sys::RequestInit::new().method("POST").body(Some(&val)), - )?; + let mut request_init = web_sys::RequestInit::new(); + request_init.method("POST").body(Some(&val)); + object_set(&request_init, &"duplex".into(), &"half".into())?; + let req = web_sys::Request::new_with_str_and_init("/", &request_init)?; Ok(( JsFuture::from(req.array_buffer()?) .await?