-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Reply with a long string will encounter "Premature close #215" #286
Comments
If you have an async handler, you should always return the body instead of using const fastify = new Fastify({})
fastify.register(fastifyCompress) // #1 disable this line will work
fastify.get('/subscription', async (req, reply) => {
const longString = new Array(1024).fill('a').join('') // <--- build a string, whose length is >= 1024 (compress.threshold)
return longString
}) Or: const fastify = new Fastify({})
fastify.register(fastifyCompress) // #1 disable this line will work
fastify.get('/subscription', (req, reply) => {
const longString = new Array(1024).fill('a').join('') // <--- build a string, whose length is >= 1024 (compress.threshold)
reply.send(longString)
}) You can find more information here: https://fastify.dev/docs/latest/Reference/Routes/#promise-resolution |
@gurgunday Thanks for sharing info. It's a bit tricky for a new user. I'd now strictly call I was not aware this when migrating from Koa of promise based routes. // in koa
async someGetRoute(ctx) {
ctx.body = await getMyDataAsync()
}
// in fastify
async someGetRoute(request, reply) {
return reply.send(await getMyDataAsync())
} |
Prerequisites
Fastify version
4.26.2
Plugin version
7.0.1
Node.js version
18.17.1
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
Windows 11
Description
Similar issue to #215
I'm sending a long string as response, with
fastify-compress
enabled, it will fail with errorPremature close
.Steps to Reproduce
Expected Behavior
Regardless
return
is added or not, it should always respond with expected content.Question
Do you think, there is something can be improved in @fastify/compress
The text was updated successfully, but these errors were encountered: