Skip to content
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

WIP: Prototype azure_core WASM support via reqwest #1128

Closed
wants to merge 2 commits into from

Conversation

johnbatty
Copy link
Contributor

In a recent hackathon I managed to get azure_core compiled to WASM and making requests from a browser. This made use of reqwest's WASM support but did require a couple of hacks to work around the fact that it doesn't yet support streaming responses (although there is an open PR which does appear to add this: seanmonstar/reqwest#1576).

Not sure whether you want to take any part of this, but thought I'd make it available in case you are interested!

The main changes are:

  • re-enable inclusion of reqwest and creation of a reqwest http client in the http_client module when the target is wasm32
  • for wasm32 target omit the Send trait when using async_trait
  • for wasm32 target remove support for Body::SeekableStream
  • when receiving a response read all the bytes and wrap it up in a "stream wrapper" (due to lack of a bytes_stream(...) function)
    • this is the hackiest part! Any alternative suggestions welcomed!
  • for wasm32 target remove Send + Sync from the PinnedStream definition
  • add a new feature wasm-bindgen that enables time/wasm-bindgen
    • if this time feature is not enabled then the retry policy code triggers a panic when querying the current time

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@johnbatty
Copy link
Contributor Author

Fyi, to get this working with my azure-devops-rust-api autorust-generated client I just had to replace BoxFuture with LocalBoxFuture to remove the Send trait:
microsoft/azure-devops-rust-api@d3e88b8#diff-54f4194d327855556893a578a400f781df3d8db6549897cc38d0e39da5ccf2bd

@johnbatty johnbatty marked this pull request as draft October 18, 2022 20:16
@@ -24,6 +26,10 @@ impl HttpClient for ::reqwest::Client {

let reqwest_request = match body {
Body::Bytes(bytes) => req.body(bytes).build(),
// Hack... Temporarily remove for wasm32
// Need to implement properly when reqwest has support for streaming body.
// https://github.com/seanmonstar/reqwest/pull/1576
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seanmonstar/reqwest#1576 looks good to me, but has not been merged yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this function was merged to reqwest main last week via seanmonstar/reqwest#1713.

Now just need to wait for it to appear in a release...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is available in reqwest 0.11.14:
https://github.com/seanmonstar/reqwest/releases/tag/v0.11.14

I'll try updating the PR to use the new function...

@johnbatty
Copy link
Contributor Author

Closing, as I've created a new PR with updated changes against the latest codebase: #1367

@johnbatty johnbatty closed this Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants