Prerequisites
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 with null or undefined, the response header content-length: 4 will be present (hanging Postman and other HTTP clients).
- when I call
reply.send(), with or without promises, the content-length header 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.
Prerequisites
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
204responses.I suspect the problem could be the positively-valued
content-lengthresponse header. I've recreated the case without any trouble with a bare-bone Fastify instance (seeSteps to Reproduce).Having
reply.code(204):async(Promise) handler that resolves withnullorundefined, the response headercontent-length: 4will be present (hanging Postman and other HTTP clients).reply.send(), with or without promises, thecontent-lengthheader is omitted from the response.Steps to Reproduce
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:
Expected Behavior
Response header
content-lengthshould be0or omitted when204status code is set.