src: Remove http2::sort_nva

This function is no longer necessary because 0x00 concatenation rule
is gone.
This commit is contained in:
Tatsuhiro Tsujikawa 2014-08-07 21:55:30 +09:00
parent 6ccf06c6da
commit 9fb2bc8468
7 changed files with 13 additions and 81 deletions

View File

@ -887,7 +887,7 @@ int Http2Handler::submit_push_promise(Stream *stream,
auto promised_stream = util::make_unique<Stream>(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;

View File

@ -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<uint8_t*>(name), const_cast<uint8_t*>(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_nv(&nv);
}
return 0;
}

View File

@ -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<nghttp2_nv> sort_nva(const nghttp2_nv *nva, size_t nvlen)
{
auto v = std::vector<nghttp2_nv>(&nva[0], &nva[nvlen]);
std::sort(std::begin(v), std::end(v), nv_name_less);
auto res = std::vector<nghttp2_nv>();
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<size_t>(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);

View File

@ -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<nghttp2_nv> 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.

View File

@ -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();

View File

@ -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);

View File

@ -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",