Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

RafalGoslawski
Copy link

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

@@ -138,7 +134,7 @@ export const compression = (

contentType = resContentType ? resContentType : 'text/plain'

const buffer = await res.arrayBuffer()
const buffer = await res.clone().arrayBuffer()
Copy link
Author

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()
Copy link
Author

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"

@canadaduane
Copy link

As a temporary workaround, here is a branch with this PR, with dist/ folder included so that it can be used as a package.json reference:

    "elysia-compress": "github:canadaduane/elysia-compress#fixes",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants