You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "chenBright (via GitHub)" <gi...@apache.org> on 2023/09/24 15:45:34 UTC

[PR] Fix HTTP no content of 1xx and 204 (brpc)

chenBright opened a new pull request, #2393:
URL: https://github.com/apache/brpc/pull/2393

   ### What problem does this PR solve?
   
   Issue Number: Fix  #1610
   
   Problem Summary:
   
   ### What is changed and the side effects?
   
   Changed:
   
   Side effects:
   - Performance effects(性能影响):
   
   - Breaking backward compatibility(向后兼容性): 
   
   ---
   ### Check List:
   - Please make sure your changes are compilable(请确保你的更改可以通过编译).
   - When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试).
   - Please follow [Contributor Covenant Code of Conduct](../../master/CODE_OF_CONDUCT.md).(请遵循贡献者准则).
   


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Fix HTTP no content of 1xx and 204 (brpc)

Posted by "Huixxi (via GitHub)" <gi...@apache.org>.
Huixxi merged PR #2393:
URL: https://github.com/apache/brpc/pull/2393


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Fix HTTP no content of 1xx and 204 (brpc)

Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2393:
URL: https://github.com/apache/brpc/pull/2393#discussion_r1339949615


##########
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:
   done



-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Fix HTTP no content of 1xx and 204 (brpc)

Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on PR #2393:
URL: https://github.com/apache/brpc/pull/2393#issuecomment-1734721053

   LGTM


-- 
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Fix HTTP no content of 1xx and 204 (brpc)

Posted by "Huixxi (via GitHub)" <gi...@apache.org>.
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Fix HTTP no content of 1xx and 204 (brpc)

Posted by "Huixxi (via GitHub)" <gi...@apache.org>.
Huixxi commented on code in PR #2393:
URL: https://github.com/apache/brpc/pull/2393#discussion_r1337971546


##########
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:
   is_invalid_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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Fix HTTP no content of 1xx and 204 (brpc)

Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2393:
URL: https://github.com/apache/brpc/pull/2393#discussion_r1337958510


##########
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:
   改成need_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:
   改成need_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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Fix HTTP no content of 1xx and 204 (brpc)

Posted by "chenBright (via GitHub)" <gi...@apache.org>.
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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Fix HTTP no content of 1xx and 204 (brpc)

Posted by "Huixxi (via GitHub)" <gi...@apache.org>.
Huixxi commented on code in PR #2393:
URL: https://github.com/apache/brpc/pull/2393#discussion_r1337971546


##########
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:
   is_invalid_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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org