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"
static const char *static_table[] = {
/* 0 */ ":method", "GET",
/* 1 */ ":method", "POST",
/* 2 */ ":scheme", "http",
/* 3 */ ":scheme", "https",
/* 4 */ ":path", "/",
/* 5 */ ":status", "200",
/* 6 */ ":authority", "",
/* 7 */ "accept-charset", "",
/* 8 */ "accept-encoding", "",
/* 9 */ "accept-language", "",
/* 10 */ "accept-ranges", "",
/* 11 */ "accept", "",
/* 12 */ "access-control-allow-origin", "",
/* 13 */ "age", "",
/* 14 */ "allow", "",
/* 15 */ "authorization", "",
/* 16 */ "cache-control", "",
/* 17 */ "connection", "",
/* 18 */ "content-disposition", "",
/* 19 */ "content-encoding", "",
/* 20 */ "content-language", "",
/* 21 */ "content-length", "",
/* 22 */ "content-location", "",
/* 23 */ "content-range", "",
/* 24 */ "content-type", "",
/* 25 */ "cookie", "",
/* 26 */ "date", "",
/* 27 */ "etag", "",
/* 28 */ "expect", "",
/* 29 */ "expires", "",
/* 30 */ "from", "",
/* 31 */ "host", "",
/* 32 */ "if-match", "",
/* 33 */ "if-modified-since", "",
/* 34 */ "if-none-match", "",
/* 35 */ "if-range", "",
/* 36 */ "if-unmodified-since", "",
/* 37 */ "last-modified", "",
/* 38 */ "link", "",
/* 39 */ "location", "",
/* 40 */ "max-forwards", "",
/* 41 */ "proxy-authenticate", "",
/* 42 */ "proxy-authorization", "",
/* 43 */ "range", "",
/* 44 */ "referer", "",
/* 45 */ "refresh", "",
/* 46 */ "retry-after", "",
/* 47 */ "server", "",
/* 48 */ "set-cookie", "",
/* 49 */ "strict-transport-security", "",
/* 50 */ "transfer-encoding", "",
/* 51 */ "user-agent", "",
/* 52 */ "vary", "",
/* 53 */ "via", "",
/* 54 */ "www-authenticate", "",
/* 0 */ ":authority", "",
/* 1 */ ":method", "GET",
/* 2 */ ":method", "POST",
/* 3 */ ":path", "/",
/* 4 */ ":path", "/index.html",
/* 5 */ ":scheme", "http",
/* 6 */ ":scheme", "https",
/* 7 */ ":status", "200",
/* 8 */ ":status", "500",
/* 9 */ ":status", "404",
/* 10 */ ":status", "403",
/* 11 */ ":status", "400",
/* 12 */ ":status", "401",
/* 13 */ "accept-charset", "",
/* 14 */ "accept-encoding", "",
/* 15 */ "accept-language", "",
/* 16 */ "accept-ranges", "",
/* 17 */ "accept", "",
/* 18 */ "access-control-allow-origin", "",
/* 19 */ "age", "",
/* 20 */ "allow", "",
/* 21 */ "authorization", "",
/* 22 */ "cache-control", "",
/* 23 */ "content-disposition", "",
/* 24 */ "content-encoding", "",
/* 25 */ "content-language", "",
/* 26 */ "content-length", "",
/* 27 */ "content-location", "",
/* 28 */ "content-range", "",
/* 29 */ "content-type", "",
/* 30 */ "cookie", "",
/* 31 */ "date", "",
/* 32 */ "etag", "",
/* 33 */ "expect", "",
/* 34 */ "expires", "",
/* 35 */ "from", "",
/* 36 */ "if-match", "",
/* 37 */ "if-modified-since", "",
/* 38 */ "if-none-match", "",
/* 39 */ "if-range", "",
/* 40 */ "if-unmodified-since", "",
/* 41 */ "last-modified", "",
/* 42 */ "link", "",
/* 43 */ "location", "",
/* 44 */ "max-forwards", "",
/* 45 */ "proxy-authenticate", "",
/* 46 */ "proxy-authorization", "",
/* 47 */ "range", "",
/* 48 */ "referer", "",
/* 49 */ "refresh", "",
/* 50 */ "retry-after", "",
/* 51 */ "server", "",
/* 52 */ "set-cookie", "",
/* 53 */ "strict-transport-security", "",
/* 54 */ "transfer-encoding", "",
/* 55 */ "user-agent", "",
/* 56 */ "vary", "",
/* 57 */ "via", "",
/* 58 */ "www-authenticate", "",
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.
*
* This function returns the number of required bytes to encode given
* data, including terminal symbol code. This function always
* succeeds.
* data, including padding of prefix of terminal symbol code. This
* function always succeeds.
*/
size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len,
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.
*
* This function returns the number of written bytes, including
* terminal symbol code. This return value is exactly the same with
* the return value of nghttp2_hd_huff_encode_count() if it is given
* with the same |src|, |srclen|, and |side|. This function always
* succeeds.
* padding of prefix of terminal symbol code. This return value is
* exactly the same with the return value of
* nghttp2_hd_huff_encode_count() if it is given with the same |src|,
* |srclen|, and |side|. This function always succeeds.
*/
ssize_t nghttp2_hd_huff_encode(uint8_t *dest, size_t destlen,
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
* |srclen|. The given input must be terminated with terminal code. If
* |side| is NGHTTP2_HD_SIDE_REQUEST, the request huffman code table
* is used. Otherwise, the response code table is used.
* |srclen|. The given input must be padded with the prefix of
* terminal code. If |side| is NGHTTP2_HD_SIDE_REQUEST, the request
* huffman code table is used. Otherwise, the response code table is
* used.
*
* This function returns the number of required bytes to decode given
* 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
* memory location pointed by |dest|, allocated at lest |destlen|
* bytes. The given input must be terminated with terminal code. The
* caller is responsible to specify |destlen| at least the length that
* nghttp2_hd_huff_decode_count() returns. If |side| is
* bytes. The given input must be padded with the prefix of terminal
* code. The caller is responsible to specify |destlen| at least the
* length that nghttp2_hd_huff_decode_count() returns. If |side| is
* NGHTTP2_HD_SIDE_REQUEST, the request huffman code table is
* 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) {
nbits += huff_sym_table[src[i]].nbits;
}
/* 256 is special terminal symbol */
return (nbits + huff_sym_table[256].nbits + 7) / 8;
/* pad the prefix of EOS (256) */
return (nbits + 7) / 8;
}
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]];
bitoff = huff_encode_sym(&dest, bitoff, sym);
}
/* 256 is special terminal symbol */
bitoff = huff_encode_sym(&dest, bitoff, &huff_sym_table[256]);
/* 256 is special terminal symbol, pad with its prefix */
if(bitoff > 0) {
*dest |= huff_sym_table[256].code[0] >> bitoff;
}
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,
huff_sym_table, huff_decode_table);
if(rv == -1) {
/* TODO Check prefix of EOS */
if(i + 1 == srclen && bitoff > 0) {
break;
}
return -1;
}
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,
huff_sym_table, huff_decode_table);
if(rv == -1) {
/* TODO Check prefix of EOS */
if(i + 1 == srclen && bitoff > 0) {
break;
}
return -1;
}
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_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,
NGHTTP2_HD_SIDE_REQUEST));
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);
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,
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,
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,
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,
NGHTTP2_HD_SIDE_REQUEST));