nghttp2_hd: Adjust maximum size to index based on table size
This commit is contained in:
parent
72aef67cca
commit
201ab1a140
|
@ -926,8 +926,14 @@ nghttp2_hd_entry* nghttp2_hd_table_get(nghttp2_hd_context *context,
|
|||
#define name_match(NV, NAME) \
|
||||
(nv->namelen == sizeof(NAME) - 1 && memeq(nv->name, NAME, sizeof(NAME) - 1))
|
||||
|
||||
static int should_indexing(const nghttp2_nv *nv)
|
||||
static int hd_deflate_should_indexing(nghttp2_hd_context *deflater,
|
||||
const nghttp2_nv *nv)
|
||||
{
|
||||
size_t table_size = nghttp2_min(deflater->deflate_hd_table_bufsize_max,
|
||||
deflater->hd_table_bufsize_max);
|
||||
if(entry_room(nv->namelen, nv->valuelen) > table_size * 3 / 4) {
|
||||
return 0;
|
||||
}
|
||||
#ifdef NGHTTP2_XHD
|
||||
return !name_match(nv, NGHTTP2_XHD);
|
||||
#else /* !NGHTTP2_XHD */
|
||||
|
@ -1020,8 +1026,7 @@ static int deflate_nv(nghttp2_hd_context *deflater,
|
|||
if(res.index != -1) {
|
||||
index = res.index;
|
||||
}
|
||||
if(should_indexing(nv) &&
|
||||
entry_room(nv->namelen, nv->valuelen) <= NGHTTP2_HD_MAX_ENTRY_SIZE) {
|
||||
if(hd_deflate_should_indexing(deflater, nv)) {
|
||||
nghttp2_hd_entry *new_ent;
|
||||
if(index >= (ssize_t)deflater->hd_table.len) {
|
||||
nghttp2_nv nv_indname;
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include <nghttp2/nghttp2.h>
|
||||
|
||||
#define NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE (1 << 12)
|
||||
#define NGHTTP2_HD_MAX_ENTRY_SIZE 3072
|
||||
#define NGHTTP2_HD_ENTRY_OVERHEAD 32
|
||||
|
||||
/* Default size of maximum table buffer size for encoder. Even if
|
||||
|
|
|
@ -331,10 +331,11 @@ void test_nghttp2_hd_deflate_deflate_buffer(void)
|
|||
|
||||
blocklen = nghttp2_hd_deflate_hd(&deflater, &buf, &buflen, 0, &nv3, 1);
|
||||
CU_ASSERT(blocklen > 0);
|
||||
/* Now header table should be empty */
|
||||
CU_ASSERT(0 == deflater.hd_table.len);
|
||||
CU_ASSERT(0 == deflater.deflate_hd_tablelen);
|
||||
CU_ASSERT(0 == deflater.deflate_hd_table_bufsize);
|
||||
/* Now header table should be unchanged, because we don't index
|
||||
large header */
|
||||
CU_ASSERT(4 == deflater.hd_table.len);
|
||||
CU_ASSERT(4 == deflater.deflate_hd_tablelen);
|
||||
CU_ASSERT(156 == deflater.deflate_hd_table_bufsize);
|
||||
|
||||
nghttp2_hd_deflate_free(&deflater);
|
||||
|
||||
|
@ -401,34 +402,6 @@ void test_nghttp2_hd_deflate_deflate_buffer(void)
|
|||
|
||||
nva_out_reset(&out);
|
||||
|
||||
blocklen = nghttp2_hd_deflate_hd(&deflater, &buf, &buflen, 0, &nv3, 1);
|
||||
CU_ASSERT(blocklen > 0);
|
||||
/* Now header table should look like this:
|
||||
*
|
||||
* 0: a..a, a..a (-)
|
||||
* 1: k1, v1 (-)
|
||||
* 2: k1000, v100 (-)
|
||||
* 3: k100, v100 (-)
|
||||
* 4: k10, v10 (-)
|
||||
* 5: k1, v1 (-)
|
||||
*
|
||||
* name/value of all entries must be NULL.
|
||||
*/
|
||||
CU_ASSERT(6 == deflater.hd_table.len);
|
||||
CU_ASSERT(0 == deflater.deflate_hd_tablelen);
|
||||
CU_ASSERT(0 == deflater.deflate_hd_table_bufsize);
|
||||
for(i = 0; i < 6; ++i) {
|
||||
ent = nghttp2_hd_table_get(&deflater, i);
|
||||
CU_ASSERT(0 == (ent->flags & NGHTTP2_HD_FLAG_REFSET));
|
||||
}
|
||||
|
||||
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, buf, blocklen));
|
||||
|
||||
CU_ASSERT(1 == out.nvlen);
|
||||
assert_nv_equal(&nv3, out.nva, 1);
|
||||
|
||||
nva_out_reset(&out);
|
||||
|
||||
free(buf);
|
||||
nghttp2_hd_inflate_free(&inflater);
|
||||
nghttp2_hd_deflate_free(&deflater);
|
||||
|
|
Loading…
Reference in New Issue