From 05f982dcfb21f0892e04a9abe5d240db293ad6b3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 7 Aug 2014 23:27:13 +0900 Subject: [PATCH] src: Sort header fields so that pseudo headers come first --- src/http2.cc | 8 ++++++++ src/shrpx_downstream_test.cc | 24 ++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/http2.cc b/src/http2.cc index 901698fc..22a73942 100644 --- a/src/http2.cc +++ b/src/http2.cc @@ -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, 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; } diff --git a/src/shrpx_downstream_test.cc b/src/shrpx_downstream_test.cc index 3a8bebc6..4694c098 100644 --- a/src/shrpx_downstream_test.cc +++ b/src/shrpx_downstream_test.cc @@ -35,17 +35,25 @@ namespace shrpx { void test_downstream_normalize_request_headers(void) { Downstream d(nullptr, 0, 0); - d.add_request_header("Charlie", "0"); - d.add_request_header("Alpha", "1"); - d.add_request_header("Delta", "2"); - d.add_request_header("BravO", "3"); + d.add_request_header("1", "0"); + d.add_request_header("2", "1"); + d.add_request_header("Charlie", "2"); + 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(); auto ans = Headers{ - {"alpha", "1"}, - {"bravo", "3"}, - {"charlie", "0"}, - {"delta", "2"} + {":authority", "7"}, + {":method", "6"}, + {"1", "0"}, + {"2", "1"}, + {"alpha", "3"}, + {"bravo", "5"}, + {"charlie", "2"}, + {"delta", "4"} }; CU_ASSERT(ans == d.get_request_headers()); }