-
Notifications
You must be signed in to change notification settings - Fork 77
feat: Clean up the incoming object if the request is not completely finished. #252
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
Merged
+778
−39
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
77eda50
feat: Clean up the incoming object if the request is not completely f…
usualoma 548ab07
feat: add autoCleanupIncoming option to disable auto cleanup of incom…
usualoma 46cfddb
test: add test cases for partially consumed and cancelled request body
usualoma 55c2bb1
test: added test for incomplete requests with low-level sockets, a pa…
usualoma f4b64f3
test: ignore test/app.ts in jest.config.js
usualoma d1889ab
test: skip test for partially consumed pattern in v18
usualoma 1cfcb19
fix: typo
usualoma 37f999c
docs: fix typo
usualoma 538fe24
fix: eliminate environment dependence of type loading
usualoma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { Response as PonyfillResponse } from '@whatwg-node/fetch' | ||
| import { Hono } from 'hono' | ||
|
|
||
| export const app = new Hono() | ||
|
|
||
| app.get('/', (c) => c.text('Hello! Node!')) | ||
| app.get('/url', (c) => c.text(c.req.url)) | ||
|
|
||
| app.get('/posts', (c) => { | ||
| return c.text(`Page ${c.req.query('page')}`) | ||
| }) | ||
| app.get('/user-agent', (c) => { | ||
| return c.text(c.req.header('user-agent') as string) | ||
| }) | ||
| app.post('/posts', (c) => { | ||
| return c.redirect('/posts') | ||
| }) | ||
| app.post('/body-consumed', async (c) => { | ||
| return c.text(`Body length: ${(await c.req.text()).length}`) | ||
| }) | ||
| app.post('/no-body-consumed', (c) => { | ||
| if (!c.req.raw.body) { | ||
| // force create new request object | ||
| throw new Error('No body consumed') | ||
| } | ||
| return c.text('No body consumed') | ||
| }) | ||
| app.post('/body-cancelled', (c) => { | ||
| if (!c.req.raw.body) { | ||
| // force create new request object | ||
| throw new Error('No body consumed') | ||
| } | ||
| c.req.raw.body.cancel() | ||
| return c.text('Body cancelled') | ||
| }) | ||
| app.post('/partially-consumed', async (c) => { | ||
| if (!c.req.raw.body) { | ||
| // force create new request object | ||
| throw new Error('No body consumed') | ||
| } | ||
| const reader = c.req.raw.body.getReader() | ||
| await reader.read() // read only one chunk | ||
| return c.text('Partially consumed') | ||
| }) | ||
| app.post('/partially-consumed-and-cancelled', async (c) => { | ||
| if (!c.req.raw.body) { | ||
| // force create new request object | ||
| throw new Error('No body consumed') | ||
| } | ||
| const reader = c.req.raw.body.getReader() | ||
| await reader.read() // read only one chunk | ||
| reader.cancel() | ||
| return c.text('Partially consumed and cancelled') | ||
| }) | ||
| app.delete('/posts/:id', (c) => { | ||
| return c.text(`DELETE ${c.req.param('id')}`) | ||
| }) | ||
| // @ts-expect-error the response is string | ||
| app.get('/invalid', () => { | ||
| return '<h1>HTML</h1>' | ||
| }) | ||
| app.get('/ponyfill', () => { | ||
| return new PonyfillResponse('Pony') | ||
| }) | ||
|
|
||
| app.on('trace', '/', (c) => { | ||
| const headers = c.req.raw.headers // build new request object | ||
| return c.text(`headers: ${JSON.stringify(headers)}`) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.