mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 22:40:01 -04:00
rename wstcp -> epoxy
This commit is contained in:
parent
f035e51256
commit
6e3f968f9c
9 changed files with 72 additions and 70 deletions
|
@ -58,7 +58,7 @@ async fn send_req(
|
|||
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
if let Err(e) = conn.await {
|
||||
error!("wstcp: error in muxed hyper connection! {:?}", e);
|
||||
error!("epoxy: error in muxed hyper connection! {:?}", e);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>wstcp</title>
|
||||
<script src="wstcp_client.js"></script>
|
||||
<title>epoxy</title>
|
||||
<script src="epoxy_client_bundled.js"></script>
|
||||
<script src="index.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
running... (wait for the browser alert)
|
||||
running... (wait for the browser alert if not running ws test)
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
(async () => {
|
||||
console.log(
|
||||
"%cWASM is significantly slower with DevTools open!",
|
||||
"color:red;font-size:2rem;font-weight:bold"
|
||||
"color:red;font-size:3rem;font-weight:bold"
|
||||
);
|
||||
|
||||
const should_feature_test = (new URL(window.location.href)).searchParams.has("feature_test");
|
||||
const should_perf_test = (new URL(window.location.href)).searchParams.has("perf_test");
|
||||
const should_ws_test = (new URL(window.location.href)).searchParams.has("ws_test");
|
||||
|
||||
await wasm_bindgen("./wstcp_client_bg.wasm");
|
||||
await epoxy();
|
||||
|
||||
const tconn0 = performance.now();
|
||||
// args: websocket url, user agent, redirect limit
|
||||
let epoxy = await new wasm_bindgen.EpoxyClient("wss://localhost:4000", navigator.userAgent, 10);
|
||||
let epoxy_client = await new epoxy.EpoxyClient("wss://localhost:4000", navigator.userAgent, 10);
|
||||
const tconn1 = performance.now();
|
||||
console.warn(`conn establish took ${tconn1 - tconn0} ms or ${(tconn1 - tconn0) / 1000} s`);
|
||||
|
||||
|
@ -25,14 +25,14 @@
|
|||
["https://httpbin.org/redirect/11", {}],
|
||||
["https://httpbin.org/redirect/1", { redirect: "manual" }]
|
||||
]) {
|
||||
let resp = await epoxy.fetch(url[0], url[1]);
|
||||
let resp = await epoxy_client.fetch(url[0], url[1]);
|
||||
console.warn(url, resp, Object.fromEntries(resp.headers));
|
||||
console.warn(await resp.text());
|
||||
}
|
||||
} else if (should_perf_test) {
|
||||
const test_mux = async (url) => {
|
||||
const t0 = performance.now();
|
||||
await epoxy.fetch(url);
|
||||
await epoxy_client.fetch(url);
|
||||
const t1 = performance.now();
|
||||
return t1 - t0;
|
||||
};
|
||||
|
@ -62,7 +62,7 @@
|
|||
console.warn(`avg native (10) took ${total_native} ms or ${total_native / 1000} s`);
|
||||
console.warn(`mux - native: ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`);
|
||||
} else if (should_ws_test) {
|
||||
let ws = await epoxy.connect_ws(
|
||||
let ws = await epoxy_client.connect_ws(
|
||||
() => console.log("opened"),
|
||||
() => console.log("closed"),
|
||||
err => console.error(err),
|
||||
|
@ -73,7 +73,7 @@
|
|||
);
|
||||
await ws.send("data");
|
||||
} else {
|
||||
let resp = await epoxy.fetch("https://httpbin.org/get");
|
||||
let resp = await epoxy_client.fetch("https://httpbin.org/get");
|
||||
console.warn(resp, Object.fromEntries(resp.headers));
|
||||
console.warn(await resp.text());
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ impl EpxWebSocket {
|
|||
Err(jerr!("Use EpoxyClient.connect_ws() instead."))
|
||||
}
|
||||
|
||||
|
||||
// shut up
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn connect(
|
||||
|
@ -75,7 +74,7 @@ impl EpxWebSocket {
|
|||
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
if let Err(e) = conn.with_upgrades().await {
|
||||
error!("wstcp: error in muxed hyper connection (ws)! {:?}", e);
|
||||
error!("epoxy: error in muxed hyper connection (ws)! {:?}", e);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -176,7 +175,7 @@ impl EpxWebSocket {
|
|||
// https://github.com/snapview/tungstenite-rs/blob/314feea3055a93e585882fb769854a912a7e6dae/src/handshake/client.rs#L189
|
||||
fn verify(response: &Response<Incoming>) -> Result<(), JsError> {
|
||||
if response.status() != StatusCode::SWITCHING_PROTOCOLS {
|
||||
return Err(jerr!("wstcpws connect: Invalid status code"));
|
||||
return Err(jerr!("epoxy ws connect: Invalid status code"));
|
||||
}
|
||||
|
||||
let headers = response.headers();
|
||||
|
@ -187,7 +186,7 @@ fn verify(response: &Response<Incoming>) -> Result<(), JsError> {
|
|||
.map(|h| h.eq_ignore_ascii_case("websocket"))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Err(jerr!("wstcpws connect: Invalid upgrade header"));
|
||||
return Err(jerr!("epoxy ws connect: Invalid upgrade header"));
|
||||
}
|
||||
|
||||
if !headers
|
||||
|
@ -196,7 +195,7 @@ fn verify(response: &Response<Incoming>) -> Result<(), JsError> {
|
|||
.map(|h| h.eq_ignore_ascii_case("Upgrade"))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Err(jerr!("wstcpws connect: Invalid upgrade header"));
|
||||
return Err(jerr!("epoxy ws connect: Invalid upgrade header"));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue