fix issue with null bodies, move npm package to client/

This commit is contained in:
Toshit Chawda 2024-03-02 20:16:10 -08:00
parent 4edf27198a
commit 75c48ccded
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
8 changed files with 79 additions and 75 deletions

View file

@ -1,14 +0,0 @@
/target
server/
out/
client/src
client/pkg
client/out
client/demo.js
client/index.html
client/build.sh
client/Cargo.toml
.direnv
Cargo.toml
Cargo.lock
pnpm-lock.yaml

4
Cargo.lock generated
View file

@ -357,7 +357,7 @@ dependencies = [
[[package]]
name = "epoxy-client"
version = "1.0.0"
version = "1.1.1"
dependencies = [
"async-compression",
"async_io_stream",
@ -1849,7 +1849,7 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]]
name = "wisp-mux"
version = "1.1.2"
version = "1.1.3"
dependencies = [
"async_io_stream",
"bytes",

5
client/.npmignore Normal file
View file

@ -0,0 +1,5 @@
build.sh
Cargo.toml
serve.py
src

View file

@ -1,6 +1,6 @@
[package]
name = "epoxy-client"
version = "1.1.0"
version = "1.1.1"
edition = "2021"
license = "LGPL-3.0-only"

26
client/package.json Normal file
View file

@ -0,0 +1,26 @@
{
"name": "@mercuryworkshop/epoxy-tls",
"version": "1.1.1",
"description": "A wasm library for using raw encrypted tls/ssl/https/websocket streams on the browser",
"scripts": {
"build": "./build.sh"
},
"keywords": [
"wasm",
"ssl",
"tls",
"rust",
"proxy",
"http"
],
"author": "MercuryWorkshop",
"repository": {
"type": "git",
"url": "git+https://github.com/MercuryWorkshop/epoxy-tls.git"
},
"license": "LGPL-3.0-only",
"browser": "./pkg/epoxy-module-bundled.js",
"module": "./pkg/epoxy-module-bundled.js",
"main": "./pkg/epoxy-module-bundled.js",
"types": "./pkg/epoxy-module-bundled.d.ts"
}

View file

@ -352,6 +352,7 @@ impl EpoxyClient {
.status(resp.status().as_u16())
.status_text(resp.status().canonical_reason().unwrap_or_default());
let stream = if !utils::is_null_body(resp.status().as_u16()) {
let compression = match resp
.headers()
.get("Content-Encoding")
@ -364,6 +365,7 @@ impl EpoxyClient {
};
let incoming_body = IncomingBody::new(resp.into_body());
let decompressed_body = match compression {
Some(alg) => match alg {
EpxCompression::Gzip => Either::Left(Either::Left(ReaderStream::new(
@ -375,18 +377,22 @@ impl EpoxyClient {
},
None => Either::Right(incoming_body),
};
let stream = wasm_streams::ReadableStream::from_stream(decompressed_body.map(|x| {
Some(
wasm_streams::ReadableStream::from_stream(decompressed_body.map(|x| {
Ok(Uint8Array::from(
x.replace_err_jv("Failed to get frame from response")?
.as_ref(),
)
.into())
}));
let resp = web_sys::Response::new_with_opt_readable_stream_and_init(
Some(&stream.into_raw()),
&respinit,
}))
.into_raw(),
)
} else {
None
};
let resp =
web_sys::Response::new_with_opt_readable_stream_and_init(stream.as_ref(), &respinit)
.replace_err("Failed to make response")?;
Object::define_property(

View file

@ -51,11 +51,11 @@ impl<T, E: std::fmt::Debug> ReplaceErr for Result<T, E> {
type Ok = T;
fn replace_err(self, err: &str) -> Result<<Self as ReplaceErr>::Ok, JsError> {
self.map_err(|_| jerr!(err))
self.map_err(|x| jerr!(&format!("{}, original error: {:?}", err, x)))
}
fn replace_err_jv(self, err: &str) -> Result<<Self as ReplaceErr>::Ok, JsValue> {
self.map_err(|_| jval!(err))
self.map_err(|x| jval!(&format!("{}, original error: {:?}", err, x)))
}
}
@ -165,6 +165,10 @@ pub fn is_redirect(code: u16) -> bool {
[301, 302, 303, 307, 308].contains(&code)
}
pub fn is_null_body(code: u16) -> bool {
[101, 204, 205, 304].contains(&code)
}
pub fn get_is_secure(url: &Uri) -> Result<bool, JsError> {
let url_scheme_str = url.scheme_str().replace_err("URL must have a scheme")?;
match url_scheme_str {

View file

@ -1,23 +0,0 @@
{
"name": "@mercuryworkshop/epoxy-tls",
"version": "1.1.0",
"description": "A wasm library for using raw encrypted tls/ssl/https/websocket streams on the browser",
"scripts": {
"build": "cd client && ./build.sh"
},
"keywords": [
"wasm",
"ssl",
"tls",
"rust",
"proxy",
"http"
],
"author": "MercuryWorkshop",
"repository": "https://github.com/MercuryWorkshop/epoxy-tls",
"license": "LGPL-3.0-only",
"browser": "./client/pkg/epoxy-module-bundled.js",
"module": "./client/pkg/epoxy-module-bundled.js",
"main": "./client/pkg/epoxy-module-bundled.js",
"types": "./client/pkg/epoxy-module-bundled.d.ts"
}