mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -04:00
chrome 69 support
This commit is contained in:
parent
cc21e6c4a2
commit
07a304e9c6
4 changed files with 16 additions and 9 deletions
|
@ -270,7 +270,7 @@ import initEpoxy, { EpoxyClient, EpoxyClientOptions, EpoxyHandlers, info as epox
|
||||||
console.time();
|
console.time();
|
||||||
let resp = await epoxy_client.fetch("https://www.example.com/");
|
let resp = await epoxy_client.fetch("https://www.example.com/");
|
||||||
console.timeEnd();
|
console.timeEnd();
|
||||||
console.log(resp, Object.fromEntries(resp.headers));
|
console.log(resp, resp.rawHeaders);
|
||||||
log(await resp.text());
|
log(await resp.text());
|
||||||
}
|
}
|
||||||
log("done");
|
log("done");
|
||||||
|
|
|
@ -23,9 +23,7 @@ use send_wrapper::SendWrapper;
|
||||||
use stream_provider::{StreamProvider, StreamProviderService};
|
use stream_provider::{StreamProvider, StreamProviderService};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use utils::{
|
use utils::{
|
||||||
asyncread_to_readablestream_stream, convert_body, entries_of_object, is_null_body, is_redirect,
|
asyncread_to_readablestream_stream, convert_body, entries_of_object, from_entries, is_null_body, is_redirect, object_get, object_set, object_truthy, IncomingBody, UriExt, WasmExecutor, WispTransportRead, WispTransportWrite
|
||||||
object_get, object_set, object_truthy, IncomingBody, UriExt, WasmExecutor, WispTransportRead,
|
|
||||||
WispTransportWrite,
|
|
||||||
};
|
};
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use wasm_bindgen_futures::JsFuture;
|
use wasm_bindgen_futures::JsFuture;
|
||||||
|
@ -556,7 +554,7 @@ impl EpoxyClient {
|
||||||
|
|
||||||
let headers = object_truthy(object_get(&options, "headers")).and_then(|val| {
|
let headers = object_truthy(object_get(&options, "headers")).and_then(|val| {
|
||||||
if web_sys::Headers::instanceof(&val) {
|
if web_sys::Headers::instanceof(&val) {
|
||||||
Some(entries_of_object(&Object::from_entries(&val).ok()?))
|
Some(entries_of_object(&from_entries(&val).ok()?))
|
||||||
} else if val.is_truthy() {
|
} else if val.is_truthy() {
|
||||||
Some(entries_of_object(&Object::from(val)))
|
Some(entries_of_object(&Object::from(val)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -621,7 +619,7 @@ impl EpoxyClient {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let response_headers = Object::from_entries(&response_headers)
|
let response_headers = from_entries(&response_headers)
|
||||||
.map_err(|_| EpoxyError::ResponseHeadersFromEntriesFailed)?;
|
.map_err(|_| EpoxyError::ResponseHeadersFromEntriesFailed)?;
|
||||||
|
|
||||||
let response_headers_raw = response.headers().clone();
|
let response_headers_raw = response.headers().clone();
|
||||||
|
|
|
@ -339,6 +339,12 @@ export function ws_key() {
|
||||||
crypto.getRandomValues(key);
|
crypto.getRandomValues(key);
|
||||||
return btoa(Array.from(key).map(String.fromCharCode).join(''));
|
return btoa(Array.from(key).map(String.fromCharCode).join(''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function from_entries(entries){
|
||||||
|
var ret = {};
|
||||||
|
for(var i = 0; i < entries.length; i++) ret[entries[i][0]] = entries[i][1];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
"#)]
|
"#)]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn object_get(obj: &Object, key: &str) -> JsValue;
|
pub fn object_get(obj: &Object, key: &str) -> JsValue;
|
||||||
|
@ -350,6 +356,9 @@ extern "C" {
|
||||||
fn entries_of_object_inner(obj: &Object) -> Vec<Array>;
|
fn entries_of_object_inner(obj: &Object) -> Vec<Array>;
|
||||||
pub fn define_property(obj: &Object, key: &str, val: JsValue);
|
pub fn define_property(obj: &Object, key: &str, val: JsValue);
|
||||||
pub fn ws_key() -> String;
|
pub fn ws_key() -> String;
|
||||||
|
|
||||||
|
#[wasm_bindgen(catch)]
|
||||||
|
pub fn from_entries(iterable: &JsValue) -> Result<Object, JsValue>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn convert_body(val: JsValue) -> Result<(Uint8Array, Option<String>), JsValue> {
|
pub async fn convert_body(val: JsValue) -> Result<(Uint8Array, Option<String>), JsValue> {
|
||||||
|
|
|
@ -16,14 +16,14 @@ use hyper::{
|
||||||
body::Incoming,
|
body::Incoming,
|
||||||
upgrade::{self, Upgraded},
|
upgrade::{self, Upgraded},
|
||||||
};
|
};
|
||||||
use js_sys::{ArrayBuffer, Function, Object, Uint8Array};
|
use js_sys::{ArrayBuffer, Function, Uint8Array};
|
||||||
use tokio::io::WriteHalf;
|
use tokio::io::WriteHalf;
|
||||||
use wasm_bindgen::{prelude::*, JsError, JsValue};
|
use wasm_bindgen::{prelude::*, JsError, JsValue};
|
||||||
use wasm_bindgen_futures::spawn_local;
|
use wasm_bindgen_futures::spawn_local;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
tokioio::TokioIo,
|
tokioio::TokioIo,
|
||||||
utils::{entries_of_object, ws_key},
|
utils::{entries_of_object, from_entries, ws_key},
|
||||||
EpoxyClient, EpoxyError, EpoxyHandlers, HttpBody,
|
EpoxyClient, EpoxyError, EpoxyHandlers, HttpBody,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ impl EpoxyWebSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
if web_sys::Headers::instanceof(&headers)
|
if web_sys::Headers::instanceof(&headers)
|
||||||
&& let Ok(entries) = Object::from_entries(&headers)
|
&& let Ok(entries) = from_entries(&headers)
|
||||||
{
|
{
|
||||||
for header in entries_of_object(&entries) {
|
for header in entries_of_object(&entries) {
|
||||||
request = request.header(&header[0], &header[1]);
|
request = request.header(&header[0], &header[1]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue