-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix #68 not working with static plugin #130
base: master
Are you sure you want to change the base?
Fix #68 not working with static plugin #130
Conversation
@@ -138,7 +134,7 @@ export const compression = ( | |||
|
|||
contentType = resContentType ? resContentType : 'text/plain' | |||
|
|||
const buffer = await res.arrayBuffer() | |||
const buffer = await res.clone().arrayBuffer() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual fix. The other changes are tests and minor cleanup of issues found by my IDE.
expect(res.headers.get('Content-Type')).toBe('image/png') | ||
expect(res.headers.get('vary')).toBeNull() | ||
|
||
const actualBody = await res.arrayBuffer() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the fix, the error here is:
132 | const actualBody = await res.arrayBuffer()
^
error: Body already used
code: "ERR_BODY_ALREADY_USED"
As a temporary workaround, here is a branch with this PR, with
|
A proposed fix for #68
After investigation it turned out that in some cases the response body is consumed by the plugin and not replaced with a correct response. Using 'res.clone()' when getting the response buffer prevents breaking the original response if we exit early with
return