-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.22.0
Plugin version
No response
Node.js version
18.16.1
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
6.4.11-arch2-1 (64-bit)
Description
Hi everyone.
I'm having Postman hanging with some 204 responses.
I suspect the problem could be the positively-valued content-length response header. I've recreated the case without any trouble with a bare-bone Fastify instance (see Steps to Reproduce).
Having reply.code(204):
- when I'm using an
async(Promise) handler that resolves withnullorundefined, the response headercontent-length: 4will be present (hanging Postman and other HTTP clients). - when I call
reply.send(), with or without promises, thecontent-lengthheader is omitted from the response.
Steps to Reproduce
// Node.js v18.16.1
import Fastify from 'fastify' // v4.22.0
const app = Fastify({
logger: true,
})
app.route({
method: 'POST',
url: '*',
async handler(request, reply) {
reply.code(204)
// Replace with `reply.send()`, and everything works.
return null
},
})
await app.listen({
port: 3000,
})Run code above.
Run wget -q -S -O- --post-data='{}' --header='Content-Type:application/json' 'http://127.0.0.1:3000/json'
My output is:
HTTP/1.1 204 No Content
content-type: application/json; charset=utf-8
content-length: 4
Date: Tue, 29 Aug 2023 12:58:12 GMT
Connection: keep-alive
Keep-Alive: timeout=72
Expected Behavior
Response header content-length should be 0 or omitted when 204 status code is set.
Reactions are currently unavailable