src: Sort header fields so that pseudo headers come first

This commit is contained in:
Tatsuhiro Tsujikawa 2014-08-07 23:27:13 +09:00
parent cc24b9aaf0
commit 05f982dcfb
2 changed files with 24 additions and 8 deletions

View File

@ -227,6 +227,14 @@ size_t HTTP1_IGN_HDLEN = sizeof(HTTP1_IGN_HD)/sizeof(HTTP1_IGN_HD[0]);
bool name_less(const Headers::value_type& lhs, bool name_less(const Headers::value_type& lhs,
const Headers::value_type& rhs) const Headers::value_type& rhs)
{ {
if(lhs.name.c_str()[0] == ':') {
if(rhs.name.c_str()[0] != ':') {
return true;
}
} else if(rhs.name.c_str()[0] == ':') {
return false;
}
return lhs.name < rhs.name; return lhs.name < rhs.name;
} }

View File

@ -35,17 +35,25 @@ namespace shrpx {
void test_downstream_normalize_request_headers(void) void test_downstream_normalize_request_headers(void)
{ {
Downstream d(nullptr, 0, 0); Downstream d(nullptr, 0, 0);
d.add_request_header("Charlie", "0"); d.add_request_header("1", "0");
d.add_request_header("Alpha", "1"); d.add_request_header("2", "1");
d.add_request_header("Delta", "2"); d.add_request_header("Charlie", "2");
d.add_request_header("BravO", "3"); d.add_request_header("Alpha", "3");
d.add_request_header("Delta", "4");
d.add_request_header("BravO", "5");
d.add_request_header(":method", "6");
d.add_request_header(":authority", "7");
d.normalize_request_headers(); d.normalize_request_headers();
auto ans = Headers{ auto ans = Headers{
{"alpha", "1"}, {":authority", "7"},
{"bravo", "3"}, {":method", "6"},
{"charlie", "0"}, {"1", "0"},
{"delta", "2"} {"2", "1"},
{"alpha", "3"},
{"bravo", "5"},
{"charlie", "2"},
{"delta", "4"}
}; };
CU_ASSERT(ans == d.get_request_headers()); CU_ASSERT(ans == d.get_request_headers());
} }