Sending wrong Content-Length value returns status code 500
pavelsaman opened this issue · 0 comments
pavelsaman commented
- problem
Sending a custom made Content-Length header value that doesn't correspond to the actual length returns 500 with the following stack trace:
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at parse (/app/node_modules/body-parser/lib/types/json.js:89:19)
at /app/node_modules/body-parser/lib/read.js:121:18
at invokeCallback (/app/node_modules/raw-body/index.js:224:16)
at done (/app/node_modules/raw-body/index.js:213:7)
at IncomingMessage.onEnd (/app/node_modules/raw-body/index.js:273:7)
at IncomingMessage.emit (events.js:333:22)
at endReadableNT (_stream_readable.js:1204:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
- steps to reproduce
send the following req:
POST /posts HTTP/1.1
Content-Length: 2
Content-Type: application/json
User-Agent: PostmanRuntime/7.22.0
Accept: */*
Host: jsonplaceholder.typicode.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
{
"a": 5
}
- desired behaviour
Treat it as error, respond with status code 400 (Bad Request) and close the connection.