feat: add gloo-net HTTP backend for WASM targets#1272
feat: add gloo-net HTTP backend for WASM targets#1272ap-1 wants to merge 4 commits intooxidecomputer:mainfrom
Conversation
|
I haven't taken a thorough look, but on first glance this looks like quite a lot of complexity that isn't particularly of use to us at Oxide. I'd like to propose an alternative approach to see if it might enable what you're building: I don't think Might this address your use case? |
Yes, I think this is a good solution. |
|
If you're interested in working on this approach, I'd suggest we first define a trait, then create an implementation for |
Progenitor previously only supported the
reqwestHTTP backend, which adds bundle size overhead for WASM/browser applications. Thegloo-netlibrary is specifically designed for WASM targets and leverages the browser's native Fetch API.This means we get smaller bundle sizes, better integration with browser APIs (WebSocket, streaming, etc.), and the native browser behavior for connection pooling, timeouts, and TLS. This change adds first-class support for
gloo-netas an alternative HTTP backend.progenitor-impl: AddedHttpBackendenum (Reqwest|Gloo) to represent backend choice throughout code generationprogenitor-client: Implementedgloo_impl.rswith feature parity toreqwest_impl.rs:Error<E>enumResponseValue<T>wrapper for responses with status/headersByteStreamsupport viawasm_streamsfor streaming responsesweb_sys::WebSocketdirectly, rather than HTTP upgrade (since browsers don't exposeWebSocketas an HTTP upgrade)shared.rsfor both backendscargo-progenitor: Added--backendCLI flag (defaults toreqwest) to generate backend-specific code and dependenciesbackendparameter togenerate_api!macrobuild.rs: Addedwith_backend()method toGenerationSettingsexample-wasm/was updated to demonstrate gloo backend usage withHttpBackend::Glooinbuild.rsDesign Decisions
reqwest-clientandgloo-clientinto mutually exclusive features, for the following reasons:reqwestvsgloo-net/web-sys), including some existing dependencies that need to have optional features enabledreqwest::ErrorvsString/serde_json::Error)progenitor-client/src/lib.rsenforces this with compile-time errors. To avoid the same error,example-wasmis excluded from the workspace: it depends onprogenitor-clientwithgloo-client, whereascargo-progenitordepends onprogenitor-clientwithreqwest-client.--backend gloowith the--include-clientflag, which is supposed to inlineprogenitor-clientcode. It's theoretically possible, but I realized the following:wasm-bindgen,web-sys,js-sys) that we'd have to enableusestatementswasm32-unknown-unknownusually have some form of more complex build process using tools likewasm-packortrunkanywayInstead it returns an error message directing users to use the dependency instead.
reqwestdoes something likeClient::new_with_client(url, reqwest::Client), and all configuration happens at construction time.gloo-netuses theClientHookstrait with thepre()andpost()hooks, which allow per-request customization of the Fetch APIRequestInitoptions.Usage
For WASM applications wanting to use the gloo backend: