chenBright commented on code in PR #2393:
URL: https://github.com/apache/brpc/pull/2393#discussion_r1337978018
##########
src/brpc/details/http_message.cpp:
##########
@@ -630,7 +630,19 @@ void MakeRawHttpResponse(butil::IOBuf* response,
os << "HTTP/" << h->major_version() << '.'
<< h->minor_version() << ' ' << h->status_code()
<< ' ' << h->reason_phrase() << BRPC_CRLF;
- if (content) {
+ bool no_content = h->status_code() < HTTP_STATUS_OK ||
+ h->status_code() == HTTP_STATUS_NO_CONTENT;
+ if (no_content) {
+ // https://www.rfc-editor.org/rfc/rfc7230#section-3.3.1
+ // A server MUST NOT send a Transfer-Encoding header field in any
+ // response with a status code of 1xx (Informational) or 204 (No
+ // Content).
+ h->RemoveHeader("Transfer-Encoding");
+ // https://www.rfc-editor.org/rfc/rfc7230#section-3.3.2
+ // A server MUST NOT send a Content-Length header field in any response
+ // with a status code of 1xx (Informational) or 204 (No Content).
+ h->RemoveHeader("Content-Length");
+ } else if (content) {
h->RemoveHeader("Content-Length");
Review Comment:
可以
##########
src/brpc/details/http_message.cpp:
##########
@@ -630,7 +630,19 @@ void MakeRawHttpResponse(butil::IOBuf* response,
os << "HTTP/" << h->major_version() << '.'
<< h->minor_version() << ' ' << h->status_code()
<< ' ' << h->reason_phrase() << BRPC_CRLF;
- if (content) {
+ bool no_content = h->status_code() < HTTP_STATUS_OK ||
+ h->status_code() == HTTP_STATUS_NO_CONTENT;
+ if (no_content) {
+ // https://www.rfc-editor.org/rfc/rfc7230#section-3.3.1
+ // A server MUST NOT send a Transfer-Encoding header field in any
+ // response with a status code of 1xx (Informational) or 204 (No
+ // Content).
+ h->RemoveHeader("Transfer-Encoding");
+ // https://www.rfc-editor.org/rfc/rfc7230#section-3.3.2
+ // A server MUST NOT send a Content-Length header field in any response
+ // with a status code of 1xx (Informational) or 204 (No Content).
+ h->RemoveHeader("Content-Length");
+ } else if (content) {
h->RemoveHeader("Content-Length");
Review Comment:
可以
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]