mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -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]]
|
||||
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
5
client/.npmignore
Normal file
|
@ -0,0 +1,5 @@
|
|||
build.sh
|
||||
Cargo.toml
|
||||
serve.py
|
||||
src
|
||||
|
|
@ -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
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,42 +352,48 @@ impl EpoxyClient {
|
|||
.status(resp.status().as_u16())
|
||||
.status_text(resp.status().canonical_reason().unwrap_or_default());
|
||||
|
||||
let compression = match resp
|
||||
.headers()
|
||||
.get("Content-Encoding")
|
||||
.and_then(|val| val.to_str().ok())
|
||||
.unwrap_or_default()
|
||||
{
|
||||
"gzip" => Some(EpxCompression::Gzip),
|
||||
"br" => Some(EpxCompression::Brotli),
|
||||
_ => None,
|
||||
};
|
||||
let stream = if !utils::is_null_body(resp.status().as_u16()) {
|
||||
let compression = match resp
|
||||
.headers()
|
||||
.get("Content-Encoding")
|
||||
.and_then(|val| val.to_str().ok())
|
||||
.unwrap_or_default()
|
||||
{
|
||||
"gzip" => Some(EpxCompression::Gzip),
|
||||
"br" => Some(EpxCompression::Brotli),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
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(
|
||||
async_comp::GzipDecoder::new(StreamReader::new(incoming_body)),
|
||||
))),
|
||||
EpxCompression::Brotli => Either::Left(Either::Right(ReaderStream::new(
|
||||
async_comp::BrotliDecoder::new(StreamReader::new(incoming_body)),
|
||||
))),
|
||||
},
|
||||
None => Either::Right(incoming_body),
|
||||
};
|
||||
let stream = wasm_streams::ReadableStream::from_stream(decompressed_body.map(|x| {
|
||||
Ok(Uint8Array::from(
|
||||
x.replace_err_jv("Failed to get frame from response")?
|
||||
.as_ref(),
|
||||
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(
|
||||
async_comp::GzipDecoder::new(StreamReader::new(incoming_body)),
|
||||
))),
|
||||
EpxCompression::Brotli => Either::Left(Either::Right(ReaderStream::new(
|
||||
async_comp::BrotliDecoder::new(StreamReader::new(incoming_body)),
|
||||
))),
|
||||
},
|
||||
None => Either::Right(incoming_body),
|
||||
};
|
||||
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())
|
||||
}))
|
||||
.into_raw(),
|
||||
)
|
||||
.into())
|
||||
}));
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let resp = web_sys::Response::new_with_opt_readable_stream_and_init(
|
||||
Some(&stream.into_raw()),
|
||||
&respinit,
|
||||
)
|
||||
.replace_err("Failed to make response")?;
|
||||
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(
|
||||
&resp,
|
||||
|
|
|
@ -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 {
|
||||
|
|
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