Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/devashishdxt/tonic-web-wasm-client"
readme = "README.md"
categories = ["web-programming", "network-programming", "asynchronous"]
keywords = ["grpc", "grpc-web", "tonic", "wasm"]
edition = "2021"
edition = "2024"

[dependencies]
base64 = "0.22"
Expand Down
2 changes: 1 addition & 1 deletion src/abort_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::time::Duration;

use js_sys::Function;
use wasm_bindgen::{
prelude::{wasm_bindgen, Closure},
JsCast, JsValue,
prelude::{Closure, wasm_bindgen},
};
use web_sys::{AbortController, AbortSignal};

Expand Down
4 changes: 2 additions & 2 deletions src/body_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use std::{
};

use bytes::Bytes;
use futures_util::{stream::empty, Stream, TryStreamExt};
use futures_util::{Stream, TryStreamExt, stream::empty};
use http_body::{Body, Frame};
use js_sys::Uint8Array;
use wasm_streams::readable::IntoStream;

use crate::{abort_guard::AbortGuard, Error};
use crate::{Error, abort_guard::AbortGuard};

pub struct BodyStream {
body_stream: Pin<Box<dyn Stream<Item = Result<Bytes, Error>>>>,
Expand Down
4 changes: 2 additions & 2 deletions src/call.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use http::{
HeaderMap, HeaderValue, Request, Response,
header::{ACCEPT, CONTENT_TYPE},
response::Builder,
HeaderMap, HeaderValue, Request, Response,
};
use http_body_util::BodyExt;
use js_sys::{Array, Uint8Array};
use tonic::body::Body;
use wasm_bindgen::JsValue;
use web_sys::{Headers, RequestCredentials, RequestInit};

use crate::{fetch::fetch, options::FetchOptions, Error, ResponseBody};
use crate::{Error, ResponseBody, fetch::fetch, options::FetchOptions};

pub async fn call(
mut base_url: String,
Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use http::{Request, Response};
use tonic::body::Body;
use tower_service::Service;

use crate::{call::call, options::FetchOptions, Error, ResponseBody};
use crate::{Error, ResponseBody, call::call, options::FetchOptions};

/// `grpc-web` based transport layer for `tonic` clients
#[derive(Debug, Clone)]
Expand Down
13 changes: 6 additions & 7 deletions src/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use js_sys::Promise;
use wasm_bindgen::{prelude::wasm_bindgen, JsCast, JsValue};
use wasm_bindgen::{JsCast, JsValue, prelude::wasm_bindgen};
use wasm_bindgen_futures::JsFuture;
use web_sys::{Request, RequestInit, Response};

Expand All @@ -13,14 +13,13 @@ extern "C" {

fn js_fetch(request: &Request, init: &RequestInit) -> Promise {
let global = js_sys::global();
let key = JsValue::from_str("ServiceWorkerGlobalScope");

if let Ok(true) = js_sys::Reflect::has(&global, &JsValue::from_str("ServiceWorkerGlobalScope"))
{
global
match js_sys::Reflect::has(&global, &key) {
Ok(true) => global
.unchecked_into::<web_sys::ServiceWorkerGlobalScope>()
.fetch_with_request_and_init(request, init)
} else {
fetch_with_request_and_init(request, init)
.fetch_with_request_and_init(request, init),
_ => fetch_with_request_and_init(request, init),
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/response_body.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use std::{
ops::{Deref, DerefMut},
pin::Pin,
task::{ready, Context, Poll},
task::{Context, Poll, ready},
};

use base64::{prelude::BASE64_STANDARD, Engine};
use base64::{Engine, prelude::BASE64_STANDARD};
use byteorder::{BigEndian, ByteOrder};
use bytes::{BufMut, Bytes, BytesMut};
use http::{header::HeaderName, HeaderMap, HeaderValue};
use http::{HeaderMap, HeaderValue, header::HeaderName};
use http_body::Body;
use httparse::{Status, EMPTY_HEADER};
use httparse::{EMPTY_HEADER, Status};
use pin_project::pin_project;
use wasm_bindgen::JsCast;
use web_sys::ReadableStream;

use crate::{abort_guard::AbortGuard, body_stream::BodyStream, content_type::Encoding, Error};
use crate::{Error, abort_guard::AbortGuard, body_stream::BodyStream, content_type::Encoding};

/// If 8th MSB of a frame is `0` for data and `1` for trailer
const TRAILER_BIT: u8 = 0b10000000;
Expand Down Expand Up @@ -146,10 +146,10 @@ impl ResponseBody {

match ready!(this.body_stream.poll_frame(cx)) {
Some(Ok(frame)) => {
if let Some(data) = frame.data_ref() {
if let Err(e) = this.buf.append(data.clone()) {
return Poll::Ready(Err(e));
}
if let Some(data) = frame.data_ref()
&& let Err(e) = this.buf.append(data.clone())
{
return Poll::Ready(Err(e));
};

Poll::Ready(Ok(()))
Expand Down
Loading