Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mhart/workers-inspect-test
A demo Worker showing different strategies to inspect the first X kb from a downstream response
https://github.com/mhart/workers-inspect-test
Last synced: 14 days ago
JSON representation
A demo Worker showing different strategies to inspect the first X kb from a downstream response
- Host: GitHub
- URL: https://github.com/mhart/workers-inspect-test
- Owner: mhart
- License: mit
- Created: 2024-03-25T06:01:44.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-03-25T07:55:43.000Z (8 months ago)
- Last Synced: 2024-05-01T22:35:51.383Z (7 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# workers-inspect-test
A demo Worker showing different strategies to inspect the first 10kb from a downstream response, while still providing streaming.
## Approach 1: Cloning
This approach clones the body, so it can be read in parallel.
For the cloned stream, we use a BYOB reader with the `min` argument (this used to be a custom CF extension called `readAtLeast`) so we can read at least 10kb bytes, and then we cancel that stream.
See src/index.js for more details
## Approach 2: Creating a new stream
This approach also reads the first 10kb bytes using the same BYOB reader method, but it does it off the original stream, not a cloned stream.
Then we create a new response stream, first pushing the 10kb we've already read, and the rest of the original stream.
See src/index.js for more details