Huixxi commented on code in PR #2393:
URL: https://github.com/apache/brpc/pull/2393#discussion_r1337475108
##########
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:
no_content是个bool类型,表示着一些状态码的status(包括no_content状态码和一些信息性状态码),而content则是butil::IOBuf*的指针类型,但两个变量的命名上看起来比较容易混淆,有没有更好的变量名来替换这个no_content
##########
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:
no_content是个bool类型,表示着一些状态码的status(包括no_content状态码和一些信息性状态码),而content则是butil::IOBuf*的指针类型,但两个变量的命名上看起来比较容易混淆,有没有更好的变量名来替换这个no_content
--
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]