From b33cabe08c33e29eb8aef65dd46b2c1f3cf2d186 Mon Sep 17 00:00:00 2001 From: David Steele Date: Fri, 25 Feb 2022 10:51:40 -0600 Subject: [PATCH] Allow case-insensitive matching of HTTP connection header values. The specification allows values for the connection header to be case-insensitive. See https://www.rfc-editor.org/rfc/rfc7230#section-6.1. --- doc/xml/release.xml | 18 ++++++++++++++++++ src/common/io/http/response.c | 7 ++++--- test/src/module/common/ioHttpTest.c | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 7462ca7af..d5118fa27 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -33,6 +33,19 @@

Retry errors in S3 batch file delete.

+ + + + + + + + + + + +

Allow case-insensitive matching of HTTP connection header values.

+
@@ -11310,6 +11323,11 @@ Rakshitha-BR + + Rémi Vidier + vidierr + + Rohit Raveendran rohitrav33ndran diff --git a/src/common/io/http/response.c b/src/common/io/http/response.c index 3efdd9d77..df2f28d8c 100644 --- a/src/common/io/http/response.c +++ b/src/common/io/http/response.c @@ -275,8 +275,6 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache) String *headerKey = strLower(strTrim(strSubN(header, 0, (size_t)colonPos))); String *headerValue = strTrim(strSub(header, (size_t)colonPos + 1)); - httpHeaderAdd(this->pub.header, headerKey, headerValue); - // Read transfer encoding (only chunked is supported) if (strEq(headerKey, HTTP_HEADER_TRANSFER_ENCODING_STR)) { @@ -300,8 +298,11 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache) // If the server notified of a closed connection then close the client connection after reading content. This // prevents doing a retry on the next request when using the closed connection. - if (strEq(headerKey, HTTP_HEADER_CONNECTION_STR) && strEq(headerValue, HTTP_VALUE_CONNECTION_CLOSE_STR)) + if (strEq(headerKey, HTTP_HEADER_CONNECTION_STR) && strEq(strLower(headerValue), HTTP_VALUE_CONNECTION_CLOSE_STR)) this->closeOnContentEof = true; + + // Add after header checks in case the value was modified + httpHeaderAdd(this->pub.header, headerKey, headerValue); } while (1); diff --git a/test/src/module/common/ioHttpTest.c b/test/src/module/common/ioHttpTest.c index 360e06a5f..ab2d7b885 100644 --- a/test/src/module/common/ioHttpTest.c +++ b/test/src/module/common/ioHttpTest.c @@ -638,7 +638,7 @@ testRun(void) hrnServerScriptExpectZ( http, "GET /path/file%201.txt HTTP/1.1\r\n" TEST_USER_AGENT "content-length:30\r\n\r\n" "012345678901234567890123456789"); - hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\nConnection:close\r\n\r\n01234567890123456789012345678901"); + hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\nConnection:ClosE\r\n\r\n01234567890123456789012345678901"); hrnServerScriptClose(http);