jsdom fetching and resource loader rewrite based on undici #4782
domenic
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Undici community,
I've recently completed a big rewrite of jsdom's fetching and resource loading functionality on top of undici. The PR contains full details on the motivations and API changes from a jsdom perspective.
I want to thank the Undici maintainers for being quite responsive to my bug reports, which help make this feasible.
I would welcome review from the community on my usage of Undici and if there are any better ways to get around the rough edges I encountered. I'll excerpt a part of my PR description that might be of interest:
In terms of files from the PR that are of interest to the Undici community:
jsdom-dispatcher.js: our custom dispatcher. It handlesfile:anddata:URLs independently from undici, then calls into a given "base" dispatcher (by defaultgetGlobalDispatcher()) for HTTP(S) and WebSocket fetches. Along the way it does a lot of jsdom-specific stuff around CORS and cookie handling.request-interceptor.js: our helper function to let people write a Undici interceptor that goesRequest→Promise<Response>. This illustrates some of the complexities around controllers and handlers that I discuss above, with multiple layers of wrapping (createSignalHandler+sendStreamResponse) necessary to get the semantics I want to present to our users.xhr-utils.jsillustrates how, once we have the custom jsdom dispatcher in place, calling it from another part of the codebase is mostly straightforward. (Except the adapter having to deal with abort signals vs. Undici controllers...)Thanks again for a wonderful library!
Beta Was this translation helpful? Give feedback.
All reactions