diff --git a/Release/src/http/listener/http_server_httpsys.cpp b/Release/src/http/listener/http_server_httpsys.cpp index d4c080a76b..318d1404c0 100644 --- a/Release/src/http/listener/http_server_httpsys.cpp +++ b/Release/src/http/listener/http_server_httpsys.cpp @@ -43,62 +43,53 @@ namespace experimental namespace details { /// -/// String values for all HTTP Server API known headers. +/// String values for all HTTP Server API HTTP_REQUEST_HEADERS known headers. /// NOTE: the order here is important it is from the _HTTP_HEADER_ID enum. /// -static utility::string_t HttpServerAPIKnownHeaders[] = {U("Cache-Control"), - U("Connection"), - U("Data"), - U("Keep-Alive"), - U("Pragma"), - U("Trailer"), - U("Transfer-Encoding"), - U("Upgrade"), - U("Via"), - U("Warning"), - U("Allow"), - U("Content-Length"), - U("Content-Type"), - U("Content-Encoding"), - U("Content-Language"), - U("Content-Location"), - U("Content-Md5"), - U("Content-Range"), - U("Expires"), - U("Last-Modified"), - U("Accept"), - U("Accept-Charset"), - U("Accept-Encoding"), - U("Accept-Language"), - U("Authorization"), - U("Cookie"), - U("Expect"), - U("From"), - U("Host"), - U("If-Match"), - U("If-Modified-Since"), - U("If-None-Match"), - U("If-Range"), - U("If-Unmodified-Since"), - U("Max-Forwards"), - U("Proxy-Authorization"), - U("Referer"), - U("Range"), - U("TE"), - U("Translate"), - U("User-Agent"), - U("Request-Maximum"), - U("Accept-Ranges"), - U("Age"), - U("Etag"), - U("Location"), - U("Proxy-Authenticate"), - U("Retry-After"), - U("Server"), - U("Set-Cookie"), - U("Vary"), - U("Www-Authenticate"), - U("Response-Maximum")}; +static utility::string_t HttpServerAPIRequestKnownHeaders[] = +{ + U("Cache-Control"), + U("Connection"), + U("Date"), + U("Keep-Alive"), + U("Pragma"), + U("Trailer"), + U("Transfer-Encoding"), + U("Upgrade"), + U("Via"), + U("Warning"), + U("Allow"), + U("Content-Length"), + U("Content-Type"), + U("Content-Encoding"), + U("Content-Language"), + U("Content-Location"), + U("Content-MD5"), + U("Content-Range"), + U("Expires"), + U("Last-Modified"), + U("Accept"), + U("Accept-Charset"), + U("Accept-Encoding"), + U("Accept-Language"), + U("Authorization"), + U("Cookie"), + U("Expect"), + U("From"), + U("Host"), + U("If-Match"), + U("If-Modified-Since"), + U("If-None-Match"), + U("If-Range"), + U("If-Unmodified-Since"), + U("Max-Forwards"), + U("Proxy-Authorization"), + U("Referer"), + U("Range"), + U("TE"), + U("Translate"), + U("User-Agent") +}; static void char_to_wstring(utf16string& dest, const char* src) { @@ -162,7 +153,7 @@ void parse_http_headers(const HTTP_REQUEST_HEADERS& headers, http::http_headers& { if (headers.KnownHeaders[i].RawValueLength > 0) { - msgHeaders.add(HttpServerAPIKnownHeaders[i], + msgHeaders.add(HttpServerAPIRequestKnownHeaders[i], utility::conversions::to_utf16string(headers.KnownHeaders[i].pRawValue)); } } diff --git a/Release/tests/functional/http/listener/header_tests.cpp b/Release/tests/functional/http/listener/header_tests.cpp index a3cff2e2e1..87cf6783fb 100644 --- a/Release/tests/functional/http/listener/header_tests.cpp +++ b/Release/tests/functional/http/listener/header_tests.cpp @@ -112,6 +112,31 @@ SUITE(header_tests) listener.close().wait(); } + TEST_FIXTURE(uri_address, request_known_headers) + { + http_listener listener(m_uri); + listener.open().wait(); + test_http_client::scoped_client client(m_uri); + test_http_client* p_client = client.client(); + const utility::string_t mtd = methods::GET; + std::map headers; + + // "Date" was being incorrectly mapped to "Data" + // see https://github.com/microsoft/cpprestsdk/issues/1208 + headers[U("Date")] = U("Mon, 29 Jul 2019 12:32:57 GMT"); + listener.support([&](http_request request) { + http_asserts::assert_request_equals(request, mtd, U("/"), headers); + request.reply(status_codes::OK).wait(); + }); + VERIFY_ARE_EQUAL(0, p_client->request(mtd, U(""), headers)); + p_client->next_response() + .then([](test_response* p_response) { + http_asserts::assert_test_response_equals(p_response, status_codes::OK); + }) + .wait(); + listener.close().wait(); + } + TEST_FIXTURE(uri_address, response_headers) { http_listener listener(m_uri); diff --git a/Release/tests/functional/http/utilities/test_http_server.cpp b/Release/tests/functional/http/utilities/test_http_server.cpp index e3a96570ab..3abb6915b6 100644 --- a/Release/tests/functional/http/utilities/test_http_server.cpp +++ b/Release/tests/functional/http/utilities/test_http_server.cpp @@ -97,62 +97,53 @@ static utility::string_t parse_verb(const HTTP_REQUEST* p_http_request) } /// -/// String values for all HTTP Server API known headers. +/// String values for all HTTP Server API HTTP_REQUEST_HEADERS known headers. /// NOTE: the order here is important it is from the _HTTP_HEADER_ID enum. /// -static utility::string_t HttpServerAPIKnownHeaders[] = {U("Cache-Control"), - U("Connection"), - U("Data"), - U("Keep-Alive"), - U("Pragma"), - U("Trailer"), - U("Transfer-Encoding"), - U("Upgrade"), - U("Via"), - U("Warning"), - U("Allow"), - U("Content-Length"), - U("Content-Type"), - U("Content-Encoding"), - U("Content-Language"), - U("Content-Location"), - U("Content-Md5"), - U("Content-Range"), - U("Expires"), - U("Last-Modified"), - U("Accept"), - U("Accept-Charset"), - U("Accept-Encoding"), - U("Accept-Language"), - U("Authorization"), - U("Cookie"), - U("Expect"), - U("From"), - U("Host"), - U("If-Match"), - U("If-Modified-Since"), - U("If-None-Match"), - U("If-Range"), - U("If-Unmodified-Since"), - U("Max-Forwards"), - U("Proxy-Authorization"), - U("Referer"), - U("Range"), - U("TE"), - U("Translate"), - U("User-Agent"), - U("Request-Maximum"), - U("Accept-Ranges"), - U("Age"), - U("Etag"), - U("Location"), - U("Proxy-Authenticate"), - U("Retry-After"), - U("Server"), - U("Set-Cookie"), - U("Vary"), - U("Www-Authenticate"), - U("Response-Maximum")}; +static utility::string_t HttpServerAPIRequestKnownHeaders[] = +{ + U("Cache-Control"), + U("Connection"), + U("Date"), + U("Keep-Alive"), + U("Pragma"), + U("Trailer"), + U("Transfer-Encoding"), + U("Upgrade"), + U("Via"), + U("Warning"), + U("Allow"), + U("Content-Length"), + U("Content-Type"), + U("Content-Encoding"), + U("Content-Language"), + U("Content-Location"), + U("Content-MD5"), + U("Content-Range"), + U("Expires"), + U("Last-Modified"), + U("Accept"), + U("Accept-Charset"), + U("Accept-Encoding"), + U("Accept-Language"), + U("Authorization"), + U("Cookie"), + U("Expect"), + U("From"), + U("Host"), + U("If-Match"), + U("If-Modified-Since"), + U("If-None-Match"), + U("If-Range"), + U("If-Unmodified-Since"), + U("Max-Forwards"), + U("Proxy-Authorization"), + U("Referer"), + U("Range"), + U("TE"), + U("Translate"), + U("User-Agent") +}; static utility::string_t char_to_wstring(const char* src) { @@ -176,7 +167,7 @@ static std::map parse_http_headers(const H { if (headers.KnownHeaders[i].RawValueLength != 0) { - headers_map[HttpServerAPIKnownHeaders[i]] = char_to_wstring(headers.KnownHeaders[i].pRawValue); + headers_map[HttpServerAPIRequestKnownHeaders[i]] = char_to_wstring(headers.KnownHeaders[i].pRawValue); } } return headers_map;