Response Headers Get Unexpectedly Modified
Opened this issue · 0 comments
FlorianWendelborn commented
There's a small bug/unexpected behavior in this function.
Minimal Repro
const headers = { cors: { 'Access-Control-Allow-Origin': '*' } }
require('http').createServer(
require('spirit').node.adapter(r => r.path === '/bug' ? {
status: 200,
headers: headers.cors,
} : {
status: 200,
headers: headers.cors,
body: 'Not Empty',
})
).listen(8080)
Request 1: curl "http://127.0.0.1:8080"
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Length: 9
Date: Wed, 18 Apr 2018 21:06:35 GMT
Connection: close
Not Empty
Request 2: curl "http://127.0.0.1:8080/bug"
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Length: 0
Date: Wed, 18 Apr 2018 21:07:05 GMT
Connection: close
Retry request 1: curl "http://127.0.0.1:8080"
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Length: 0
Date: Wed, 18 Apr 2018 21:07:30 GMT
Connection: close
What exactly happens?
Spirit tries to add Content-Length: 0
to the response headers, but those also get added to headers.cors
, making all bodies that will ever be sent vanish.