-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
http: throw error when attempting to write to response with no body #47656
Conversation
Review requested:
|
This needs a test. After which, I think you will notice that this does not work since all implementations override this method. |
Do I need to create a new test, I would appreciate it if you could inform me about it. |
Yes, please create a new test. |
I added a test |
The test is failing. |
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.
You should test the public api not the internal one.
I think you can try looking into how the response body is sent, the API that devs use to write to the response body. It should be this API. From there, you can try to trace the code and understand how it works. |
Ah, actually I meant about where to start to understand about the necessary changes. What I suggested is: because we want to prevent writing to the response body when the request method is HEAD, we can start by looking at the You can search for About writing test, I think you can refer to existing tests, you can search in the codebase with the keyword "test-http" and there are plenty of them. And you can try running the tests in local first, see this. I hope that helps 😄 |
server.listen(0, () => { | ||
const port = server.address().port; | ||
const options = { | ||
method: 'GET', |
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 we want to verify that HEAD
can't write. So I am not sure why we are only testing GET
here.
46165c5
to
2d212f0
Compare
@ronag class HttpBodyNotAllowedError extends Error {
constructor(message) {
super(message);
this.name = 'HttpBodyNotAllowedError';
this.code = 'ERR_HTTP_BODY_NOT_ALLOWED';
}
} |
Previously, when the _hasBody property of the response object was false, the code simply ignored any data being written to the response. This behavior was changed to throw an error instead, which is more appropriate for responses that are not allowed to have a body