From ca6b491fd3832111d4cd0b910d43b90ece7044e1 Mon Sep 17 00:00:00 2001 From: Arne H Juul Date: Tue, 9 May 2017 14:04:18 +0200 Subject: only send Content-Length for POST --- fbench/src/httpclient/httpclient.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/fbench/src/httpclient/httpclient.cpp b/fbench/src/httpclient/httpclient.cpp index ba2f593a76c..3a4cb68aa19 100644 --- a/fbench/src/httpclient/httpclient.cpp +++ b/fbench/src/httpclient/httpclient.cpp @@ -121,28 +121,27 @@ HTTPClient::Connect(const char *url, bool usePost, const char *content, int cLen assert(req != NULL); } + if (!_keepAlive) { + headers += "Connection: close\r\n"; + } + headers += "User-Agent: fbench/4.2.10\r\n"; + // create request - if(_keepAlive) { + if (usePost) { snprintf(req, req_max, - "%s %s HTTP/1.1\r\n" + "POST %s HTTP/1.1\r\n" "Host: %s\r\n" "Content-Length: %d\r\n" - "User-Agent: fbench/4.2.10\r\n" "%s" "\r\n", - usePost ? "POST" : "GET", url, _authority.c_str(), cLen, headers.c_str()); } else { snprintf(req, req_max, - "%s %s HTTP/1.1\r\n" + "GET %s HTTP/1.1\r\n" "Host: %s\r\n" - "Connection: close\r\n" - "Content-Length: %d\r\n" - "User-Agent: fbench/4.2.10\r\n" "%s" "\r\n", - usePost ? "POST" : "GET", - url, _authority.c_str(), cLen, headers.c_str()); + url, _authority.c_str(), headers.c_str()); } // try to reuse connection if keep-alive is enabled -- cgit v1.2.3