This is an automated email from the ASF dual-hosted git repository.
jiashunzhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 308b3c81 Remove Content-Length header of GET request (#2458)
308b3c81 is described below
commit 308b3c81e12d2068b540488044d4a862cf256da8
Author: Bright Chen <[email protected]>
AuthorDate: Mon Dec 4 00:20:02 2023 +0800
Remove Content-Length header of GET request (#2458)
---
src/brpc/details/http_message.cpp | 4 ++--
test/brpc_http_message_unittest.cpp | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/brpc/details/http_message.cpp
b/src/brpc/details/http_message.cpp
index 45a7bf07..ab8bb4f2 100644
--- a/src/brpc/details/http_message.cpp
+++ b/src/brpc/details/http_message.cpp
@@ -556,9 +556,9 @@ void MakeRawHttpRequest(butil::IOBuf* request,
uri.PrintWithoutHost(os); // host is sent by "Host" header.
os << " HTTP/" << h->major_version() << '.'
<< h->minor_version() << BRPC_CRLF;
+ // Never use "Content-Length" set by user.
+ h->RemoveHeader("Content-Length");
if (h->method() != HTTP_METHOD_GET) {
- h->RemoveHeader("Content-Length");
- // Never use "Content-Length" set by user.
os << "Content-Length: " << (content ? content->length() : 0)
<< BRPC_CRLF;
}
diff --git a/test/brpc_http_message_unittest.cpp
b/test/brpc_http_message_unittest.cpp
index 1b13e2b7..ff51657e 100644
--- a/test/brpc_http_message_unittest.cpp
+++ b/test/brpc_http_message_unittest.cpp
@@ -408,8 +408,9 @@ TEST(HttpMessageTest, serialize_http_request) {
MakeRawHttpRequest(&request, &header, ep, &content);
ASSERT_EQ("POST / HTTP/1.1\r\nContent-Length: 4\r\naccePT:
blahblah\r\nuser-AGENT: myUA\r\nauthorization: myAuthString\r\nFoo:
Bar\r\nHost: MyHost: 4321\r\n\r\ndata", request);
- // GET does not serialize content
+ // GET does not serialize content and user-set content-length is ignored.
header.set_method(brpc::HTTP_METHOD_GET);
+ header.SetHeader("Content-Length", "100");
MakeRawHttpRequest(&request, &header, ep, &content);
ASSERT_EQ("GET / HTTP/1.1\r\naccePT: blahblah\r\nuser-AGENT:
myUA\r\nauthorization: myAuthString\r\nFoo: Bar\r\nHost: MyHost: 4321\r\n\r\n",
request);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]