Update huffman table and static table

Use huffman table in https://github.com/grmocg/httpbis-header-compression
This commit is contained in:
Tatsuhiro Tsujikawa 2013-10-21 23:56:14 +09:00
parent 9e50ae46d9
commit d5ccc89fc4
5 changed files with 2145 additions and 3320 deletions

View File

@ -31,61 +31,65 @@
#include "nghttp2_helper.h" #include "nghttp2_helper.h"
static const char *static_table[] = { static const char *static_table[] = {
/* 0 */ ":method", "GET", /* 0 */ ":authority", "",
/* 1 */ ":method", "POST", /* 1 */ ":method", "GET",
/* 2 */ ":scheme", "http", /* 2 */ ":method", "POST",
/* 3 */ ":scheme", "https", /* 3 */ ":path", "/",
/* 4 */ ":path", "/", /* 4 */ ":path", "/index.html",
/* 5 */ ":status", "200", /* 5 */ ":scheme", "http",
/* 6 */ ":authority", "", /* 6 */ ":scheme", "https",
/* 7 */ "accept-charset", "", /* 7 */ ":status", "200",
/* 8 */ "accept-encoding", "", /* 8 */ ":status", "500",
/* 9 */ "accept-language", "", /* 9 */ ":status", "404",
/* 10 */ "accept-ranges", "", /* 10 */ ":status", "403",
/* 11 */ "accept", "", /* 11 */ ":status", "400",
/* 12 */ "access-control-allow-origin", "", /* 12 */ ":status", "401",
/* 13 */ "age", "", /* 13 */ "accept-charset", "",
/* 14 */ "allow", "", /* 14 */ "accept-encoding", "",
/* 15 */ "authorization", "", /* 15 */ "accept-language", "",
/* 16 */ "cache-control", "", /* 16 */ "accept-ranges", "",
/* 17 */ "connection", "", /* 17 */ "accept", "",
/* 18 */ "content-disposition", "", /* 18 */ "access-control-allow-origin", "",
/* 19 */ "content-encoding", "", /* 19 */ "age", "",
/* 20 */ "content-language", "", /* 20 */ "allow", "",
/* 21 */ "content-length", "", /* 21 */ "authorization", "",
/* 22 */ "content-location", "", /* 22 */ "cache-control", "",
/* 23 */ "content-range", "", /* 23 */ "content-disposition", "",
/* 24 */ "content-type", "", /* 24 */ "content-encoding", "",
/* 25 */ "cookie", "", /* 25 */ "content-language", "",
/* 26 */ "date", "", /* 26 */ "content-length", "",
/* 27 */ "etag", "", /* 27 */ "content-location", "",
/* 28 */ "expect", "", /* 28 */ "content-range", "",
/* 29 */ "expires", "", /* 29 */ "content-type", "",
/* 30 */ "from", "", /* 30 */ "cookie", "",
/* 31 */ "host", "", /* 31 */ "date", "",
/* 32 */ "if-match", "", /* 32 */ "etag", "",
/* 33 */ "if-modified-since", "", /* 33 */ "expect", "",
/* 34 */ "if-none-match", "", /* 34 */ "expires", "",
/* 35 */ "if-range", "", /* 35 */ "from", "",
/* 36 */ "if-unmodified-since", "", /* 36 */ "if-match", "",
/* 37 */ "last-modified", "", /* 37 */ "if-modified-since", "",
/* 38 */ "link", "", /* 38 */ "if-none-match", "",
/* 39 */ "location", "", /* 39 */ "if-range", "",
/* 40 */ "max-forwards", "", /* 40 */ "if-unmodified-since", "",
/* 41 */ "proxy-authenticate", "", /* 41 */ "last-modified", "",
/* 42 */ "proxy-authorization", "", /* 42 */ "link", "",
/* 43 */ "range", "", /* 43 */ "location", "",
/* 44 */ "referer", "", /* 44 */ "max-forwards", "",
/* 45 */ "refresh", "", /* 45 */ "proxy-authenticate", "",
/* 46 */ "retry-after", "", /* 46 */ "proxy-authorization", "",
/* 47 */ "server", "", /* 47 */ "range", "",
/* 48 */ "set-cookie", "", /* 48 */ "referer", "",
/* 49 */ "strict-transport-security", "", /* 49 */ "refresh", "",
/* 50 */ "transfer-encoding", "", /* 50 */ "retry-after", "",
/* 51 */ "user-agent", "", /* 51 */ "server", "",
/* 52 */ "vary", "", /* 52 */ "set-cookie", "",
/* 53 */ "via", "", /* 53 */ "strict-transport-security", "",
/* 54 */ "www-authenticate", "", /* 54 */ "transfer-encoding", "",
/* 55 */ "user-agent", "",
/* 56 */ "vary", "",
/* 57 */ "via", "",
/* 58 */ "www-authenticate", "",
NULL NULL
}; };

View File

@ -275,8 +275,8 @@ nghttp2_hd_entry* nghttp2_hd_table_get(nghttp2_hd_context *context,
* is used. Otherwise, the response code table is used. * is used. Otherwise, the response code table is used.
* *
* This function returns the number of required bytes to encode given * This function returns the number of required bytes to encode given
* data, including terminal symbol code. This function always * data, including padding of prefix of terminal symbol code. This
* succeeds. * function always succeeds.
*/ */
size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len, size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len,
nghttp2_hd_side side); nghttp2_hd_side side);
@ -290,10 +290,10 @@ size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len,
* used. Otherwise, the response code table is used. * used. Otherwise, the response code table is used.
* *
* This function returns the number of written bytes, including * This function returns the number of written bytes, including
* terminal symbol code. This return value is exactly the same with * padding of prefix of terminal symbol code. This return value is
* the return value of nghttp2_hd_huff_encode_count() if it is given * exactly the same with the return value of
* with the same |src|, |srclen|, and |side|. This function always * nghttp2_hd_huff_encode_count() if it is given with the same |src|,
* succeeds. * |srclen|, and |side|. This function always succeeds.
*/ */
ssize_t nghttp2_hd_huff_encode(uint8_t *dest, size_t destlen, ssize_t nghttp2_hd_huff_encode(uint8_t *dest, size_t destlen,
const uint8_t *src, size_t srclen, const uint8_t *src, size_t srclen,
@ -301,9 +301,10 @@ ssize_t nghttp2_hd_huff_encode(uint8_t *dest, size_t destlen,
/* /*
* Counts the number of required bytes to decode |src| with length * Counts the number of required bytes to decode |src| with length
* |srclen|. The given input must be terminated with terminal code. If * |srclen|. The given input must be padded with the prefix of
* |side| is NGHTTP2_HD_SIDE_REQUEST, the request huffman code table * terminal code. If |side| is NGHTTP2_HD_SIDE_REQUEST, the request
* is used. Otherwise, the response code table is used. * huffman code table is used. Otherwise, the response code table is
* used.
* *
* This function returns the number of required bytes to decode given * This function returns the number of required bytes to decode given
* data if it succeeds, or -1. * data if it succeeds, or -1.
@ -314,9 +315,9 @@ ssize_t nghttp2_hd_huff_decode_count(const uint8_t *src, size_t srclen,
/* /*
* Decodes the given data |src| with length |srclen| to the given * Decodes the given data |src| with length |srclen| to the given
* memory location pointed by |dest|, allocated at lest |destlen| * memory location pointed by |dest|, allocated at lest |destlen|
* bytes. The given input must be terminated with terminal code. The * bytes. The given input must be padded with the prefix of terminal
* caller is responsible to specify |destlen| at least the length that * code. The caller is responsible to specify |destlen| at least the
* nghttp2_hd_huff_decode_count() returns. If |side| is * length that nghttp2_hd_huff_decode_count() returns. If |side| is
* NGHTTP2_HD_SIDE_REQUEST, the request huffman code table is * NGHTTP2_HD_SIDE_REQUEST, the request huffman code table is
* used. Otherwise, the response code table is used. * used. Otherwise, the response code table is used.
* *

View File

@ -156,8 +156,8 @@ size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len,
for(i = 0; i < len; ++i) { for(i = 0; i < len; ++i) {
nbits += huff_sym_table[src[i]].nbits; nbits += huff_sym_table[src[i]].nbits;
} }
/* 256 is special terminal symbol */ /* pad the prefix of EOS (256) */
return (nbits + huff_sym_table[256].nbits + 7) / 8; return (nbits + 7) / 8;
} }
ssize_t nghttp2_hd_huff_encode(uint8_t *dest, size_t destlen, ssize_t nghttp2_hd_huff_encode(uint8_t *dest, size_t destlen,
@ -179,8 +179,10 @@ ssize_t nghttp2_hd_huff_encode(uint8_t *dest, size_t destlen,
const nghttp2_huff_sym *sym = &huff_sym_table[src[i]]; const nghttp2_huff_sym *sym = &huff_sym_table[src[i]];
bitoff = huff_encode_sym(&dest, bitoff, sym); bitoff = huff_encode_sym(&dest, bitoff, sym);
} }
/* 256 is special terminal symbol */ /* 256 is special terminal symbol, pad with its prefix */
bitoff = huff_encode_sym(&dest, bitoff, &huff_sym_table[256]); if(bitoff > 0) {
*dest |= huff_sym_table[256].code[0] >> bitoff;
}
return dest - dest_first + (bitoff > 0); return dest - dest_first + (bitoff > 0);
} }
@ -204,6 +206,10 @@ ssize_t nghttp2_hd_huff_decode_count(const uint8_t *src, size_t srclen,
int rv = huff_decode(src + i, srclen - i, bitoff, int rv = huff_decode(src + i, srclen - i, bitoff,
huff_sym_table, huff_decode_table); huff_sym_table, huff_decode_table);
if(rv == -1) { if(rv == -1) {
/* TODO Check prefix of EOS */
if(i + 1 == srclen && bitoff > 0) {
break;
}
return -1; return -1;
} }
if(rv == 256) { if(rv == 256) {
@ -239,6 +245,10 @@ ssize_t nghttp2_hd_huff_decode(uint8_t *dest, size_t destlen,
int rv = huff_decode(src + i, srclen - i, bitoff, int rv = huff_decode(src + i, srclen - i, bitoff,
huff_sym_table, huff_decode_table); huff_sym_table, huff_decode_table);
if(rv == -1) { if(rv == -1) {
/* TODO Check prefix of EOS */
if(i + 1 == srclen && bitoff > 0) {
break;
}
return -1; return -1;
} }
if(rv == 256) { if(rv == 256) {

File diff suppressed because it is too large Load Diff

View File

@ -245,7 +245,7 @@ void test_nghttp2_hd_inflate_indname_inc(void)
nghttp2_nv *resnva; nghttp2_nv *resnva;
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST); nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST);
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&buf, &buflen, &offset, 51, CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&buf, &buflen, &offset, 55,
nv.value, nv.valuelen, 1, nv.value, nv.valuelen, 1,
NGHTTP2_HD_SIDE_REQUEST)); NGHTTP2_HD_SIDE_REQUEST));
CU_ASSERT(1 == nghttp2_hd_inflate_hd(&inflater, &resnva, buf, offset)); CU_ASSERT(1 == nghttp2_hd_inflate_hd(&inflater, &resnva, buf, offset));
@ -270,16 +270,16 @@ void test_nghttp2_hd_inflate_indname_inc_eviction(void)
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST); nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST);
memset(value, '0', sizeof(value)); memset(value, '0', sizeof(value));
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&buf, &buflen, &offset, 7, CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&buf, &buflen, &offset, 13,
value, sizeof(value), 1, value, sizeof(value), 1,
NGHTTP2_HD_SIDE_REQUEST)); NGHTTP2_HD_SIDE_REQUEST));
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&buf, &buflen, &offset, 8, CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&buf, &buflen, &offset, 14,
value, sizeof(value), 1, value, sizeof(value), 1,
NGHTTP2_HD_SIDE_REQUEST)); NGHTTP2_HD_SIDE_REQUEST));
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&buf, &buflen, &offset, 9, CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&buf, &buflen, &offset, 15,
value, sizeof(value), 1, value, sizeof(value), 1,
NGHTTP2_HD_SIDE_REQUEST)); NGHTTP2_HD_SIDE_REQUEST));
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&buf, &buflen, &offset, 10, CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&buf, &buflen, &offset, 16,
value, sizeof(value), 1, value, sizeof(value), 1,
NGHTTP2_HD_SIDE_REQUEST)); NGHTTP2_HD_SIDE_REQUEST));