uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
8.08k stars 574 forks source link

Content-Length is invalid when method is head #739

Closed zdm closed 2 years ago

zdm commented 2 years ago

Head method should return headers only without body.

So I write headers, including body Content-Length, then finish request with res.end();

res.ens() adds Content-Length: 0 automatically, if body is not provided. This leads to the error, because response will contain two Content-Length headers with different values.

Correct behavior: if res.end() called without body - do not add Content-Length header.

ghost commented 2 years ago

https://github.com/uNetworking/uWebSockets/blob/b498b61532d7d37834323bace243e6f115312d24/src/HttpResponse.h#L386

zdm commented 2 years ago

Should I use endWithoutBody()?

zdm commented 2 years ago

endWithoutBody is not a function, not exposed to the nodejs level.

ghost commented 2 years ago

It needs to be wrapped then

zdm commented 2 years ago

will you add this?

ghost commented 2 years ago

endWithoutBody is in binaries branch (no release yet)

zdm commented 2 years ago

thank you, could you release it pls?

ghost commented 2 years ago

20.10.0

zdm commented 2 years ago

endWithoutBody( reportedContentLength, closeConnection )

It works only when called without arguments. If I call it like: `endWithoutBody( 0, true ) - it does not finish response headers with "\r\n\r\n" so all communication become frozen. It works only when called without arguments.

ghost commented 2 years ago

only endWithoutBody() is implemented. It's an issue in C++ repo