diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 9f4bbd8f..d2e43d57 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -887,7 +887,7 @@ int Http2Handler::submit_push_promise(Stream *stream, auto promised_stream = util::make_unique(this, promised_stream_id); - append_nv(promised_stream.get(), http2::sort_nva(nva.data(), nva.size())); + append_nv(promised_stream.get(), nva); add_stream(promised_stream_id, std::move(promised_stream)); return 0; diff --git a/src/app_helper.cc b/src/app_helper.cc index b82f8ec3..92b5b8d1 100644 --- a/src/app_helper.cc +++ b/src/app_helper.cc @@ -187,10 +187,11 @@ void print_nv(nghttp2_nv *nv) namespace { void print_nv(nghttp2_nv *nva, size_t nvlen) { - for(auto& nv : http2::sort_nva(nva, nvlen)) { + auto end = nva + nvlen; + for(; nva != end; ++nva) { print_frame_attr_indent(); - print_nv(&nv); + print_nv(nva); } } } // namelen @@ -436,18 +437,16 @@ int verbose_on_header_callback(nghttp2_session *session, uint8_t flags, void *user_data) { - nghttp2_nv nva = { + nghttp2_nv nv = { const_cast(name), const_cast(value), namelen, valuelen }; - for(auto& nv : http2::sort_nva(&nva, 1)) { - print_timer(); - fprintf(outfile, " (stream_id=%d, noind=%d) ", frame->hd.stream_id, - (flags & NGHTTP2_NV_FLAG_NO_INDEX) != 0); + print_timer(); + fprintf(outfile, " (stream_id=%d, noind=%d) ", frame->hd.stream_id, + (flags & NGHTTP2_NV_FLAG_NO_INDEX) != 0); - print_nv(&nv); - } + print_nv(&nv); return 0; } diff --git a/src/http2.cc b/src/http2.cc index 5920a6c5..0d7cc591 100644 --- a/src/http2.cc +++ b/src/http2.cc @@ -224,13 +224,6 @@ namespace { size_t HTTP1_IGN_HDLEN = sizeof(HTTP1_IGN_HD)/sizeof(HTTP1_IGN_HD[0]); } // namespace -namespace { -auto nv_name_less = [](const nghttp2_nv& lhs, const nghttp2_nv& rhs) -{ - return nghttp2_nv_compare_name(&lhs, &rhs) < 0; -}; -} // namespace - bool name_less(const Headers::value_type& lhs, const Headers::value_type& rhs) { @@ -311,37 +304,6 @@ void normalize_headers(Headers& nva) std::stable_sort(std::begin(nva), std::end(nva), name_less); } -std::vector sort_nva(const nghttp2_nv *nva, size_t nvlen) -{ - auto v = std::vector(&nva[0], &nva[nvlen]); - std::sort(std::begin(v), std::end(v), nv_name_less); - auto res = std::vector(); - res.reserve(nvlen); - for(size_t i = 0; i < nvlen; ++i) { - if(v[i].valuelen == 0) { - res.push_back(v[i]); - continue; - } - auto j = v[i].value; - auto end = v[i].value + v[i].valuelen; - for(;;) { - // Skip 0 length value - j = std::find_if(j, end, - [](uint8_t c) - { - return c != '\0'; - }); - if(j == end) { - break; - } - auto l = std::find(j, end, '\0'); - res.push_back({v[i].name, j, v[i].namelen, static_cast(l - j)}); - j = l; - } - } - return res; -} - Headers::value_type to_header(const uint8_t *name, size_t namelen, const uint8_t *value, size_t valuelen, bool no_index) @@ -513,12 +475,11 @@ void dump_nv(FILE *out, const char **nv) void dump_nv(FILE *out, const nghttp2_nv *nva, size_t nvlen) { - // |nva| may have NULL-concatenated header fields - auto v = sort_nva(nva, nvlen); - for(auto& nv : v) { - fwrite(nv.name, nv.namelen, 1, out); + auto end = nva + nvlen; + for(; nva != end; ++nva) { + fwrite(nva->name, nva->namelen, 1, out); fwrite(": ", 2, 1, out); - fwrite(nv.value, nv.valuelen, 1, out); + fwrite(nva->value, nva->valuelen, 1, out); fwrite("\n", 1, 1, out); } fwrite("\n", 1, 1, out); diff --git a/src/http2.h b/src/http2.h index a063d2ee..7e1a4ff4 100644 --- a/src/http2.h +++ b/src/http2.h @@ -122,13 +122,6 @@ void add_header(Headers& nva, const uint8_t *value, size_t valuelen, bool no_index); -// Returns sorted |nva| with |nvlen| elements. The headers are sorted -// by name only and not necessarily stable. In addition to the -// sorting, this function splits values concatenated with NULL. The -// ordering of the concatenated values are preserved. The element of -// the returned vector refers to the memory pointed by |nva|. -std::vector sort_nva(const nghttp2_nv *nva, size_t nvlen); - // Returns the iterator to the entry in |nva| which has name |name| // and the |name| is uinque in the |nva|. If no such entry exist, // returns nullptr. diff --git a/src/http2_test.cc b/src/http2_test.cc index e59a4288..63d7074a 100644 --- a/src/http2_test.cc +++ b/src/http2_test.cc @@ -53,25 +53,6 @@ void check_nv(const Header& a, const nghttp2_nv *b) } } // namespace -void test_http2_sort_nva(void) -{ - // Last 0 is stripped in MAKE_NV - const uint8_t concatval[] = { '4', 0x00, 0x00, '6', 0x00, '5', 0x00 }; - nghttp2_nv nv[] = {MAKE_NV("alpha", "1"), - MAKE_NV("charlie", "3"), - MAKE_NV("bravo", "2"), - MAKE_NV("delta", concatval)}; - auto nvlen = sizeof(nv)/sizeof(nv[0]); - auto nva = http2::sort_nva(nv, nvlen); - CU_ASSERT(6 == nva.size()); - check_nv({"alpha", "1"}, &nva[0]); - check_nv({"bravo", "2"}, &nva[1]); - check_nv({"charlie", "3"}, &nva[2]); - check_nv({"delta", "4"}, &nva[3]); - check_nv({"delta", "6"}, &nva[4]); - check_nv({"delta", "5"}, &nva[5]); -} - void test_http2_add_header(void) { auto nva = Headers(); diff --git a/src/http2_test.h b/src/http2_test.h index b7a99c29..49b27487 100644 --- a/src/http2_test.h +++ b/src/http2_test.h @@ -28,7 +28,6 @@ namespace shrpx { void test_http2_add_header(void); -void test_http2_sort_nva(void); void test_http2_check_http2_headers(void); void test_http2_get_unique_header(void); void test_http2_get_header(void); diff --git a/src/shrpx-unittest.cc b/src/shrpx-unittest.cc index 0d6f0a5f..4e4c77b8 100644 --- a/src/shrpx-unittest.cc +++ b/src/shrpx-unittest.cc @@ -72,7 +72,6 @@ int main(int argc, char* argv[]) !CU_add_test(pSuite, "ssl_cert_lookup_tree_add_cert_from_file", shrpx::test_shrpx_ssl_cert_lookup_tree_add_cert_from_file) || !CU_add_test(pSuite, "http2_add_header", shrpx::test_http2_add_header) || - !CU_add_test(pSuite, "http2_sort_nva", shrpx::test_http2_sort_nva) || !CU_add_test(pSuite, "http2_check_http2_headers", shrpx::test_http2_check_http2_headers) || !CU_add_test(pSuite, "http2_get_unique_header",