mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 06:20:02 -04:00
fix issue with null bodies, move npm package to client/
This commit is contained in:
parent
4edf27198a
commit
75c48ccded
8 changed files with 79 additions and 75 deletions
14
.npmignore
14
.npmignore
|
@ -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
4
Cargo.lock
generated
|
@ -357,7 +357,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "epoxy-client"
|
name = "epoxy-client"
|
||||||
version = "1.0.0"
|
version = "1.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-compression",
|
"async-compression",
|
||||||
"async_io_stream",
|
"async_io_stream",
|
||||||
|
@ -1849,7 +1849,7 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wisp-mux"
|
name = "wisp-mux"
|
||||||
version = "1.1.2"
|
version = "1.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async_io_stream",
|
"async_io_stream",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|
5
client/.npmignore
Normal file
5
client/.npmignore
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
build.sh
|
||||||
|
Cargo.toml
|
||||||
|
serve.py
|
||||||
|
src
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "epoxy-client"
|
name = "epoxy-client"
|
||||||
version = "1.1.0"
|
version = "1.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "LGPL-3.0-only"
|
license = "LGPL-3.0-only"
|
||||||
|
|
||||||
|
|
26
client/package.json
Normal file
26
client/package.json
Normal 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"
|
||||||
|
}
|
|
@ -352,6 +352,7 @@ impl EpoxyClient {
|
||||||
.status(resp.status().as_u16())
|
.status(resp.status().as_u16())
|
||||||
.status_text(resp.status().canonical_reason().unwrap_or_default());
|
.status_text(resp.status().canonical_reason().unwrap_or_default());
|
||||||
|
|
||||||
|
let stream = if !utils::is_null_body(resp.status().as_u16()) {
|
||||||
let compression = match resp
|
let compression = match resp
|
||||||
.headers()
|
.headers()
|
||||||
.get("Content-Encoding")
|
.get("Content-Encoding")
|
||||||
|
@ -364,6 +365,7 @@ impl EpoxyClient {
|
||||||
};
|
};
|
||||||
|
|
||||||
let incoming_body = IncomingBody::new(resp.into_body());
|
let incoming_body = IncomingBody::new(resp.into_body());
|
||||||
|
|
||||||
let decompressed_body = match compression {
|
let decompressed_body = match compression {
|
||||||
Some(alg) => match alg {
|
Some(alg) => match alg {
|
||||||
EpxCompression::Gzip => Either::Left(Either::Left(ReaderStream::new(
|
EpxCompression::Gzip => Either::Left(Either::Left(ReaderStream::new(
|
||||||
|
@ -375,18 +377,22 @@ impl EpoxyClient {
|
||||||
},
|
},
|
||||||
None => Either::Right(incoming_body),
|
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(
|
Ok(Uint8Array::from(
|
||||||
x.replace_err_jv("Failed to get frame from response")?
|
x.replace_err_jv("Failed to get frame from response")?
|
||||||
.as_ref(),
|
.as_ref(),
|
||||||
)
|
)
|
||||||
.into())
|
.into())
|
||||||
}));
|
}))
|
||||||
|
.into_raw(),
|
||||||
let resp = web_sys::Response::new_with_opt_readable_stream_and_init(
|
|
||||||
Some(&stream.into_raw()),
|
|
||||||
&respinit,
|
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let resp =
|
||||||
|
web_sys::Response::new_with_opt_readable_stream_and_init(stream.as_ref(), &respinit)
|
||||||
.replace_err("Failed to make response")?;
|
.replace_err("Failed to make response")?;
|
||||||
|
|
||||||
Object::define_property(
|
Object::define_property(
|
||||||
|
|
|
@ -51,11 +51,11 @@ impl<T, E: std::fmt::Debug> ReplaceErr for Result<T, E> {
|
||||||
type Ok = T;
|
type Ok = T;
|
||||||
|
|
||||||
fn replace_err(self, err: &str) -> Result<<Self as ReplaceErr>::Ok, JsError> {
|
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> {
|
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)
|
[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> {
|
pub fn get_is_secure(url: &Uri) -> Result<bool, JsError> {
|
||||||
let url_scheme_str = url.scheme_str().replace_err("URL must have a scheme")?;
|
let url_scheme_str = url.scheme_str().replace_err("URL must have a scheme")?;
|
||||||
match url_scheme_str {
|
match url_scheme_str {
|
||||||
|
|
23
package.json
23
package.json
|
@ -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"
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue