-
Notifications
You must be signed in to change notification settings - Fork 884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjectStore WASM32 Support #7226
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,9 +84,14 @@ impl HttpError { | |
} | ||
|
||
pub(crate) fn reqwest(e: reqwest::Error) -> Self { | ||
#[cfg(not(target_arch = "wasm32"))] | ||
let is_connect = || e.is_connect(); | ||
#[cfg(target_arch = "wasm32")] | ||
let is_connect = || false; | ||
|
||
let mut kind = if e.is_timeout() { | ||
HttpErrorKind::Timeout | ||
} else if e.is_connect() { | ||
} else if is_connect() { | ||
HttpErrorKind::Connect | ||
} else if e.is_decode() { | ||
HttpErrorKind::Decode | ||
|
@@ -200,6 +205,7 @@ impl HttpClient { | |
} | ||
|
||
#[async_trait] | ||
#[cfg(not(target_arch = "wasm32"))] | ||
impl HttpService for reqwest::Client { | ||
async fn call(&self, req: HttpRequest) -> Result<HttpResponse, HttpError> { | ||
let (parts, body) = req.into_parts(); | ||
|
@@ -227,11 +233,37 @@ pub trait HttpConnector: std::fmt::Debug + Send + Sync + 'static { | |
/// [`HttpConnector`] using [`reqwest::Client`] | ||
#[derive(Debug, Default)] | ||
#[allow(missing_copy_implementations)] | ||
#[cfg(not(target_arch = "wasm32"))] | ||
pub struct ReqwestConnector {} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
impl HttpConnector for ReqwestConnector { | ||
fn connect(&self, options: &ClientOptions) -> crate::Result<HttpClient> { | ||
let client = options.client()?; | ||
Ok(HttpClient::new(client)) | ||
} | ||
} | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
pub(crate) fn http_connector( | ||
custom: Option<Arc<dyn HttpConnector>>, | ||
) -> crate::Result<Arc<dyn HttpConnector>> { | ||
match custom { | ||
Some(x) => Ok(x), | ||
None => Err(crate::Error::NotSupported { | ||
source: "WASM32 architectures must provide an HTTPConnector" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At some point it would be great to have an example of implementing WASM / a documentation guide for how to do it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to even go as far as providing first-party support, but I don't have time to figure out the complexities involved. #7227 is my attempt to fish for contributions |
||
.to_string() | ||
.into(), | ||
}), | ||
} | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
pub(crate) fn http_connector( | ||
custom: Option<Arc<dyn HttpConnector>>, | ||
) -> crate::Result<Arc<dyn HttpConnector>> { | ||
match custom { | ||
Some(x) => Ok(x), | ||
None => Ok(Arc::new(ReqwestConnector {})), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉