mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -04:00
fix websockets
This commit is contained in:
parent
4081ea6cce
commit
2c54b54b4f
5 changed files with 30 additions and 11 deletions
|
@ -11,7 +11,7 @@ wasm-bindgen --weak-refs --target no-modules --no-modules-global epoxy --out-dir
|
|||
echo "[ws] bindgen finished"
|
||||
|
||||
mv out/epoxy_client_bg.wasm out/epoxy_client_unoptimized.wasm
|
||||
time wasm-opt out/epoxy_client_unoptimized.wasm -o out/epoxy_client_bg.wasm
|
||||
time wasm-opt -O4 out/epoxy_client_unoptimized.wasm -o out/epoxy_client_bg.wasm
|
||||
echo "[ws] optimized"
|
||||
|
||||
AUTOGENERATED_SOURCE=$(<"out/epoxy_client.js")
|
||||
|
|
|
@ -67,11 +67,13 @@
|
|||
() => console.log("closed"),
|
||||
err => console.error(err),
|
||||
msg => console.log(msg),
|
||||
"ws://localhost:9000",
|
||||
"wss://echo.websocket.events",
|
||||
[],
|
||||
"localhost"
|
||||
);
|
||||
await ws.send("data");
|
||||
while (true) {
|
||||
await ws.send("data");
|
||||
}
|
||||
} else {
|
||||
let resp = await epoxy_client.fetch("https://httpbin.org/get");
|
||||
console.warn(resp, Object.fromEntries(resp.headers));
|
||||
|
|
|
@ -170,7 +170,7 @@ impl EpoxyClient {
|
|||
.await
|
||||
.replace_err("Failed to create multiplexor channel")?;
|
||||
|
||||
if *url.scheme().replace_err("URL must have a scheme")? == uri::Scheme::HTTPS {
|
||||
if utils::get_is_secure(url)? {
|
||||
let cloned_uri = url_host.to_string().clone();
|
||||
let connector = TlsConnector::from(self.rustls_config.clone());
|
||||
let io = connector
|
||||
|
|
|
@ -130,8 +130,27 @@ pub fn is_redirect(code: u16) -> bool {
|
|||
[301, 302, 303, 307, 308].contains(&code)
|
||||
}
|
||||
|
||||
pub fn get_is_secure(url: &Uri) -> Result<bool, JsError> {
|
||||
let url_scheme = url.scheme().replace_err("URL must have a scheme")?;
|
||||
let url_scheme_str = url.scheme_str().replace_err("URL must have a scheme")?;
|
||||
// can't use match, compiler error
|
||||
// error: to use a constant of type `Scheme` in a pattern, `Scheme` must be annotated with `#[derive(PartialEq, Eq)]`
|
||||
if *url_scheme == uri::Scheme::HTTP {
|
||||
Ok(false)
|
||||
} else if *url_scheme == uri::Scheme::HTTPS {
|
||||
Ok(true)
|
||||
} else if url_scheme_str == "ws" {
|
||||
Ok(false)
|
||||
} else if url_scheme_str == "wss" {
|
||||
Ok(true)
|
||||
} else {
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_url_port(url: &Uri) -> Result<u16, JsError> {
|
||||
let url_scheme = url.scheme().replace_err("URL must have a scheme")?;
|
||||
let url_scheme_str = url.scheme_str().replace_err("URL must have a scheme")?;
|
||||
if let Some(port) = url.port() {
|
||||
Ok(port.as_u16())
|
||||
} else {
|
||||
|
@ -141,6 +160,10 @@ pub fn get_url_port(url: &Uri) -> Result<u16, JsError> {
|
|||
Ok(80)
|
||||
} else if *url_scheme == uri::Scheme::HTTPS {
|
||||
Ok(443)
|
||||
} else if url_scheme_str == "ws" {
|
||||
Ok(80)
|
||||
} else if url_scheme_str == "wss" {
|
||||
Ok(443)
|
||||
} else {
|
||||
return Err(jerr!("Failed to coerce port from scheme"));
|
||||
}
|
||||
|
|
|
@ -51,15 +51,9 @@ impl EpxWebSocket {
|
|||
let key = STANDARD.encode(rand);
|
||||
|
||||
|
||||
let pathstr = if let Some(p) = url.path_and_query() {
|
||||
p.to_string()
|
||||
} else {
|
||||
url.path().to_string()
|
||||
};
|
||||
|
||||
let mut builder = Request::builder()
|
||||
.method("GET")
|
||||
.uri(pathstr)
|
||||
.uri(url.clone())
|
||||
.header("Host", host)
|
||||
.header("Origin", origin)
|
||||
.header(UPGRADE, "websocket")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue