Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Data" to "Date" in the HTTP Server API mapping #1219

Merged
merged 1 commit into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 46 additions & 55 deletions Release/src/http/listener/http_server_httpsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,62 +43,53 @@ namespace experimental
namespace details
{
/// <summary>
/// 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.
/// </summary>
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)
{
Expand Down Expand Up @@ -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));
}
}
Expand Down
25 changes: 25 additions & 0 deletions Release/tests/functional/http/listener/header_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<utility::string_t, utility::string_t> 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);
Expand Down
101 changes: 46 additions & 55 deletions Release/tests/functional/http/utilities/test_http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,62 +97,53 @@ static utility::string_t parse_verb(const HTTP_REQUEST* p_http_request)
}

/// <summary>
/// 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.
/// </summary>
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)
{
Expand All @@ -176,7 +167,7 @@ static std::map<utility::string_t, utility::string_t> 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;
Expand Down