Skip to content

Commit f7065f4

Browse files
garethsbBillyONeal
authored andcommitted
Fix "Data" to "Date" in the HTTP Server API mapping, and clarify that the indices of these values match the HTTP_HEADER_ID values for HTTP_REQUEST_HEADERS but *not* HTTP_RESPONSE_HEADERS (#1219)
1 parent 265d681 commit f7065f4

File tree

3 files changed

+117
-110
lines changed

3 files changed

+117
-110
lines changed

Release/src/http/listener/http_server_httpsys.cpp

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -43,62 +43,53 @@ namespace experimental
4343
namespace details
4444
{
4545
/// <summary>
46-
/// String values for all HTTP Server API known headers.
46+
/// String values for all HTTP Server API HTTP_REQUEST_HEADERS known headers.
4747
/// NOTE: the order here is important it is from the _HTTP_HEADER_ID enum.
4848
/// </summary>
49-
static utility::string_t HttpServerAPIKnownHeaders[] = {U("Cache-Control"),
50-
U("Connection"),
51-
U("Data"),
52-
U("Keep-Alive"),
53-
U("Pragma"),
54-
U("Trailer"),
55-
U("Transfer-Encoding"),
56-
U("Upgrade"),
57-
U("Via"),
58-
U("Warning"),
59-
U("Allow"),
60-
U("Content-Length"),
61-
U("Content-Type"),
62-
U("Content-Encoding"),
63-
U("Content-Language"),
64-
U("Content-Location"),
65-
U("Content-Md5"),
66-
U("Content-Range"),
67-
U("Expires"),
68-
U("Last-Modified"),
69-
U("Accept"),
70-
U("Accept-Charset"),
71-
U("Accept-Encoding"),
72-
U("Accept-Language"),
73-
U("Authorization"),
74-
U("Cookie"),
75-
U("Expect"),
76-
U("From"),
77-
U("Host"),
78-
U("If-Match"),
79-
U("If-Modified-Since"),
80-
U("If-None-Match"),
81-
U("If-Range"),
82-
U("If-Unmodified-Since"),
83-
U("Max-Forwards"),
84-
U("Proxy-Authorization"),
85-
U("Referer"),
86-
U("Range"),
87-
U("TE"),
88-
U("Translate"),
89-
U("User-Agent"),
90-
U("Request-Maximum"),
91-
U("Accept-Ranges"),
92-
U("Age"),
93-
U("Etag"),
94-
U("Location"),
95-
U("Proxy-Authenticate"),
96-
U("Retry-After"),
97-
U("Server"),
98-
U("Set-Cookie"),
99-
U("Vary"),
100-
U("Www-Authenticate"),
101-
U("Response-Maximum")};
49+
static utility::string_t HttpServerAPIRequestKnownHeaders[] =
50+
{
51+
U("Cache-Control"),
52+
U("Connection"),
53+
U("Date"),
54+
U("Keep-Alive"),
55+
U("Pragma"),
56+
U("Trailer"),
57+
U("Transfer-Encoding"),
58+
U("Upgrade"),
59+
U("Via"),
60+
U("Warning"),
61+
U("Allow"),
62+
U("Content-Length"),
63+
U("Content-Type"),
64+
U("Content-Encoding"),
65+
U("Content-Language"),
66+
U("Content-Location"),
67+
U("Content-MD5"),
68+
U("Content-Range"),
69+
U("Expires"),
70+
U("Last-Modified"),
71+
U("Accept"),
72+
U("Accept-Charset"),
73+
U("Accept-Encoding"),
74+
U("Accept-Language"),
75+
U("Authorization"),
76+
U("Cookie"),
77+
U("Expect"),
78+
U("From"),
79+
U("Host"),
80+
U("If-Match"),
81+
U("If-Modified-Since"),
82+
U("If-None-Match"),
83+
U("If-Range"),
84+
U("If-Unmodified-Since"),
85+
U("Max-Forwards"),
86+
U("Proxy-Authorization"),
87+
U("Referer"),
88+
U("Range"),
89+
U("TE"),
90+
U("Translate"),
91+
U("User-Agent")
92+
};
10293

10394
static void char_to_wstring(utf16string& dest, const char* src)
10495
{
@@ -162,7 +153,7 @@ void parse_http_headers(const HTTP_REQUEST_HEADERS& headers, http::http_headers&
162153
{
163154
if (headers.KnownHeaders[i].RawValueLength > 0)
164155
{
165-
msgHeaders.add(HttpServerAPIKnownHeaders[i],
156+
msgHeaders.add(HttpServerAPIRequestKnownHeaders[i],
166157
utility::conversions::to_utf16string(headers.KnownHeaders[i].pRawValue));
167158
}
168159
}

Release/tests/functional/http/listener/header_tests.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@ SUITE(header_tests)
112112
listener.close().wait();
113113
}
114114

115+
TEST_FIXTURE(uri_address, request_known_headers)
116+
{
117+
http_listener listener(m_uri);
118+
listener.open().wait();
119+
test_http_client::scoped_client client(m_uri);
120+
test_http_client* p_client = client.client();
121+
const utility::string_t mtd = methods::GET;
122+
std::map<utility::string_t, utility::string_t> headers;
123+
124+
// "Date" was being incorrectly mapped to "Data"
125+
// see https://github.com/microsoft/cpprestsdk/issues/1208
126+
headers[U("Date")] = U("Mon, 29 Jul 2019 12:32:57 GMT");
127+
listener.support([&](http_request request) {
128+
http_asserts::assert_request_equals(request, mtd, U("/"), headers);
129+
request.reply(status_codes::OK).wait();
130+
});
131+
VERIFY_ARE_EQUAL(0, p_client->request(mtd, U(""), headers));
132+
p_client->next_response()
133+
.then([](test_response* p_response) {
134+
http_asserts::assert_test_response_equals(p_response, status_codes::OK);
135+
})
136+
.wait();
137+
listener.close().wait();
138+
}
139+
115140
TEST_FIXTURE(uri_address, response_headers)
116141
{
117142
http_listener listener(m_uri);

Release/tests/functional/http/utilities/test_http_server.cpp

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -97,62 +97,53 @@ static utility::string_t parse_verb(const HTTP_REQUEST* p_http_request)
9797
}
9898

9999
/// <summary>
100-
/// String values for all HTTP Server API known headers.
100+
/// String values for all HTTP Server API HTTP_REQUEST_HEADERS known headers.
101101
/// NOTE: the order here is important it is from the _HTTP_HEADER_ID enum.
102102
/// </summary>
103-
static utility::string_t HttpServerAPIKnownHeaders[] = {U("Cache-Control"),
104-
U("Connection"),
105-
U("Data"),
106-
U("Keep-Alive"),
107-
U("Pragma"),
108-
U("Trailer"),
109-
U("Transfer-Encoding"),
110-
U("Upgrade"),
111-
U("Via"),
112-
U("Warning"),
113-
U("Allow"),
114-
U("Content-Length"),
115-
U("Content-Type"),
116-
U("Content-Encoding"),
117-
U("Content-Language"),
118-
U("Content-Location"),
119-
U("Content-Md5"),
120-
U("Content-Range"),
121-
U("Expires"),
122-
U("Last-Modified"),
123-
U("Accept"),
124-
U("Accept-Charset"),
125-
U("Accept-Encoding"),
126-
U("Accept-Language"),
127-
U("Authorization"),
128-
U("Cookie"),
129-
U("Expect"),
130-
U("From"),
131-
U("Host"),
132-
U("If-Match"),
133-
U("If-Modified-Since"),
134-
U("If-None-Match"),
135-
U("If-Range"),
136-
U("If-Unmodified-Since"),
137-
U("Max-Forwards"),
138-
U("Proxy-Authorization"),
139-
U("Referer"),
140-
U("Range"),
141-
U("TE"),
142-
U("Translate"),
143-
U("User-Agent"),
144-
U("Request-Maximum"),
145-
U("Accept-Ranges"),
146-
U("Age"),
147-
U("Etag"),
148-
U("Location"),
149-
U("Proxy-Authenticate"),
150-
U("Retry-After"),
151-
U("Server"),
152-
U("Set-Cookie"),
153-
U("Vary"),
154-
U("Www-Authenticate"),
155-
U("Response-Maximum")};
103+
static utility::string_t HttpServerAPIRequestKnownHeaders[] =
104+
{
105+
U("Cache-Control"),
106+
U("Connection"),
107+
U("Date"),
108+
U("Keep-Alive"),
109+
U("Pragma"),
110+
U("Trailer"),
111+
U("Transfer-Encoding"),
112+
U("Upgrade"),
113+
U("Via"),
114+
U("Warning"),
115+
U("Allow"),
116+
U("Content-Length"),
117+
U("Content-Type"),
118+
U("Content-Encoding"),
119+
U("Content-Language"),
120+
U("Content-Location"),
121+
U("Content-MD5"),
122+
U("Content-Range"),
123+
U("Expires"),
124+
U("Last-Modified"),
125+
U("Accept"),
126+
U("Accept-Charset"),
127+
U("Accept-Encoding"),
128+
U("Accept-Language"),
129+
U("Authorization"),
130+
U("Cookie"),
131+
U("Expect"),
132+
U("From"),
133+
U("Host"),
134+
U("If-Match"),
135+
U("If-Modified-Since"),
136+
U("If-None-Match"),
137+
U("If-Range"),
138+
U("If-Unmodified-Since"),
139+
U("Max-Forwards"),
140+
U("Proxy-Authorization"),
141+
U("Referer"),
142+
U("Range"),
143+
U("TE"),
144+
U("Translate"),
145+
U("User-Agent")
146+
};
156147

157148
static utility::string_t char_to_wstring(const char* src)
158149
{
@@ -176,7 +167,7 @@ static std::map<utility::string_t, utility::string_t> parse_http_headers(const H
176167
{
177168
if (headers.KnownHeaders[i].RawValueLength != 0)
178169
{
179-
headers_map[HttpServerAPIKnownHeaders[i]] = char_to_wstring(headers.KnownHeaders[i].pRawValue);
170+
headers_map[HttpServerAPIRequestKnownHeaders[i]] = char_to_wstring(headers.KnownHeaders[i].pRawValue);
180171
}
181172
}
182173
return headers_map;

0 commit comments

Comments
 (0)