-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
test: refactor test-httpparser.response.js #14290
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if Ci is green
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution and welcome to the project :)
CRLF + | ||
'pong' | ||
`HTTP/1.1 200 OK${CRLF}Content-types: text/plain${CRLF}` + | ||
`Content-Length: 4${CRLF}${CRLF}pong` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this does not represent the HTTP header structure as well as the old code did, where one code line was equivalent to one line of the request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree - I'd rather see the CRLF on a new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the thing to do is to go back to the old code layout, but replace lines 22, 23, and 24 with template literals:
const request = Buffer.from(
`HTTP/1.1 200 OK${CRLF}` +
`Content-types: text/plain${CRLF}` +
`Content-Length: 4${CRLF}` +
CRLF +
'pong'
);
@erdun Does that seem good to you? Can you make that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another possibility might be to use Array.prototype.join()
but I'm not sure it's more readable:
const request = Buffer.from(
['HTTP 1.1 200 OK',
'Content-types: text/plain',
'Content-Length: 4',
'',
'pong'
].join(CRLF)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet another possibility for readable-and-an-improvement-over-what's-there-now is to leave it as strings but remove the inline concatenation by removing the CRLF
variable:
'HTTP/1.1 200 OK\r\n' +
'Content-types: text/plain\r\n' +
'Content-Length: 4\r\n' +
'\r\n' +
'pong'
Aside: Is Content-types
is a typographical error and it is supposed to be Content-type
? If so, maybe that should be fixed too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay, I assumed the capitalization was as much by design as the typo in the header name.
cc @thlorenz @nodejs/async_hooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the capitalization was by design since this is a test file.
IDK, looks like the test just checks that you get a response. You think it's checking that a different capitalisation is still valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gibfahn I thought it was checking the misnamed header (It's Content-types
here and not Content-Type
) I assumed it was checking compatibility with nonconforming clients.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any reason why Content-types
vs Content-type
would affect the test. I think it is just a meaningless error. The test just checks that creating an HTTPParser
object correctly invokes async_hooks
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW That header is not mandatory. IMHO it should be removed.
Actually the only header that "MUST" be included is the Status-Line
and two CRLF
s
Ref: https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The code is less readable than before. (Why do we even use
CRLF
instead of\r\n
?) - The HTTP protocol is strictly line-oriented and the old code depicted that nicely by using one line of code per HTTP request line. These changes shadow the structure of the request (see test: refactor test-httpparser.response.js #14290 (comment)).
'Content-Length: 4' + CRLF + | ||
CRLF + | ||
'pong' | ||
`HTTP/1.1 200 OK${CRLF}Content-types: text/plain${CRLF}` + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps just replace the ${CRLF}
with a literal \r\n
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 (see #14290 (review))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message should be minimized (optional headers removed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git commit title is too long. please limit to 50 characters.
* replace CRLF constant with '\r\n' literal * fix typo in HTTP header name
Fixed up commit message and nits. PTAL @trevnorris @refack @tniessen |
* replace CRLF constant with '\r\n' literal * fix typo in HTTP header name PR-URL: nodejs#14290 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
Landed in 672e020. Thanks for the contribution! 🎉 |
* replace CRLF constant with '\r\n' literal * fix typo in HTTP header name PR-URL: #14290 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
Replace string concatenation in
test/async-hooks/test-httpparser.response.js
with template literalsChecklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)