From 3fa23d93f31f964c3aaccf76be82ad4ae002ddd8 Mon Sep 17 00:00:00 2001 From: Valdemar Erk Date: Tue, 27 Jun 2023 13:23:26 +0200 Subject: [PATCH] remove the worker related files as I plan to go with reqwest --- twilight-http/src/http/mod.rs | 5 -- twilight-http/src/http/worker/mod.rs | 111 --------------------------- twilight-http/src/response/mod.rs | 15 ---- 3 files changed, 131 deletions(-) delete mode 100644 twilight-http/src/http/worker/mod.rs diff --git a/twilight-http/src/http/mod.rs b/twilight-http/src/http/mod.rs index 90f202f105d..3e7a339cef3 100644 --- a/twilight-http/src/http/mod.rs +++ b/twilight-http/src/http/mod.rs @@ -10,11 +10,6 @@ mod reqwest; #[cfg(target_arch = "wasm32")] pub use self::reqwest::{HttpClient, RawRequest, RawResponseFuture, RawResponse}; -// #[cfg(target_arch = "wasm32")] -// mod worker; -// #[cfg(target_arch = "wasm32")] -// pub use self::worker::{HttpClient, RawRequest, RawResponseFuture, RawResponse}; - use http::{Method, HeaderMap, HeaderValue, Uri}; pub struct RawRequestBuilder { diff --git a/twilight-http/src/http/worker/mod.rs b/twilight-http/src/http/worker/mod.rs deleted file mode 100644 index aba7c116323..00000000000 --- a/twilight-http/src/http/worker/mod.rs +++ /dev/null @@ -1,111 +0,0 @@ -use std::{ - future::Future, - pin::Pin, - task::{Context, Poll}, -}; - -use http::{HeaderMap, HeaderValue, Method, Uri}; -use worker::{ - js_sys, - wasm_bindgen::{JsCast, JsValue}, - wasm_bindgen_futures::JsFuture, - Headers, Request, RequestInit, Response, -}; -use worker_sys::web_sys::WorkerGlobalScope; - -use crate::{error::ErrorType, Error, response::{BytesFuture, StatusCode}}; - -#[derive(Debug)] -pub struct RawRequest { - request: Request, -} - -#[derive(Debug)] -pub struct HttpClient {} - -impl HttpClient { - pub fn new() -> Self { - HttpClient {} - } - - pub fn request(&self, req: RawRequest) -> RawResponseFuture { - let inner = fetch_with_request(req.request); - RawResponseFuture { inner: Box::new(inner) } - } -} - -// todo(erk): This struct needs to contain a enum since we need to -// read all the data into containers that is Send (+Sync) -// since the worker::Response struct is not. - -#[derive(Debug)] -pub struct RawResponseFuture { - inner: Box>>, -} - -impl RawResponseFuture { - fn inner(&mut self) - -> &mut impl Future> { - self.inner - } -} - -impl Future for RawResponseFuture { - type Output = Result; - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - Pin::new(&mut self.inner) - .poll(cx) - .map(|jsval| from_result(jsval)) - } -} - -#[derive(Debug)] -pub struct RawResponse { - resp: Response, -} - -impl RawResponse { - fn new(resp: Response) -> Self { - RawResponse { resp } - } - - pub fn headers(&self) -> &HeaderMap { - todo!() - } - - pub fn headers_mut(&mut self) -> &mut HeaderMap { - todo!() - } - - pub fn bytes(self, compressed: bool) -> BytesFuture { - BytesFuture::from_worker(self.resp) - } - - pub fn status(&self) -> StatusCode { - StatusCode::new(self.resp.status_code()) - } - -} - -async fn fetch_with_request(request: Request) -> Result { - worker::Fetch::Request(request).send().await -} - -fn from_result(res: Result) -> Result { - match res { - Ok(r) => to_response(r).map(RawResponse::new), - Err(_why) => Err(Error { - kind: ErrorType::RequestError, - source: None, - }), - } -} - -// fn to_response(resp: JsValue) -> Result { -// let edge_response: Response = resp.dyn_into().map_err(|_source| Error { -// kind: ErrorType::RequestError, -// source: None, -// })?; -// Ok(edge_response.into()) -// } diff --git a/twilight-http/src/response/mod.rs b/twilight-http/src/response/mod.rs index ad0494a9a65..0552522bb0a 100644 --- a/twilight-http/src/response/mod.rs +++ b/twilight-http/src/response/mod.rs @@ -444,21 +444,6 @@ impl BytesFuture { } } - // #[cfg(target_arch = "wasm32")] - // pub(crate) fn from_worker(response: ::worker::Response) -> Self { - // let fut = async move { - // response.bytes().await - // .map_err(|source| DeserializeBodyError { - // kind: DeserializeBodyErrorType::Chunking, - // source: None, - // }) - // }; - - // BytesFuture { - // inner: Box::pin(fut), - // } - // } - #[cfg(target_arch = "wasm32")] pub(crate) fn from_reqwest(response: reqwest::Response) -> Self { let fut = async move {