Skip to content
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

Response Headers Get Unexpectedly Modified #21

Open
FlorianWendelborn opened this issue Apr 18, 2018 · 0 comments
Open

Response Headers Get Unexpectedly Modified #21

FlorianWendelborn opened this issue Apr 18, 2018 · 0 comments

Comments

@FlorianWendelborn
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant