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

allow fetch on worker scripts(web-worker, service-worker) #23

Closed
wants to merge 68 commits into from
Closed

allow fetch on worker scripts(web-worker, service-worker) #23

wants to merge 68 commits into from

Conversation

extraymond
Copy link
Contributor

Hi! I've adapted the code copied from the gloo crate(related_section) to allow wasm-client to use fetch under worker environments.

Stumbled upon this when trying cloudflare workers(which is using service worker).

@extraymond extraymond changed the title allow fetch on worker scripts(web-worker, service-worker) [WIP] allow fetch on worker scripts(web-worker, service-worker) Mar 11, 2020
@extraymond extraymond changed the title [WIP] allow fetch on worker scripts(web-worker, service-worker) allow fetch on worker scripts(web-worker, service-worker) Mar 12, 2020
@extraymond
Copy link
Contributor Author

extraymond commented Jun 2, 2020

@yoshuawuyts Greetings! Would you mind giving me some guidance over making this PR into an acceptable state? While currently http-client -> surf supports running on wasm, it will only allow making requests on the windows_global_scope, which for users seeking to use it inside web-worker or service-worker will receive runtime error by using rust web_sys::window().unwrap()

This PR simply get the global_scope in runtime, so request and fetch api can be used alongside http-client -> surf.

@extraymond
Copy link
Contributor Author

rebase

@goto-bus-stop goto-bus-stop changed the base branch from master to main August 9, 2020 12:58
@yoshuawuyts
Copy link
Member

@extraymond hi! -- sorry for not catching this sooner; yes we should definitely merge this. If you can fix the merge conflicts we can merge + release it.

@extraymond
Copy link
Contributor Author

@yoshuawuyts No biggie, conflict resolved now.

@yoshuawuyts
Copy link
Member

@extraymond it seems the CI is currently failing to compile WASM, and it may also need a cargo fmt pass. Would you mind looking into that?

Fishrock123 and others added 25 commits November 5, 2020 23:40
This fixes a bug where duplicate headers would only use one value.

Possibly related to http-rs/surf#220
Fixes the IsahcClient to work wiith async_trait from
a943eb9
Only the wasm client uses it and it is not light.
Prevents users from writing `HttpClient {}`.
- Makes HyperClient impl Clone and Default
- Re-uses the internal hyper client for pooling and alloc efficiency
- Adds HyperClient::from_client()
- Always uses the HttpsConnector (has internal http fallback)

Required for hyper-client in Surf:
http-rs/surf#234
Avoid leaking Hyper generics into HttpClient by hiding it behind a dynamic trait object pointer.
This fixes a forbid rust_2018_idioms issue.
This release brings improvements for `HyperClient` (`hyper_client` feature).

### Added
- `HyperClient` now impls `Default`.
- `HyperClient::from_client(hyper::Client<C>)`.

### Changed
- `HyperClient` now re-uses the internal client, allowing connection pooling.
@extraymond
Copy link
Contributor Author

rebase again

@extraymond
Copy link
Contributor Author

It seems I'm messing stuff up.
Should have just do it all over again since it's only two code snippets...

@extraymond
Copy link
Contributor Author

continue at #50

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

10 participants