Description
Previously, on Love Island
If a web server sends both a Content-Length
header and a Transfer-Encoding: chunked
header, it is a violation of the HTTP spec.
node 10's older HTTP parser didn't error on this (though it should have)
node 12's newer HTTP parser does error on this (which is good)
The issue
As a spicy noderperson, using a REST API client that worked with node 10, I recently moved it to node 12 and did a bunch of research trying to work out what was wrong before finding out the cause of this error.
Important thing since we're communicating of the internet and people tend not to read things before replying:
If it's not clear from the above, I believe node is doing the right thing here, It just needs to be communicated better. Please don't comment saying I support malformed headers, I don't support malformed headers. If you do comment saying I support malformed headers, I'll block you for non-constructive behaviour.
1. Robustness principle / Postel's law
See https://en.wikipedia.org/wiki/Robustness_principle
Be conservative in what you do, be liberal in what you accept from others (often reworded as "Be conservative in what you send, be liberal in what you accept").
ie, node could have:
warning: this response contains both a `Content-Length` header and a `Transfer-Encoding: chunked` header, it is a violation of the HTTP spec. Ignoring (whichever header is being ignored)
2. Lack of a transition period
Think about the good way node (as a community) is handling uncaught promises. There's a warning, everyone knows what's coming.
Ideally, a transition period could have occurred, ie:
warning: this response contains both a `Content-Length` header and a `Transfer-Encoding: chunked` header, it is a violation of the HTTP spec. In a future version of node this response will be rejected.
3. Poor communication around a breaking change
If node was to break existing behaviour, a CHANGELOG entry that calls this out explicitly would help:
https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V12.md#12.0.0 states:
switch default parser to llhttp (Anna Henningsen) #24870
The change should be communicated more explicitly.
Note: the new HTTP parser is stricter in some cases, and malformed HTTP responses that may have worked in the previous HTTP parser are no longer handled. See https://someurl for details.
4. error.message
around the malformed HTTP response is vague
Error: Parse Error at TLSSocket.socketOnData (_http_client.js:452:22)
- The error is vague.
- Apparently there is some other field (
error.reason
) that has an explanation, buterror.message
itself is vague, and I didn't know abouterror.reason
(am I ignorant here? I thoughterror.message
was the reason) - I appreciate that the response isn't being parsed correctly in that it's invalid, but the error makes it sounds like node's parser has an error, rather than the response being parsed
A better error.message
would be:
Error: invalid HTTP response. See https://someUrl
or perhaps:
Error: invalid HTTP response (contains both 'Content-Length' header and a 'Transfer-Encoding: chunked' header
)
Just some suggestions. Thanks for reading.