diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-05-17 01:20:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-17 01:20:32 +0200 |
commit | 867a6d303285cdffd060e6bb4b0e97de73925cfe (patch) | |
tree | 1c1f34b8a57fd6f7950d1b093a4b93f86480e247 /ext/fetch/lib.rs | |
parent | a22388bbd1377f75d3b873c59f6836cd12c2abe5 (diff) |
refactor(node): reimplement http client (#19122)
This commit reimplements most of "node:http" client APIs using
"ext/fetch".
There is some duplicated code and two removed Node compat tests that
will be fixed in follow up PRs.
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/fetch/lib.rs')
-rw-r--r-- | ext/fetch/lib.rs | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 51688a6fc..e41d85ea4 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -66,7 +66,7 @@ pub use reqwest; pub use fs_fetch_handler::FsFetchHandler; -use crate::byte_stream::MpscByteStream; +pub use crate::byte_stream::MpscByteStream; #[derive(Clone)] pub struct Options { @@ -186,9 +186,9 @@ pub fn get_declaration() -> PathBuf { #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct FetchReturn { - request_rid: ResourceId, - request_body_rid: Option<ResourceId>, - cancel_handle_rid: Option<ResourceId>, + pub request_rid: ResourceId, + pub request_body_rid: Option<ResourceId>, + pub cancel_handle_rid: Option<ResourceId>, } pub fn get_or_create_client_from_state( @@ -302,7 +302,7 @@ where } Some(data) => { // If a body is passed, we use it, and don't return a body for streaming. - request = request.body(Vec::from(&*data)); + request = request.body(data.to_vec()); None } } @@ -400,12 +400,12 @@ where #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct FetchResponse { - status: u16, - status_text: String, - headers: Vec<(ByteString, ByteString)>, - url: String, - response_rid: ResourceId, - content_length: Option<u64>, + pub status: u16, + pub status_text: String, + pub headers: Vec<(ByteString, ByteString)>, + pub url: String, + pub response_rid: ResourceId, + pub content_length: Option<u64>, } #[op] @@ -462,8 +462,8 @@ pub async fn op_fetch_send( type CancelableResponseResult = Result<Result<Response, AnyError>, Canceled>; -struct FetchRequestResource( - Pin<Box<dyn Future<Output = CancelableResponseResult>>>, +pub struct FetchRequestResource( + pub Pin<Box<dyn Future<Output = CancelableResponseResult>>>, ); impl Resource for FetchRequestResource { @@ -472,7 +472,7 @@ impl Resource for FetchRequestResource { } } -struct FetchCancelHandle(Rc<CancelHandle>); +pub struct FetchCancelHandle(pub Rc<CancelHandle>); impl Resource for FetchCancelHandle { fn name(&self) -> Cow<str> { @@ -485,8 +485,8 @@ impl Resource for FetchCancelHandle { } pub struct FetchRequestBodyResource { - body: AsyncRefCell<mpsc::Sender<Option<bytes::Bytes>>>, - cancel: CancelHandle, + pub body: AsyncRefCell<mpsc::Sender<Option<bytes::Bytes>>>, + pub cancel: CancelHandle, } impl Resource for FetchRequestBodyResource { @@ -537,10 +537,10 @@ impl Resource for FetchRequestBodyResource { type BytesStream = Pin<Box<dyn Stream<Item = Result<bytes::Bytes, std::io::Error>> + Unpin>>; -struct FetchResponseBodyResource { - reader: AsyncRefCell<Peekable<BytesStream>>, - cancel: CancelHandle, - size: Option<u64>, +pub struct FetchResponseBodyResource { + pub reader: AsyncRefCell<Peekable<BytesStream>>, + pub cancel: CancelHandle, + pub size: Option<u64>, } impl Resource for FetchResponseBodyResource { @@ -590,8 +590,8 @@ impl Resource for FetchResponseBodyResource { } } -struct HttpClientResource { - client: Client, +pub struct HttpClientResource { + pub client: Client, } impl Resource for HttpClientResource { |