nghttp2_hd: Define dedicated struct for HPACK deflater and inflater
This commit is contained in:
parent
45a9f0b637
commit
e7fc2951b8
|
@ -219,7 +219,7 @@ size_t nghttp2_frame_headers_payload_nv_offset(nghttp2_headers *frame)
|
||||||
ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr,
|
ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr,
|
||||||
size_t *buflen_ptr,
|
size_t *buflen_ptr,
|
||||||
nghttp2_headers *frame,
|
nghttp2_headers *frame,
|
||||||
nghttp2_hd_context *deflater)
|
nghttp2_hd_deflater *deflater)
|
||||||
{
|
{
|
||||||
ssize_t framelen;
|
ssize_t framelen;
|
||||||
size_t nv_offset = headers_nv_offset(frame);
|
size_t nv_offset = headers_nv_offset(frame);
|
||||||
|
@ -380,7 +380,7 @@ int nghttp2_frame_unpack_settings_payload2(nghttp2_settings_entry **iv_ptr,
|
||||||
ssize_t nghttp2_frame_pack_push_promise(uint8_t **buf_ptr,
|
ssize_t nghttp2_frame_pack_push_promise(uint8_t **buf_ptr,
|
||||||
size_t *buflen_ptr,
|
size_t *buflen_ptr,
|
||||||
nghttp2_push_promise *frame,
|
nghttp2_push_promise *frame,
|
||||||
nghttp2_hd_context *deflater)
|
nghttp2_hd_deflater *deflater)
|
||||||
{
|
{
|
||||||
ssize_t framelen;
|
ssize_t framelen;
|
||||||
size_t nv_offset = NGHTTP2_FRAME_HEAD_LENGTH + 4;
|
size_t nv_offset = NGHTTP2_FRAME_HEAD_LENGTH + 4;
|
||||||
|
|
|
@ -114,7 +114,7 @@ size_t nghttp2_frame_headers_payload_nv_offset(nghttp2_headers *frame);
|
||||||
ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr,
|
ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr,
|
||||||
size_t *buflen_ptr,
|
size_t *buflen_ptr,
|
||||||
nghttp2_headers *frame,
|
nghttp2_headers *frame,
|
||||||
nghttp2_hd_context *deflater);
|
nghttp2_hd_deflater *deflater);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks HEADERS frame byte sequence into |frame|. This function
|
* Unpacks HEADERS frame byte sequence into |frame|. This function
|
||||||
|
@ -257,7 +257,7 @@ int nghttp2_frame_unpack_settings_payload2(nghttp2_settings_entry **iv_ptr,
|
||||||
ssize_t nghttp2_frame_pack_push_promise(uint8_t **buf_ptr,
|
ssize_t nghttp2_frame_pack_push_promise(uint8_t **buf_ptr,
|
||||||
size_t *buflen_ptr,
|
size_t *buflen_ptr,
|
||||||
nghttp2_push_promise *frame,
|
nghttp2_push_promise *frame,
|
||||||
nghttp2_hd_context *deflater);
|
nghttp2_hd_deflater *deflater);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks PUSH_PROMISE frame byte sequence into |frame|. This function
|
* Unpacks PUSH_PROMISE frame byte sequence into |frame|. This function
|
||||||
|
|
155
lib/nghttp2_hd.c
155
lib/nghttp2_hd.c
|
@ -294,7 +294,6 @@ static int nghttp2_hd_context_init(nghttp2_hd_context *context,
|
||||||
context->role = role;
|
context->role = role;
|
||||||
context->side = side;
|
context->side = side;
|
||||||
context->bad = 0;
|
context->bad = 0;
|
||||||
context->no_refset = 0;
|
|
||||||
context->hd_table_bufsize_max = NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE;
|
context->hd_table_bufsize_max = NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE;
|
||||||
rv = nghttp2_hd_ringbuf_init
|
rv = nghttp2_hd_ringbuf_init
|
||||||
(&context->hd_table,
|
(&context->hd_table,
|
||||||
|
@ -303,11 +302,6 @@ static int nghttp2_hd_context_init(nghttp2_hd_context *context,
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
context->ent_keep = NULL;
|
|
||||||
context->name_keep = NULL;
|
|
||||||
context->value_keep = NULL;
|
|
||||||
context->end_headers_index = 0;
|
|
||||||
|
|
||||||
context->deflate_hd_table_bufsize_max = deflate_hd_table_bufsize_max;
|
context->deflate_hd_table_bufsize_max = deflate_hd_table_bufsize_max;
|
||||||
context->deflate_hd_table_bufsize = 0;
|
context->deflate_hd_table_bufsize = 0;
|
||||||
context->deflate_hd_tablelen = 0;
|
context->deflate_hd_tablelen = 0;
|
||||||
|
@ -315,28 +309,39 @@ static int nghttp2_hd_context_init(nghttp2_hd_context *context,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nghttp2_hd_deflate_init(nghttp2_hd_context *deflater, nghttp2_hd_side side)
|
int nghttp2_hd_deflate_init(nghttp2_hd_deflater *deflater, nghttp2_hd_side side)
|
||||||
{
|
{
|
||||||
return nghttp2_hd_deflate_init2(deflater, side,
|
return nghttp2_hd_deflate_init2(deflater, side,
|
||||||
NGHTTP2_HD_DEFAULT_MAX_DEFLATE_BUFFER_SIZE);
|
NGHTTP2_HD_DEFAULT_MAX_DEFLATE_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int nghttp2_hd_deflate_init2(nghttp2_hd_context *deflater,
|
int nghttp2_hd_deflate_init2(nghttp2_hd_deflater *deflater,
|
||||||
nghttp2_hd_side side,
|
nghttp2_hd_side side,
|
||||||
size_t deflate_hd_table_bufsize_max)
|
size_t deflate_hd_table_bufsize_max)
|
||||||
{
|
{
|
||||||
return nghttp2_hd_context_init(deflater, NGHTTP2_HD_ROLE_DEFLATE, side,
|
int rv;
|
||||||
deflate_hd_table_bufsize_max);
|
rv = nghttp2_hd_context_init(&deflater->ctx, NGHTTP2_HD_ROLE_DEFLATE, side,
|
||||||
|
deflate_hd_table_bufsize_max);
|
||||||
|
if(rv != 0) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
deflater->no_refset = 0;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nghttp2_hd_inflate_init(nghttp2_hd_context *inflater, nghttp2_hd_side side)
|
int nghttp2_hd_inflate_init(nghttp2_hd_inflater *inflater, nghttp2_hd_side side)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
rv = nghttp2_hd_context_init(inflater, NGHTTP2_HD_ROLE_INFLATE, side,
|
rv = nghttp2_hd_context_init(&inflater->ctx, NGHTTP2_HD_ROLE_INFLATE, side,
|
||||||
NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE);
|
NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
inflater->ent_keep = NULL;
|
||||||
|
inflater->name_keep = NULL;
|
||||||
|
inflater->value_keep = NULL;
|
||||||
|
inflater->end_headers_index = 0;
|
||||||
|
|
||||||
inflater->opcode = NGHTTP2_HD_OPCODE_NONE;
|
inflater->opcode = NGHTTP2_HD_OPCODE_NONE;
|
||||||
inflater->state = NGHTTP2_HD_STATE_OPCODE;
|
inflater->state = NGHTTP2_HD_STATE_OPCODE;
|
||||||
nghttp2_buffer_init(&inflater->namebuf, NGHTTP2_HD_MAX_NAME);
|
nghttp2_buffer_init(&inflater->namebuf, NGHTTP2_HD_MAX_NAME);
|
||||||
|
@ -349,7 +354,7 @@ int nghttp2_hd_inflate_init(nghttp2_hd_context *inflater, nghttp2_hd_side side)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hd_inflate_keep_free(nghttp2_hd_context *inflater)
|
static void hd_inflate_keep_free(nghttp2_hd_inflater *inflater)
|
||||||
{
|
{
|
||||||
if(inflater->ent_keep) {
|
if(inflater->ent_keep) {
|
||||||
if(inflater->ent_keep->ref == 0) {
|
if(inflater->ent_keep->ref == 0) {
|
||||||
|
@ -369,20 +374,20 @@ static void nghttp2_hd_context_free(nghttp2_hd_context *context)
|
||||||
nghttp2_hd_ringbuf_free(&context->hd_table);
|
nghttp2_hd_ringbuf_free(&context->hd_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nghttp2_hd_deflate_free(nghttp2_hd_context *deflater)
|
void nghttp2_hd_deflate_free(nghttp2_hd_deflater *deflater)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context_free(deflater);
|
nghttp2_hd_context_free(&deflater->ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nghttp2_hd_inflate_free(nghttp2_hd_context *inflater)
|
void nghttp2_hd_inflate_free(nghttp2_hd_inflater *inflater)
|
||||||
{
|
{
|
||||||
hd_inflate_keep_free(inflater);
|
hd_inflate_keep_free(inflater);
|
||||||
nghttp2_buffer_free(&inflater->namebuf);
|
nghttp2_buffer_free(&inflater->namebuf);
|
||||||
nghttp2_buffer_free(&inflater->valuebuf);
|
nghttp2_buffer_free(&inflater->valuebuf);
|
||||||
nghttp2_hd_context_free(inflater);
|
nghttp2_hd_context_free(&inflater->ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nghttp2_hd_deflate_set_no_refset(nghttp2_hd_context *deflater,
|
void nghttp2_hd_deflate_set_no_refset(nghttp2_hd_deflater *deflater,
|
||||||
uint8_t no_refset)
|
uint8_t no_refset)
|
||||||
{
|
{
|
||||||
deflater->no_refset = no_refset;
|
deflater->no_refset = no_refset;
|
||||||
|
@ -393,9 +398,7 @@ static size_t entry_room(size_t namelen, size_t valuelen)
|
||||||
return NGHTTP2_HD_ENTRY_OVERHEAD + namelen + valuelen;
|
return NGHTTP2_HD_ENTRY_OVERHEAD + namelen + valuelen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int emit_indexed_header(nghttp2_hd_context *inflater,
|
static int emit_indexed_header(nghttp2_nv *nv_out, nghttp2_hd_entry *ent)
|
||||||
nghttp2_nv *nv_out,
|
|
||||||
nghttp2_hd_entry *ent)
|
|
||||||
{
|
{
|
||||||
DEBUGF(fprintf(stderr, "Header emission:\n"));
|
DEBUGF(fprintf(stderr, "Header emission:\n"));
|
||||||
DEBUGF(fwrite(ent->nv.name, ent->nv.namelen, 1, stderr));
|
DEBUGF(fwrite(ent->nv.name, ent->nv.namelen, 1, stderr));
|
||||||
|
@ -410,9 +413,7 @@ static int emit_indexed_header(nghttp2_hd_context *inflater,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int emit_newname_header(nghttp2_hd_context *inflater,
|
static int emit_newname_header(nghttp2_nv *nv_out, nghttp2_nv *nv)
|
||||||
nghttp2_nv *nv_out,
|
|
||||||
nghttp2_nv *nv)
|
|
||||||
{
|
{
|
||||||
DEBUGF(fprintf(stderr, "Header emission:\n"));
|
DEBUGF(fprintf(stderr, "Header emission:\n"));
|
||||||
DEBUGF(fwrite(nv->name, nv->namelen, 1, stderr));
|
DEBUGF(fwrite(nv->name, nv->namelen, 1, stderr));
|
||||||
|
@ -423,9 +424,7 @@ static int emit_newname_header(nghttp2_hd_context *inflater,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int emit_indname_header(nghttp2_hd_context *inflater,
|
static int emit_indname_header(nghttp2_nv *nv_out, nghttp2_hd_entry *ent,
|
||||||
nghttp2_nv *nv_out,
|
|
||||||
nghttp2_hd_entry *ent,
|
|
||||||
uint8_t *value, size_t valuelen)
|
uint8_t *value, size_t valuelen)
|
||||||
{
|
{
|
||||||
DEBUGF(fprintf(stderr, "Header emission:\n"));
|
DEBUGF(fprintf(stderr, "Header emission:\n"));
|
||||||
|
@ -440,7 +439,6 @@ static int emit_indname_header(nghttp2_hd_context *inflater,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int ensure_write_buffer(uint8_t **buf_ptr, size_t *buflen_ptr,
|
static int ensure_write_buffer(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
size_t offset, size_t need)
|
size_t offset, size_t need)
|
||||||
{
|
{
|
||||||
|
@ -963,11 +961,11 @@ nghttp2_hd_entry* nghttp2_hd_table_get(nghttp2_hd_context *context,
|
||||||
#define name_match(NV, NAME) \
|
#define name_match(NV, NAME) \
|
||||||
(nv->namelen == sizeof(NAME) - 1 && memeq(nv->name, NAME, sizeof(NAME) - 1))
|
(nv->namelen == sizeof(NAME) - 1 && memeq(nv->name, NAME, sizeof(NAME) - 1))
|
||||||
|
|
||||||
static int hd_deflate_should_indexing(nghttp2_hd_context *deflater,
|
static int hd_deflate_should_indexing(nghttp2_hd_deflater *deflater,
|
||||||
const nghttp2_nv *nv)
|
const nghttp2_nv *nv)
|
||||||
{
|
{
|
||||||
size_t table_size = nghttp2_min(deflater->deflate_hd_table_bufsize_max,
|
size_t table_size = nghttp2_min(deflater->ctx.deflate_hd_table_bufsize_max,
|
||||||
deflater->hd_table_bufsize_max);
|
deflater->ctx.hd_table_bufsize_max);
|
||||||
if(entry_room(nv->namelen, nv->valuelen) > table_size * 3 / 4) {
|
if(entry_room(nv->namelen, nv->valuelen) > table_size * 3 / 4) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -983,7 +981,7 @@ static int hd_deflate_should_indexing(nghttp2_hd_context *deflater,
|
||||||
#endif /* !NGHTTP2_XHD */
|
#endif /* !NGHTTP2_XHD */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int deflate_nv(nghttp2_hd_context *deflater,
|
static int deflate_nv(nghttp2_hd_deflater *deflater,
|
||||||
uint8_t **buf_ptr, size_t *buflen_ptr,
|
uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
size_t *offset_ptr,
|
size_t *offset_ptr,
|
||||||
nghttp2_nv *nv)
|
nghttp2_nv *nv)
|
||||||
|
@ -991,16 +989,16 @@ static int deflate_nv(nghttp2_hd_context *deflater,
|
||||||
int rv;
|
int rv;
|
||||||
nghttp2_hd_entry *ent;
|
nghttp2_hd_entry *ent;
|
||||||
search_result res;
|
search_result res;
|
||||||
res = search_hd_table(deflater, nv);
|
res = search_hd_table(&deflater->ctx, nv);
|
||||||
if(res.index != -1 && res.name_value_match) {
|
if(res.index != -1 && res.name_value_match) {
|
||||||
size_t index = res.index;
|
size_t index = res.index;
|
||||||
ent = nghttp2_hd_table_get(deflater, index);
|
ent = nghttp2_hd_table_get(&deflater->ctx, index);
|
||||||
if(index >= deflater->hd_table.len) {
|
if(index >= deflater->ctx.hd_table.len) {
|
||||||
nghttp2_hd_entry *new_ent;
|
nghttp2_hd_entry *new_ent;
|
||||||
/* It is important to first add entry to the header table and
|
/* It is important to first add entry to the header table and
|
||||||
let eviction go. If NGHTTP2_HD_FLAG_IMPLICIT_EMIT entry is
|
let eviction go. If NGHTTP2_HD_FLAG_IMPLICIT_EMIT entry is
|
||||||
evicted, it must be emitted before the |nv|. */
|
evicted, it must be emitted before the |nv|. */
|
||||||
new_ent = add_hd_table_incremental(deflater, buf_ptr, buflen_ptr,
|
new_ent = add_hd_table_incremental(&deflater->ctx, buf_ptr, buflen_ptr,
|
||||||
offset_ptr, &ent->nv,
|
offset_ptr, &ent->nv,
|
||||||
NGHTTP2_HD_FLAG_NONE);
|
NGHTTP2_HD_FLAG_NONE);
|
||||||
if(!new_ent) {
|
if(!new_ent) {
|
||||||
|
@ -1065,15 +1063,15 @@ static int deflate_nv(nghttp2_hd_context *deflater,
|
||||||
}
|
}
|
||||||
if(hd_deflate_should_indexing(deflater, nv)) {
|
if(hd_deflate_should_indexing(deflater, nv)) {
|
||||||
nghttp2_hd_entry *new_ent;
|
nghttp2_hd_entry *new_ent;
|
||||||
if(index >= (ssize_t)deflater->hd_table.len) {
|
if(index >= (ssize_t)deflater->ctx.hd_table.len) {
|
||||||
nghttp2_nv nv_indname;
|
nghttp2_nv nv_indname;
|
||||||
nv_indname = *nv;
|
nv_indname = *nv;
|
||||||
nv_indname.name = nghttp2_hd_table_get(deflater, index)->nv.name;
|
nv_indname.name = nghttp2_hd_table_get(&deflater->ctx, index)->nv.name;
|
||||||
new_ent = add_hd_table_incremental(deflater, buf_ptr, buflen_ptr,
|
new_ent = add_hd_table_incremental(&deflater->ctx, buf_ptr, buflen_ptr,
|
||||||
offset_ptr, &nv_indname,
|
offset_ptr, &nv_indname,
|
||||||
NGHTTP2_HD_FLAG_VALUE_ALLOC);
|
NGHTTP2_HD_FLAG_VALUE_ALLOC);
|
||||||
} else {
|
} else {
|
||||||
new_ent = add_hd_table_incremental(deflater, buf_ptr, buflen_ptr,
|
new_ent = add_hd_table_incremental(&deflater->ctx, buf_ptr, buflen_ptr,
|
||||||
offset_ptr, nv,
|
offset_ptr, nv,
|
||||||
NGHTTP2_HD_FLAG_NAME_ALLOC |
|
NGHTTP2_HD_FLAG_NAME_ALLOC |
|
||||||
NGHTTP2_HD_FLAG_VALUE_ALLOC);
|
NGHTTP2_HD_FLAG_VALUE_ALLOC);
|
||||||
|
@ -1093,11 +1091,11 @@ static int deflate_nv(nghttp2_hd_context *deflater,
|
||||||
}
|
}
|
||||||
if(index == -1) {
|
if(index == -1) {
|
||||||
rv = emit_newname_block(buf_ptr, buflen_ptr, offset_ptr, nv, incidx,
|
rv = emit_newname_block(buf_ptr, buflen_ptr, offset_ptr, nv, incidx,
|
||||||
deflater->side);
|
deflater->ctx.side);
|
||||||
} else {
|
} else {
|
||||||
rv = emit_indname_block(buf_ptr, buflen_ptr, offset_ptr, index,
|
rv = emit_indname_block(buf_ptr, buflen_ptr, offset_ptr, index,
|
||||||
nv->value, nv->valuelen, incidx,
|
nv->value, nv->valuelen, incidx,
|
||||||
deflater->side);
|
deflater->ctx.side);
|
||||||
}
|
}
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -1128,14 +1126,14 @@ static int deflate_post_process_hd_entry(nghttp2_hd_entry *ent,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_context *deflater,
|
ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,
|
||||||
uint8_t **buf_ptr, size_t *buflen_ptr,
|
uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
size_t nv_offset,
|
size_t nv_offset,
|
||||||
nghttp2_nv *nv, size_t nvlen)
|
nghttp2_nv *nv, size_t nvlen)
|
||||||
{
|
{
|
||||||
size_t i, offset;
|
size_t i, offset;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
if(deflater->bad) {
|
if(deflater->ctx.bad) {
|
||||||
return NGHTTP2_ERR_HEADER_COMP;
|
return NGHTTP2_ERR_HEADER_COMP;
|
||||||
}
|
}
|
||||||
offset = nv_offset;
|
offset = nv_offset;
|
||||||
|
@ -1144,7 +1142,7 @@ ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_context *deflater,
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
clear_refset(deflater);
|
clear_refset(&deflater->ctx);
|
||||||
}
|
}
|
||||||
for(i = 0; i < nvlen; ++i) {
|
for(i = 0; i < nvlen; ++i) {
|
||||||
rv = deflate_nv(deflater, buf_ptr, buflen_ptr, &offset, &nv[i]);
|
rv = deflate_nv(deflater, buf_ptr, buflen_ptr, &offset, &nv[i]);
|
||||||
|
@ -1152,8 +1150,8 @@ ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_context *deflater,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(i = 0; i < deflater->deflate_hd_tablelen; ++i) {
|
for(i = 0; i < deflater->ctx.deflate_hd_tablelen; ++i) {
|
||||||
nghttp2_hd_entry *ent = nghttp2_hd_ringbuf_get(&deflater->hd_table, i);
|
nghttp2_hd_entry *ent = nghttp2_hd_ringbuf_get(&deflater->ctx.hd_table, i);
|
||||||
rv = deflate_post_process_hd_entry(ent, i, buf_ptr, buflen_ptr, &offset);
|
rv = deflate_post_process_hd_entry(ent, i, buf_ptr, buflen_ptr, &offset);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -1161,11 +1159,11 @@ ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_context *deflater,
|
||||||
}
|
}
|
||||||
return offset - nv_offset;
|
return offset - nv_offset;
|
||||||
fail:
|
fail:
|
||||||
deflater->bad = 1;
|
deflater->ctx.bad = 1;
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hd_inflate_set_huffman_encoded(nghttp2_hd_context *inflater,
|
static void hd_inflate_set_huffman_encoded(nghttp2_hd_inflater *inflater,
|
||||||
const uint8_t *in)
|
const uint8_t *in)
|
||||||
{
|
{
|
||||||
inflater->huffman_encoded = (*in & (1 << 7)) != 0;
|
inflater->huffman_encoded = (*in & (1 << 7)) != 0;
|
||||||
|
@ -1184,7 +1182,7 @@ static void hd_inflate_set_huffman_encoded(nghttp2_hd_context *inflater,
|
||||||
* NGHTTP2_ERR_HEADER_COMP
|
* NGHTTP2_ERR_HEADER_COMP
|
||||||
* Integer decoding failed
|
* Integer decoding failed
|
||||||
*/
|
*/
|
||||||
static ssize_t hd_inflate_read_len(nghttp2_hd_context *inflater,
|
static ssize_t hd_inflate_read_len(nghttp2_hd_inflater *inflater,
|
||||||
int *rfin,
|
int *rfin,
|
||||||
uint8_t *in, uint8_t *last,
|
uint8_t *in, uint8_t *last,
|
||||||
int prefix, size_t maxlen)
|
int prefix, size_t maxlen)
|
||||||
|
@ -1216,7 +1214,7 @@ static ssize_t hd_inflate_read_len(nghttp2_hd_context *inflater,
|
||||||
* NGHTTP2_ERR_HEADER_COMP
|
* NGHTTP2_ERR_HEADER_COMP
|
||||||
* Huffman decoding failed
|
* Huffman decoding failed
|
||||||
*/
|
*/
|
||||||
static ssize_t hd_inflate_read_huff(nghttp2_hd_context *inflater,
|
static ssize_t hd_inflate_read_huff(nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_buffer *buffer,
|
nghttp2_buffer *buffer,
|
||||||
uint8_t *in, uint8_t *last)
|
uint8_t *in, uint8_t *last)
|
||||||
{
|
{
|
||||||
|
@ -1251,7 +1249,7 @@ static ssize_t hd_inflate_read_huff(nghttp2_hd_context *inflater,
|
||||||
* NGHTTP2_ERR_HEADER_COMP
|
* NGHTTP2_ERR_HEADER_COMP
|
||||||
* Header decompression failed
|
* Header decompression failed
|
||||||
*/
|
*/
|
||||||
static ssize_t hd_inflate_read(nghttp2_hd_context *inflater,
|
static ssize_t hd_inflate_read(nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_buffer *buffer,
|
nghttp2_buffer *buffer,
|
||||||
uint8_t *in, uint8_t *last)
|
uint8_t *in, uint8_t *last)
|
||||||
{
|
{
|
||||||
|
@ -1279,25 +1277,25 @@ static ssize_t hd_inflate_read(nghttp2_hd_context *inflater,
|
||||||
* NGHTTP2_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory
|
* Out of memory
|
||||||
*/
|
*/
|
||||||
static int hd_inflate_commit_indexed(nghttp2_hd_context *inflater,
|
static int hd_inflate_commit_indexed(nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_nv *nv_out)
|
nghttp2_nv *nv_out)
|
||||||
{
|
{
|
||||||
nghttp2_hd_entry *ent = nghttp2_hd_table_get(inflater, inflater->index);
|
nghttp2_hd_entry *ent = nghttp2_hd_table_get(&inflater->ctx, inflater->index);
|
||||||
if(inflater->index >= inflater->hd_table.len) {
|
if(inflater->index >= inflater->ctx.hd_table.len) {
|
||||||
nghttp2_hd_entry *new_ent;
|
nghttp2_hd_entry *new_ent;
|
||||||
new_ent = add_hd_table_incremental(inflater, NULL, NULL, NULL,
|
new_ent = add_hd_table_incremental(&inflater->ctx, NULL, NULL, NULL,
|
||||||
&ent->nv, NGHTTP2_HD_FLAG_NONE);
|
&ent->nv, NGHTTP2_HD_FLAG_NONE);
|
||||||
if(!new_ent) {
|
if(!new_ent) {
|
||||||
return NGHTTP2_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
/* new_ent->ref == 0 may be hold */
|
/* new_ent->ref == 0 may be hold */
|
||||||
emit_indexed_header(inflater, nv_out, new_ent);
|
emit_indexed_header(nv_out, new_ent);
|
||||||
inflater->ent_keep = new_ent;
|
inflater->ent_keep = new_ent;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ent->flags ^= NGHTTP2_HD_FLAG_REFSET;
|
ent->flags ^= NGHTTP2_HD_FLAG_REFSET;
|
||||||
if(ent->flags & NGHTTP2_HD_FLAG_REFSET) {
|
if(ent->flags & NGHTTP2_HD_FLAG_REFSET) {
|
||||||
emit_indexed_header(inflater, nv_out, ent);
|
emit_indexed_header(nv_out, ent);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DEBUGF(fprintf(stderr, "Toggle off item:\n"));
|
DEBUGF(fprintf(stderr, "Toggle off item:\n"));
|
||||||
|
@ -1319,7 +1317,7 @@ static int hd_inflate_commit_indexed(nghttp2_hd_context *inflater,
|
||||||
* NGHTTP2_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory
|
* Out of memory
|
||||||
*/
|
*/
|
||||||
static int hd_inflate_commit_newname(nghttp2_hd_context *inflater,
|
static int hd_inflate_commit_newname(nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_nv *nv_out)
|
nghttp2_nv *nv_out)
|
||||||
{
|
{
|
||||||
nghttp2_nv nv = {
|
nghttp2_nv nv = {
|
||||||
|
@ -1333,18 +1331,18 @@ static int hd_inflate_commit_newname(nghttp2_hd_context *inflater,
|
||||||
uint8_t ent_flags =
|
uint8_t ent_flags =
|
||||||
NGHTTP2_HD_FLAG_NAME_ALLOC | NGHTTP2_HD_FLAG_VALUE_ALLOC |
|
NGHTTP2_HD_FLAG_NAME_ALLOC | NGHTTP2_HD_FLAG_VALUE_ALLOC |
|
||||||
NGHTTP2_HD_FLAG_NAME_GIFT | NGHTTP2_HD_FLAG_VALUE_GIFT;
|
NGHTTP2_HD_FLAG_NAME_GIFT | NGHTTP2_HD_FLAG_VALUE_GIFT;
|
||||||
new_ent = add_hd_table_incremental(inflater, NULL, NULL, NULL, &nv,
|
new_ent = add_hd_table_incremental(&inflater->ctx, NULL, NULL, NULL, &nv,
|
||||||
ent_flags);
|
ent_flags);
|
||||||
if(new_ent) {
|
if(new_ent) {
|
||||||
nghttp2_buffer_release(&inflater->namebuf);
|
nghttp2_buffer_release(&inflater->namebuf);
|
||||||
nghttp2_buffer_release(&inflater->valuebuf);
|
nghttp2_buffer_release(&inflater->valuebuf);
|
||||||
emit_indexed_header(inflater, nv_out, new_ent);
|
emit_indexed_header(nv_out, new_ent);
|
||||||
inflater->ent_keep = new_ent;
|
inflater->ent_keep = new_ent;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return NGHTTP2_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
emit_newname_header(inflater, nv_out, &nv);
|
emit_newname_header(nv_out, &nv);
|
||||||
inflater->name_keep = inflater->namebuf.buf;
|
inflater->name_keep = inflater->namebuf.buf;
|
||||||
nghttp2_buffer_release(&inflater->namebuf);
|
nghttp2_buffer_release(&inflater->namebuf);
|
||||||
inflater->value_keep = inflater->valuebuf.buf;
|
inflater->value_keep = inflater->valuebuf.buf;
|
||||||
|
@ -1363,7 +1361,7 @@ static int hd_inflate_commit_newname(nghttp2_hd_context *inflater,
|
||||||
* NGHTTP2_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory
|
* Out of memory
|
||||||
*/
|
*/
|
||||||
static int hd_inflate_commit_indname(nghttp2_hd_context *inflater,
|
static int hd_inflate_commit_indname(nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_nv *nv_out)
|
nghttp2_nv *nv_out)
|
||||||
{
|
{
|
||||||
if(inflater->index_required) {
|
if(inflater->index_required) {
|
||||||
|
@ -1372,7 +1370,7 @@ static int hd_inflate_commit_indname(nghttp2_hd_context *inflater,
|
||||||
uint8_t ent_flags = NGHTTP2_HD_FLAG_VALUE_ALLOC |
|
uint8_t ent_flags = NGHTTP2_HD_FLAG_VALUE_ALLOC |
|
||||||
NGHTTP2_HD_FLAG_VALUE_GIFT;
|
NGHTTP2_HD_FLAG_VALUE_GIFT;
|
||||||
|
|
||||||
if(inflater->index < inflater->hd_table.len) {
|
if(inflater->index < inflater->ctx.hd_table.len) {
|
||||||
ent_flags |= NGHTTP2_HD_FLAG_NAME_ALLOC;
|
ent_flags |= NGHTTP2_HD_FLAG_NAME_ALLOC;
|
||||||
}
|
}
|
||||||
++inflater->ent_name->ref;
|
++inflater->ent_name->ref;
|
||||||
|
@ -1380,7 +1378,7 @@ static int hd_inflate_commit_indname(nghttp2_hd_context *inflater,
|
||||||
nv.namelen = inflater->ent_name->nv.namelen;
|
nv.namelen = inflater->ent_name->nv.namelen;
|
||||||
nv.value = inflater->valuebuf.buf;
|
nv.value = inflater->valuebuf.buf;
|
||||||
nv.valuelen = inflater->valuebuf.len;
|
nv.valuelen = inflater->valuebuf.len;
|
||||||
new_ent = add_hd_table_incremental(inflater, NULL, NULL, NULL, &nv,
|
new_ent = add_hd_table_incremental(&inflater->ctx, NULL, NULL, NULL, &nv,
|
||||||
ent_flags);
|
ent_flags);
|
||||||
if(--inflater->ent_name->ref == 0) {
|
if(--inflater->ent_name->ref == 0) {
|
||||||
nghttp2_hd_entry_free(inflater->ent_name);
|
nghttp2_hd_entry_free(inflater->ent_name);
|
||||||
|
@ -1389,13 +1387,13 @@ static int hd_inflate_commit_indname(nghttp2_hd_context *inflater,
|
||||||
inflater->ent_name = NULL;
|
inflater->ent_name = NULL;
|
||||||
if(new_ent) {
|
if(new_ent) {
|
||||||
nghttp2_buffer_release(&inflater->valuebuf);
|
nghttp2_buffer_release(&inflater->valuebuf);
|
||||||
emit_indexed_header(inflater, nv_out, new_ent);
|
emit_indexed_header(nv_out, new_ent);
|
||||||
inflater->ent_keep = new_ent;
|
inflater->ent_keep = new_ent;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return NGHTTP2_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
emit_indname_header(inflater, nv_out, inflater->ent_name,
|
emit_indname_header(nv_out, inflater->ent_name,
|
||||||
inflater->valuebuf.buf, inflater->valuebuf.len);
|
inflater->valuebuf.buf, inflater->valuebuf.len);
|
||||||
inflater->value_keep = inflater->valuebuf.buf;
|
inflater->value_keep = inflater->valuebuf.buf;
|
||||||
nghttp2_buffer_release(&inflater->valuebuf);
|
nghttp2_buffer_release(&inflater->valuebuf);
|
||||||
|
@ -1407,7 +1405,7 @@ static size_t guess_huff_decode_len(size_t encode_len)
|
||||||
return encode_len * 3 / 2;
|
return encode_len * 3 / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_nv *nv_out, int *inflate_flags,
|
nghttp2_nv *nv_out, int *inflate_flags,
|
||||||
uint8_t *in, size_t inlen, int in_final)
|
uint8_t *in, size_t inlen, int in_final)
|
||||||
{
|
{
|
||||||
|
@ -1450,7 +1448,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
||||||
rv = hd_inflate_read_len(inflater, &rfin, in, last,
|
rv = hd_inflate_read_len(inflater, &rfin, in, last,
|
||||||
inflater->opcode == NGHTTP2_HD_OPCODE_INDEXED ?
|
inflater->opcode == NGHTTP2_HD_OPCODE_INDEXED ?
|
||||||
7 : 6,
|
7 : 6,
|
||||||
get_max_index(inflater) + 1);
|
get_max_index(&inflater->ctx) + 1);
|
||||||
if(rv < 0) {
|
if(rv < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1463,7 +1461,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
||||||
inflater->index = inflater->left;
|
inflater->index = inflater->left;
|
||||||
if(inflater->index == 0) {
|
if(inflater->index == 0) {
|
||||||
DEBUGF(fprintf(stderr, "Clearing reference set\n"));
|
DEBUGF(fprintf(stderr, "Clearing reference set\n"));
|
||||||
clear_refset(inflater);
|
clear_refset(&inflater->ctx);
|
||||||
inflater->state = NGHTTP2_HD_STATE_OPCODE;
|
inflater->state = NGHTTP2_HD_STATE_OPCODE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1481,7 +1479,8 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
||||||
} else {
|
} else {
|
||||||
inflater->index = inflater->left;
|
inflater->index = inflater->left;
|
||||||
--inflater->index;
|
--inflater->index;
|
||||||
inflater->ent_name = nghttp2_hd_table_get(inflater, inflater->index);
|
inflater->ent_name = nghttp2_hd_table_get(&inflater->ctx,
|
||||||
|
inflater->index);
|
||||||
inflater->state = NGHTTP2_HD_STATE_CHECK_VALUELEN;
|
inflater->state = NGHTTP2_HD_STATE_CHECK_VALUELEN;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1508,7 +1507,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
||||||
rv = 0;
|
rv = 0;
|
||||||
if(inflater->huffman_encoded) {
|
if(inflater->huffman_encoded) {
|
||||||
nghttp2_hd_huff_decode_context_init(&inflater->huff_decode_ctx,
|
nghttp2_hd_huff_decode_context_init(&inflater->huff_decode_ctx,
|
||||||
inflater->side);
|
inflater->ctx.side);
|
||||||
rv = nghttp2_buffer_reserve(&inflater->namebuf,
|
rv = nghttp2_buffer_reserve(&inflater->namebuf,
|
||||||
guess_huff_decode_len(inflater->left));
|
guess_huff_decode_len(inflater->left));
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
|
@ -1583,7 +1582,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
||||||
}
|
}
|
||||||
if(inflater->huffman_encoded) {
|
if(inflater->huffman_encoded) {
|
||||||
nghttp2_hd_huff_decode_context_init(&inflater->huff_decode_ctx,
|
nghttp2_hd_huff_decode_context_init(&inflater->huff_decode_ctx,
|
||||||
inflater->side);
|
inflater->ctx.side);
|
||||||
rv = nghttp2_buffer_reserve(&inflater->valuebuf,
|
rv = nghttp2_buffer_reserve(&inflater->valuebuf,
|
||||||
guess_huff_decode_len(inflater->left));
|
guess_huff_decode_len(inflater->left));
|
||||||
inflater->state = NGHTTP2_HD_STATE_READ_VALUEHUFF;
|
inflater->state = NGHTTP2_HD_STATE_READ_VALUEHUFF;
|
||||||
|
@ -1645,15 +1644,15 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
||||||
}
|
}
|
||||||
assert(in == last);
|
assert(in == last);
|
||||||
if(in_final) {
|
if(in_final) {
|
||||||
for(; inflater->end_headers_index < inflater->hd_table.len;
|
for(; inflater->end_headers_index < inflater->ctx.hd_table.len;
|
||||||
++inflater->end_headers_index) {
|
++inflater->end_headers_index) {
|
||||||
nghttp2_hd_entry *ent;
|
nghttp2_hd_entry *ent;
|
||||||
ent = nghttp2_hd_ringbuf_get(&inflater->hd_table,
|
ent = nghttp2_hd_ringbuf_get(&inflater->ctx.hd_table,
|
||||||
inflater->end_headers_index);
|
inflater->end_headers_index);
|
||||||
|
|
||||||
if((ent->flags & NGHTTP2_HD_FLAG_REFSET) &&
|
if((ent->flags & NGHTTP2_HD_FLAG_REFSET) &&
|
||||||
(ent->flags & NGHTTP2_HD_FLAG_EMIT) == 0) {
|
(ent->flags & NGHTTP2_HD_FLAG_EMIT) == 0) {
|
||||||
emit_indexed_header(inflater, nv_out, ent);
|
emit_indexed_header(nv_out, ent);
|
||||||
*inflate_flags |= NGHTTP2_HD_INFLATE_EMIT;
|
*inflate_flags |= NGHTTP2_HD_INFLATE_EMIT;
|
||||||
return in - first;
|
return in - first;
|
||||||
}
|
}
|
||||||
|
@ -1663,11 +1662,11 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
||||||
}
|
}
|
||||||
return in - first;
|
return in - first;
|
||||||
fail:
|
fail:
|
||||||
inflater->bad = 1;
|
inflater->ctx.bad = 1;
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nghttp2_hd_inflate_end_headers(nghttp2_hd_context *inflater)
|
int nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater)
|
||||||
{
|
{
|
||||||
hd_inflate_keep_free(inflater);
|
hd_inflate_keep_free(inflater);
|
||||||
inflater->end_headers_index = 0;
|
inflater->end_headers_index = 0;
|
||||||
|
|
|
@ -119,17 +119,6 @@ typedef enum {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* dynamic header table */
|
/* dynamic header table */
|
||||||
nghttp2_hd_ringbuf hd_table;
|
nghttp2_hd_ringbuf hd_table;
|
||||||
/* Pointer to the nghttp2_hd_entry which is used current header
|
|
||||||
emission. This is required because in some cases the
|
|
||||||
ent_keep->ref == 0 and we have to keep track of it. */
|
|
||||||
nghttp2_hd_entry *ent_keep;
|
|
||||||
/* Pointers to the name/value pair which are used current header
|
|
||||||
emission. They are usually used to keep track of malloc'ed memory
|
|
||||||
for huffman decoding. */
|
|
||||||
uint8_t *name_keep, *value_keep;
|
|
||||||
/* The index of header table to toggle off the entry from reference
|
|
||||||
set at the end of decompression. */
|
|
||||||
size_t end_headers_index;
|
|
||||||
/* Abstract buffer size of hd_table as described in the spec. This
|
/* Abstract buffer size of hd_table as described in the spec. This
|
||||||
is the sum of length of name/value in hd_table +
|
is the sum of length of name/value in hd_table +
|
||||||
NGHTTP2_HD_ENTRY_OVERHEAD bytes overhead per each entry. */
|
NGHTTP2_HD_ENTRY_OVERHEAD bytes overhead per each entry. */
|
||||||
|
@ -162,21 +151,48 @@ typedef struct {
|
||||||
further invocation of inflate/deflate will fail with
|
further invocation of inflate/deflate will fail with
|
||||||
NGHTTP2_ERR_HEADER_COMP. */
|
NGHTTP2_ERR_HEADER_COMP. */
|
||||||
uint8_t bad;
|
uint8_t bad;
|
||||||
|
} nghttp2_hd_context;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
nghttp2_hd_context ctx;
|
||||||
/* Set to this nonzero to clear reference set on each deflation each
|
/* Set to this nonzero to clear reference set on each deflation each
|
||||||
time. */
|
time. */
|
||||||
uint8_t no_refset;
|
uint8_t no_refset;
|
||||||
/* Decoder specific members */
|
} nghttp2_hd_deflater;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
nghttp2_hd_context ctx;
|
||||||
|
/* header name buffer */
|
||||||
nghttp2_buffer namebuf;
|
nghttp2_buffer namebuf;
|
||||||
|
/* header value buffer */
|
||||||
nghttp2_buffer valuebuf;
|
nghttp2_buffer valuebuf;
|
||||||
|
/* Stores current state of huffman decoding */
|
||||||
nghttp2_hd_huff_decode_context huff_decode_ctx;
|
nghttp2_hd_huff_decode_context huff_decode_ctx;
|
||||||
int state;
|
/* Pointer to the nghttp2_hd_entry which is used current header
|
||||||
nghttp2_hd_opcode opcode;
|
emission. This is required because in some cases the
|
||||||
uint8_t huffman_encoded;
|
ent_keep->ref == 0 and we have to keep track of it. */
|
||||||
uint8_t index_required;
|
nghttp2_hd_entry *ent_keep;
|
||||||
ssize_t left;
|
/* Pointers to the name/value pair which are used current header
|
||||||
size_t index;
|
emission. They are usually used to keep track of malloc'ed memory
|
||||||
|
for huffman decoding. */
|
||||||
|
uint8_t *name_keep, *value_keep;
|
||||||
|
/* Pointers to the name/value pair which is referred as indexed
|
||||||
|
name. This entry must be in header table. */
|
||||||
nghttp2_hd_entry *ent_name;
|
nghttp2_hd_entry *ent_name;
|
||||||
} nghttp2_hd_context;
|
/* The number of bytes to read */
|
||||||
|
ssize_t left;
|
||||||
|
/* The index in indexed repr or indexed name */
|
||||||
|
size_t index;
|
||||||
|
/* The index of header table to toggle off the entry from reference
|
||||||
|
set at the end of decompression. */
|
||||||
|
size_t end_headers_index;
|
||||||
|
nghttp2_hd_opcode opcode;
|
||||||
|
nghttp2_hd_inflate_state state;
|
||||||
|
/* nonzero if string is huffman encoded */
|
||||||
|
uint8_t huffman_encoded;
|
||||||
|
/* nonzero if deflater requires that current entry is indexed */
|
||||||
|
uint8_t index_required;
|
||||||
|
} nghttp2_hd_inflater;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes the |ent| members. If NGHTTP2_HD_FLAG_NAME_ALLOC bit
|
* Initializes the |ent| members. If NGHTTP2_HD_FLAG_NAME_ALLOC bit
|
||||||
|
@ -211,7 +227,7 @@ void nghttp2_hd_entry_free(nghttp2_hd_entry *ent);
|
||||||
* NGHTTP2_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int nghttp2_hd_deflate_init(nghttp2_hd_context *deflater,
|
int nghttp2_hd_deflate_init(nghttp2_hd_deflater *deflater,
|
||||||
nghttp2_hd_side side);
|
nghttp2_hd_side side);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -227,7 +243,7 @@ int nghttp2_hd_deflate_init(nghttp2_hd_context *deflater,
|
||||||
* NGHTTP2_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int nghttp2_hd_deflate_init2(nghttp2_hd_context *deflater,
|
int nghttp2_hd_deflate_init2(nghttp2_hd_deflater *deflater,
|
||||||
nghttp2_hd_side side,
|
nghttp2_hd_side side,
|
||||||
size_t deflate_hd_table_bufsize_max);
|
size_t deflate_hd_table_bufsize_max);
|
||||||
|
|
||||||
|
@ -240,18 +256,18 @@ int nghttp2_hd_deflate_init2(nghttp2_hd_context *deflater,
|
||||||
* NGHTTP2_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int nghttp2_hd_inflate_init(nghttp2_hd_context *inflater,
|
int nghttp2_hd_inflate_init(nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_hd_side side);
|
nghttp2_hd_side side);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deallocates any resources allocated for |deflater|.
|
* Deallocates any resources allocated for |deflater|.
|
||||||
*/
|
*/
|
||||||
void nghttp2_hd_deflate_free(nghttp2_hd_context *deflater);
|
void nghttp2_hd_deflate_free(nghttp2_hd_deflater *deflater);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deallocates any resources allocated for |inflater|.
|
* Deallocates any resources allocated for |inflater|.
|
||||||
*/
|
*/
|
||||||
void nghttp2_hd_inflate_free(nghttp2_hd_context *inflater);
|
void nghttp2_hd_inflate_free(nghttp2_hd_inflater *inflater);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sets the availability of reference set in the |deflater|. If
|
* Sets the availability of reference set in the |deflater|. If
|
||||||
|
@ -259,7 +275,7 @@ void nghttp2_hd_inflate_free(nghttp2_hd_context *inflater);
|
||||||
* each invocation of nghttp2_hd_deflate_hd() to clear up reference
|
* each invocation of nghttp2_hd_deflate_hd() to clear up reference
|
||||||
* set. By default, the deflater uses reference set.
|
* set. By default, the deflater uses reference set.
|
||||||
*/
|
*/
|
||||||
void nghttp2_hd_deflate_set_no_refset(nghttp2_hd_context *deflater,
|
void nghttp2_hd_deflate_set_no_refset(nghttp2_hd_deflater *deflater,
|
||||||
uint8_t no_refset);
|
uint8_t no_refset);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -302,7 +318,7 @@ int nghttp2_hd_change_table_size(nghttp2_hd_context *context,
|
||||||
* NGHTTP2_ERR_HEADER_COMP
|
* NGHTTP2_ERR_HEADER_COMP
|
||||||
* Deflation process has failed.
|
* Deflation process has failed.
|
||||||
*/
|
*/
|
||||||
ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_context *deflater,
|
ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,
|
||||||
uint8_t **buf_ptr, size_t *buflen_ptr,
|
uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
size_t nv_offset,
|
size_t nv_offset,
|
||||||
nghttp2_nv *nva, size_t nvlen);
|
nghttp2_nv *nva, size_t nvlen);
|
||||||
|
@ -344,7 +360,7 @@ typedef enum {
|
||||||
* NGHTTP2_ERR_HEADER_COMP
|
* NGHTTP2_ERR_HEADER_COMP
|
||||||
* Inflation process has failed.
|
* Inflation process has failed.
|
||||||
*/
|
*/
|
||||||
ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_nv *nv_out, int *inflate_flags,
|
nghttp2_nv *nv_out, int *inflate_flags,
|
||||||
uint8_t *in, size_t inlen, int in_final);
|
uint8_t *in, size_t inlen, int in_final);
|
||||||
|
|
||||||
|
@ -354,7 +370,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
||||||
* This function returns 0 if it succeeds. Currently this function
|
* This function returns 0 if it succeeds. Currently this function
|
||||||
* always succeeds.
|
* always succeeds.
|
||||||
*/
|
*/
|
||||||
int nghttp2_hd_inflate_end_headers(nghttp2_hd_context *inflater);
|
int nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater);
|
||||||
|
|
||||||
/* For unittesting purpose */
|
/* For unittesting purpose */
|
||||||
int nghttp2_hd_emit_indname_block(uint8_t **buf_ptr, size_t *buflen_ptr,
|
int nghttp2_hd_emit_indname_block(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
|
|
|
@ -2673,7 +2673,7 @@ int nghttp2_session_update_local_settings(nghttp2_session *session,
|
||||||
header_table_size > NGHTTP2_MAX_HEADER_TABLE_SIZE) {
|
header_table_size > NGHTTP2_MAX_HEADER_TABLE_SIZE) {
|
||||||
return NGHTTP2_ERR_HEADER_COMP;
|
return NGHTTP2_ERR_HEADER_COMP;
|
||||||
}
|
}
|
||||||
rv = nghttp2_hd_change_table_size(&session->hd_inflater,
|
rv = nghttp2_hd_change_table_size(&session->hd_inflater.ctx,
|
||||||
header_table_size);
|
header_table_size);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -2760,7 +2760,8 @@ int nghttp2_session_on_settings_received(nghttp2_session *session,
|
||||||
return nghttp2_session_handle_invalid_connection
|
return nghttp2_session_handle_invalid_connection
|
||||||
(session, frame, NGHTTP2_COMPRESSION_ERROR);
|
(session, frame, NGHTTP2_COMPRESSION_ERROR);
|
||||||
}
|
}
|
||||||
rv = nghttp2_hd_change_table_size(&session->hd_deflater, entry->value);
|
rv = nghttp2_hd_change_table_size(&session->hd_deflater.ctx,
|
||||||
|
entry->value);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
if(nghttp2_is_fatal(rv)) {
|
if(nghttp2_is_fatal(rv)) {
|
||||||
return rv;
|
return rv;
|
||||||
|
|
|
@ -123,8 +123,8 @@ struct nghttp2_session {
|
||||||
nghttp2_pq /* <nghttp2_outbound_item*> */ ob_ss_pq;
|
nghttp2_pq /* <nghttp2_outbound_item*> */ ob_ss_pq;
|
||||||
nghttp2_active_outbound_item aob;
|
nghttp2_active_outbound_item aob;
|
||||||
nghttp2_inbound_frame iframe;
|
nghttp2_inbound_frame iframe;
|
||||||
nghttp2_hd_context hd_deflater;
|
nghttp2_hd_deflater hd_deflater;
|
||||||
nghttp2_hd_context hd_inflater;
|
nghttp2_hd_inflater hd_inflater;
|
||||||
nghttp2_session_callbacks callbacks;
|
nghttp2_session_callbacks callbacks;
|
||||||
/* Sequence number of outbound frame to maintain the order of
|
/* Sequence number of outbound frame to maintain the order of
|
||||||
enqueue if priority is equal. */
|
enqueue if priority is equal. */
|
||||||
|
|
|
@ -52,6 +52,10 @@ cdef extern from 'nghttp2_hd.h':
|
||||||
ctypedef enum nghttp2_hd_flags:
|
ctypedef enum nghttp2_hd_flags:
|
||||||
NGHTTP2_HD_FLAG_REFSET
|
NGHTTP2_HD_FLAG_REFSET
|
||||||
|
|
||||||
|
ctypedef enum nghttp2_hd_inflate_flag:
|
||||||
|
NGHTTP2_HD_INFLATE_EMIT
|
||||||
|
NGHTTP2_HD_INFLATE_FINAL
|
||||||
|
|
||||||
ctypedef struct nghttp2_hd_entry:
|
ctypedef struct nghttp2_hd_entry:
|
||||||
nghttp2_nv nv
|
nghttp2_nv nv
|
||||||
uint8_t flags
|
uint8_t flags
|
||||||
|
@ -62,34 +66,40 @@ cdef extern from 'nghttp2_hd.h':
|
||||||
ctypedef struct nghttp2_hd_context:
|
ctypedef struct nghttp2_hd_context:
|
||||||
nghttp2_hd_ringbuf hd_table
|
nghttp2_hd_ringbuf hd_table
|
||||||
|
|
||||||
int nghttp2_hd_deflate_init2(nghttp2_hd_context *deflater,
|
ctypedef struct nghttp2_hd_deflater:
|
||||||
|
nghttp2_hd_context ctx
|
||||||
|
|
||||||
|
ctypedef struct nghttp2_hd_inflater:
|
||||||
|
nghttp2_hd_context ctx
|
||||||
|
|
||||||
|
int nghttp2_hd_deflate_init2(nghttp2_hd_deflater *deflater,
|
||||||
nghttp2_hd_side side,
|
nghttp2_hd_side side,
|
||||||
size_t deflate_hd_table_bufsize_max)
|
size_t deflate_hd_table_bufsize_max)
|
||||||
|
|
||||||
int nghttp2_hd_inflate_init(nghttp2_hd_context *inflater,
|
int nghttp2_hd_inflate_init(nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_hd_side side)
|
nghttp2_hd_side side)
|
||||||
|
|
||||||
|
|
||||||
void nghttp2_hd_deflate_free(nghttp2_hd_context *deflater)
|
void nghttp2_hd_deflate_free(nghttp2_hd_deflater *deflater)
|
||||||
|
|
||||||
void nghttp2_hd_inflate_free(nghttp2_hd_context *inflater)
|
void nghttp2_hd_inflate_free(nghttp2_hd_inflater *inflater)
|
||||||
|
|
||||||
void nghttp2_hd_deflate_set_no_refset(nghttp2_hd_context *deflater,
|
void nghttp2_hd_deflate_set_no_refset(nghttp2_hd_deflater *deflater,
|
||||||
uint8_t no_refset)
|
uint8_t no_refset)
|
||||||
|
|
||||||
int nghttp2_hd_change_table_size(nghttp2_hd_context *context,
|
int nghttp2_hd_change_table_size(nghttp2_hd_context *context,
|
||||||
size_t hd_table_bufsize_max)
|
size_t hd_table_bufsize_max)
|
||||||
|
|
||||||
ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_context *deflater,
|
ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,
|
||||||
uint8_t **buf_ptr, size_t *buflen_ptr,
|
uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
size_t nv_offset,
|
size_t nv_offset,
|
||||||
nghttp2_nv *nva, size_t nvlen)
|
nghttp2_nv *nva, size_t nvlen)
|
||||||
|
|
||||||
ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_context *inflater,
|
ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_nv *nv_out, int *final,
|
nghttp2_nv *nv_out, int *inflate_flags,
|
||||||
uint8_t *input, size_t inlen)
|
uint8_t *input, size_t inlen, int in_final)
|
||||||
|
|
||||||
int nghttp2_hd_inflate_end_headers(nghttp2_hd_context *inflater)
|
int nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater)
|
||||||
|
|
||||||
nghttp2_hd_entry* nghttp2_hd_table_get(nghttp2_hd_context *context,
|
nghttp2_hd_entry* nghttp2_hd_table_get(nghttp2_hd_context *context,
|
||||||
size_t index)
|
size_t index)
|
||||||
|
|
|
@ -45,38 +45,24 @@ class HDTableEntry:
|
||||||
def space(self):
|
def space(self):
|
||||||
return self.namelen + self.valuelen + HD_ENTRY_OVERHEAD
|
return self.namelen + self.valuelen + HD_ENTRY_OVERHEAD
|
||||||
|
|
||||||
cdef class _HDContextBase:
|
cdef _change_table_size(cnghttp2.nghttp2_hd_context *ctx, hd_table_bufsize_max):
|
||||||
|
cdef int rv
|
||||||
|
rv = cnghttp2.nghttp2_hd_change_table_size(ctx, hd_table_bufsize_max)
|
||||||
|
if rv != 0:
|
||||||
|
raise Exception(_strerror(rv))
|
||||||
|
|
||||||
cdef cnghttp2.nghttp2_hd_context _ctx
|
cdef _get_hd_table(cnghttp2.nghttp2_hd_context *ctx):
|
||||||
|
cdef int length = ctx.hd_table.len
|
||||||
def __init__(self):
|
cdef cnghttp2.nghttp2_hd_entry *entry
|
||||||
pass
|
res = []
|
||||||
|
for i in range(length):
|
||||||
def change_table_size(self, hd_table_bufsize_max):
|
entry = cnghttp2.nghttp2_hd_table_get(ctx, i)
|
||||||
'''Changes header table size to |hd_table_bufsize_max| byte.
|
k = _get_pybytes(entry.nv.name, entry.nv.namelen)
|
||||||
|
v = _get_pybytes(entry.nv.value, entry.nv.valuelen)
|
||||||
An exception will be raised on error.
|
res.append(HDTableEntry(k, entry.nv.namelen,
|
||||||
|
v, entry.nv.valuelen,
|
||||||
'''
|
(entry.flags & cnghttp2.NGHTTP2_HD_FLAG_REFSET) != 0))
|
||||||
cdef int rv
|
return res
|
||||||
rv = cnghttp2.nghttp2_hd_change_table_size(&self._ctx,
|
|
||||||
hd_table_bufsize_max)
|
|
||||||
if rv != 0:
|
|
||||||
raise Exception(_strerror(rv))
|
|
||||||
|
|
||||||
def get_hd_table(self):
|
|
||||||
'''Returns copy of current dynamic header table.'''
|
|
||||||
cdef int length = self._ctx.hd_table.len
|
|
||||||
cdef cnghttp2.nghttp2_hd_entry *entry
|
|
||||||
res = []
|
|
||||||
for i in range(length):
|
|
||||||
entry = cnghttp2.nghttp2_hd_table_get(&self._ctx, i)
|
|
||||||
k = _get_pybytes(entry.nv.name, entry.nv.namelen)
|
|
||||||
v = _get_pybytes(entry.nv.value, entry.nv.valuelen)
|
|
||||||
res.append(HDTableEntry(k, entry.nv.namelen,
|
|
||||||
v, entry.nv.valuelen,
|
|
||||||
(entry.flags & cnghttp2.NGHTTP2_HD_FLAG_REFSET) != 0))
|
|
||||||
return res
|
|
||||||
|
|
||||||
cdef _get_pybytes(uint8_t *b, uint16_t blen):
|
cdef _get_pybytes(uint8_t *b, uint16_t blen):
|
||||||
# While the |blen| is positive, the |b| could be NULL. This is
|
# While the |blen| is positive, the |b| could be NULL. This is
|
||||||
|
@ -88,7 +74,7 @@ cdef _get_pybytes(uint8_t *b, uint16_t blen):
|
||||||
val = b[:blen]
|
val = b[:blen]
|
||||||
return val
|
return val
|
||||||
|
|
||||||
cdef class HDDeflater(_HDContextBase):
|
cdef class HDDeflater:
|
||||||
'''Performs header compression. The header compression algorithm has
|
'''Performs header compression. The header compression algorithm has
|
||||||
to know the header set to be compressed is request headers or
|
to know the header set to be compressed is request headers or
|
||||||
response headers. It is indicated by |side| parameter in the
|
response headers. It is indicated by |side| parameter in the
|
||||||
|
@ -114,9 +100,11 @@ cdef class HDDeflater(_HDContextBase):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
cdef cnghttp2.nghttp2_hd_deflater _deflater
|
||||||
|
|
||||||
def __cinit__(self, side,
|
def __cinit__(self, side,
|
||||||
hd_table_bufsize_max = HD_DEFLATE_HD_TABLE_BUFSIZE_MAX):
|
hd_table_bufsize_max = HD_DEFLATE_HD_TABLE_BUFSIZE_MAX):
|
||||||
rv = cnghttp2.nghttp2_hd_deflate_init2(&self._ctx, side,
|
rv = cnghttp2.nghttp2_hd_deflate_init2(&self._deflater, side,
|
||||||
hd_table_bufsize_max)
|
hd_table_bufsize_max)
|
||||||
if rv != 0:
|
if rv != 0:
|
||||||
raise Exception(_strerror(rv))
|
raise Exception(_strerror(rv))
|
||||||
|
@ -126,7 +114,7 @@ cdef class HDDeflater(_HDContextBase):
|
||||||
super(HDDeflater, self).__init__()
|
super(HDDeflater, self).__init__()
|
||||||
|
|
||||||
def __dealloc__(self):
|
def __dealloc__(self):
|
||||||
cnghttp2.nghttp2_hd_deflate_free(&self._ctx)
|
cnghttp2.nghttp2_hd_deflate_free(&self._deflater)
|
||||||
|
|
||||||
def deflate(self, headers):
|
def deflate(self, headers):
|
||||||
'''Compresses the |headers|. The |headers| must be sequence of tuple
|
'''Compresses the |headers|. The |headers| must be sequence of tuple
|
||||||
|
@ -150,7 +138,7 @@ cdef class HDDeflater(_HDContextBase):
|
||||||
cdef uint8_t *out = NULL
|
cdef uint8_t *out = NULL
|
||||||
cdef size_t outcap = 0
|
cdef size_t outcap = 0
|
||||||
cdef ssize_t rv
|
cdef ssize_t rv
|
||||||
rv = cnghttp2.nghttp2_hd_deflate_hd(&self._ctx, &out, &outcap,
|
rv = cnghttp2.nghttp2_hd_deflate_hd(&self._deflater, &out, &outcap,
|
||||||
0, nva, len(headers))
|
0, nva, len(headers))
|
||||||
free(nva)
|
free(nva)
|
||||||
if rv < 0:
|
if rv < 0:
|
||||||
|
@ -169,9 +157,21 @@ cdef class HDDeflater(_HDContextBase):
|
||||||
reference set.
|
reference set.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
cnghttp2.nghttp2_hd_deflate_set_no_refset(&self._ctx, no_refset)
|
cnghttp2.nghttp2_hd_deflate_set_no_refset(&self._deflater, no_refset)
|
||||||
|
|
||||||
cdef class HDInflater(_HDContextBase):
|
def change_table_size(self, hd_table_bufsize_max):
|
||||||
|
'''Changes header table size to |hd_table_bufsize_max| byte.
|
||||||
|
|
||||||
|
An exception will be raised on error.
|
||||||
|
|
||||||
|
'''
|
||||||
|
_change_table_size(&self._deflater.ctx, hd_table_bufsize_max)
|
||||||
|
|
||||||
|
def get_hd_table(self,):
|
||||||
|
'''Returns copy of current dynamic header table.'''
|
||||||
|
return _get_hd_table(&self._deflater.ctx)
|
||||||
|
|
||||||
|
cdef class HDInflater:
|
||||||
'''Performs header decompression.
|
'''Performs header decompression.
|
||||||
|
|
||||||
The following example shows how to compress request header sets:
|
The following example shows how to compress request header sets:
|
||||||
|
@ -183,8 +183,10 @@ cdef class HDInflater(_HDContextBase):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
cdef cnghttp2.nghttp2_hd_inflater _inflater
|
||||||
|
|
||||||
def __cinit__(self, side):
|
def __cinit__(self, side):
|
||||||
rv = cnghttp2.nghttp2_hd_inflate_init(&self._ctx, side)
|
rv = cnghttp2.nghttp2_hd_inflate_init(&self._inflater, side)
|
||||||
if rv != 0:
|
if rv != 0:
|
||||||
raise Exception(_strerror(rv))
|
raise Exception(_strerror(rv))
|
||||||
|
|
||||||
|
@ -192,7 +194,7 @@ cdef class HDInflater(_HDContextBase):
|
||||||
super(HDInflater, self).__init__()
|
super(HDInflater, self).__init__()
|
||||||
|
|
||||||
def __dealloc__(self):
|
def __dealloc__(self):
|
||||||
cnghttp2.nghttp2_hd_inflate_free(&self._ctx)
|
cnghttp2.nghttp2_hd_inflate_free(&self._inflater)
|
||||||
|
|
||||||
def inflate(self, data):
|
def inflate(self, data):
|
||||||
'''Decompresses the compressed header block |data|. The |data| must be
|
'''Decompresses the compressed header block |data|. The |data| must be
|
||||||
|
@ -200,25 +202,41 @@ cdef class HDInflater(_HDContextBase):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
cdef cnghttp2.nghttp2_nv nv
|
cdef cnghttp2.nghttp2_nv nv
|
||||||
cdef int final
|
cdef int inflate_flags
|
||||||
cdef ssize_t rv
|
cdef ssize_t rv
|
||||||
cdef uint8_t *buf = data
|
cdef uint8_t *buf = data
|
||||||
cdef size_t buflen = len(data)
|
cdef size_t buflen = len(data)
|
||||||
res = []
|
res = []
|
||||||
while True:
|
while True:
|
||||||
rv = cnghttp2.nghttp2_hd_inflate_hd(&self._ctx, &nv, &final,
|
inflate_flags = 0
|
||||||
buf, buflen)
|
rv = cnghttp2.nghttp2_hd_inflate_hd(&self._inflater, &nv,
|
||||||
|
&inflate_flags,
|
||||||
|
buf, buflen, 1)
|
||||||
if rv < 0:
|
if rv < 0:
|
||||||
raise Exception(_strerror(rv))
|
raise Exception(_strerror(rv))
|
||||||
if final:
|
|
||||||
break
|
|
||||||
buf += rv
|
buf += rv
|
||||||
buflen -= rv
|
buflen -= rv
|
||||||
# may throw
|
if inflate_flags & cnghttp2.NGHTTP2_HD_INFLATE_EMIT:
|
||||||
res.append((nv.name[:nv.namelen], nv.value[:nv.valuelen]))
|
# may throw
|
||||||
cnghttp2.nghttp2_hd_inflate_end_headers(&self._ctx)
|
res.append((nv.name[:nv.namelen], nv.value[:nv.valuelen]))
|
||||||
|
if inflate_flags & cnghttp2.NGHTTP2_HD_INFLATE_FINAL:
|
||||||
|
break
|
||||||
|
|
||||||
|
cnghttp2.nghttp2_hd_inflate_end_headers(&self._inflater)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def change_table_size(self, hd_table_bufsize_max):
|
||||||
|
'''Changes header table size to |hd_table_bufsize_max| byte.
|
||||||
|
|
||||||
|
An exception will be raised on error.
|
||||||
|
|
||||||
|
'''
|
||||||
|
_change_table_size(&self._inflater.ctx, hd_table_bufsize_max)
|
||||||
|
|
||||||
|
def get_hd_table(self):
|
||||||
|
'''Returns copy of current dynamic header table.'''
|
||||||
|
return _get_hd_table(&self._inflater.ctx)
|
||||||
|
|
||||||
cdef _strerror(int liberror_code):
|
cdef _strerror(int liberror_code):
|
||||||
return cnghttp2.nghttp2_strerror(liberror_code).decode('utf-8')
|
return cnghttp2.nghttp2_strerror(liberror_code).decode('utf-8')
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ static void to_hex(char *dest, const uint8_t *src, size_t len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void output_to_json(nghttp2_hd_context *deflater,
|
static void output_to_json(nghttp2_hd_deflater *deflater,
|
||||||
const uint8_t *buf, size_t len, size_t inputlen,
|
const uint8_t *buf, size_t len, size_t inputlen,
|
||||||
nghttp2_nv *nva, size_t nvlen,
|
nghttp2_nv *nva, size_t nvlen,
|
||||||
int seq)
|
int seq)
|
||||||
|
@ -99,7 +99,8 @@ static void output_to_json(nghttp2_hd_context *deflater,
|
||||||
json_object_set_new(obj, "header_table_size",
|
json_object_set_new(obj, "header_table_size",
|
||||||
json_integer(config.table_size));
|
json_integer(config.table_size));
|
||||||
if(config.dump_header_table) {
|
if(config.dump_header_table) {
|
||||||
json_object_set_new(obj, "header_table", dump_header_table(deflater));
|
json_object_set_new(obj, "header_table",
|
||||||
|
dump_header_table(&deflater->ctx));
|
||||||
}
|
}
|
||||||
json_dumpf(obj, stdout, JSON_PRESERVE_ORDER | JSON_INDENT(2));
|
json_dumpf(obj, stdout, JSON_PRESERVE_ORDER | JSON_INDENT(2));
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -107,7 +108,7 @@ static void output_to_json(nghttp2_hd_context *deflater,
|
||||||
free(hex);
|
free(hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deflate_hd(nghttp2_hd_context *deflater,
|
static void deflate_hd(nghttp2_hd_deflater *deflater,
|
||||||
nghttp2_nv *nva, size_t nvlen, size_t inputlen, int seq)
|
nghttp2_nv *nva, size_t nvlen, size_t inputlen, int seq)
|
||||||
{
|
{
|
||||||
ssize_t rv;
|
ssize_t rv;
|
||||||
|
@ -124,7 +125,7 @@ static void deflate_hd(nghttp2_hd_context *deflater,
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int deflate_hd_json(json_t *obj, nghttp2_hd_context *deflater, int seq)
|
static int deflate_hd_json(json_t *obj, nghttp2_hd_deflater *deflater, int seq)
|
||||||
{
|
{
|
||||||
json_t *js;
|
json_t *js;
|
||||||
nghttp2_nv nva[128];
|
nghttp2_nv nva[128];
|
||||||
|
@ -173,14 +174,14 @@ static int deflate_hd_json(json_t *obj, nghttp2_hd_context *deflater, int seq)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_deflater(nghttp2_hd_context *deflater, nghttp2_hd_side side)
|
static void init_deflater(nghttp2_hd_deflater *deflater, nghttp2_hd_side side)
|
||||||
{
|
{
|
||||||
nghttp2_hd_deflate_init2(deflater, side, config.deflate_table_size);
|
nghttp2_hd_deflate_init2(deflater, side, config.deflate_table_size);
|
||||||
nghttp2_hd_deflate_set_no_refset(deflater, config.no_refset);
|
nghttp2_hd_deflate_set_no_refset(deflater, config.no_refset);
|
||||||
nghttp2_hd_change_table_size(deflater, config.table_size);
|
nghttp2_hd_change_table_size(&deflater->ctx, config.table_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deinit_deflater(nghttp2_hd_context *deflater)
|
static void deinit_deflater(nghttp2_hd_deflater *deflater)
|
||||||
{
|
{
|
||||||
nghttp2_hd_deflate_free(deflater);
|
nghttp2_hd_deflate_free(deflater);
|
||||||
}
|
}
|
||||||
|
@ -191,7 +192,7 @@ static int perform(void)
|
||||||
json_t *json, *cases;
|
json_t *json, *cases;
|
||||||
json_error_t error;
|
json_error_t error;
|
||||||
size_t len;
|
size_t len;
|
||||||
nghttp2_hd_context deflater;
|
nghttp2_hd_deflater deflater;
|
||||||
nghttp2_hd_side side;
|
nghttp2_hd_side side;
|
||||||
|
|
||||||
json = json_loadf(stdin, 0, &error);
|
json = json_loadf(stdin, 0, &error);
|
||||||
|
@ -242,7 +243,7 @@ static int perform_from_http1text(void)
|
||||||
char line[1 << 14];
|
char line[1 << 14];
|
||||||
nghttp2_nv nva[256];
|
nghttp2_nv nva[256];
|
||||||
int seq = 0;
|
int seq = 0;
|
||||||
nghttp2_hd_context deflater;
|
nghttp2_hd_deflater deflater;
|
||||||
init_deflater(&deflater, config.side);
|
init_deflater(&deflater, config.side);
|
||||||
output_json_header(config.side);
|
output_json_header(config.side);
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
|
|
@ -67,7 +67,7 @@ static void decode_hex(uint8_t *dest, const char *src, size_t len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void to_json(nghttp2_hd_context *inflater,
|
static void to_json(nghttp2_hd_inflater *inflater,
|
||||||
json_t *headers, json_t *wire, int seq)
|
json_t *headers, json_t *wire, int seq)
|
||||||
{
|
{
|
||||||
json_t *obj;
|
json_t *obj;
|
||||||
|
@ -77,16 +77,17 @@ static void to_json(nghttp2_hd_context *inflater,
|
||||||
json_object_set(obj, "wire", wire);
|
json_object_set(obj, "wire", wire);
|
||||||
json_object_set(obj, "headers", headers);
|
json_object_set(obj, "headers", headers);
|
||||||
json_object_set_new(obj, "header_table_size",
|
json_object_set_new(obj, "header_table_size",
|
||||||
json_integer(inflater->hd_table_bufsize_max));
|
json_integer(inflater->ctx.hd_table_bufsize_max));
|
||||||
if(config.dump_header_table) {
|
if(config.dump_header_table) {
|
||||||
json_object_set_new(obj, "header_table", dump_header_table(inflater));
|
json_object_set_new(obj, "header_table",
|
||||||
|
dump_header_table(&inflater->ctx));
|
||||||
}
|
}
|
||||||
json_dumpf(obj, stdout, JSON_INDENT(2) | JSON_PRESERVE_ORDER);
|
json_dumpf(obj, stdout, JSON_INDENT(2) | JSON_PRESERVE_ORDER);
|
||||||
json_decref(obj);
|
json_decref(obj);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int inflate_hd(json_t *obj, nghttp2_hd_context *inflater, int seq)
|
static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq)
|
||||||
{
|
{
|
||||||
json_t *wire, *table_size, *headers;
|
json_t *wire, *table_size, *headers;
|
||||||
size_t inputlen;
|
size_t inputlen;
|
||||||
|
@ -109,7 +110,7 @@ static int inflate_hd(json_t *obj, nghttp2_hd_context *inflater, int seq)
|
||||||
seq);
|
seq);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
rv = nghttp2_hd_change_table_size(inflater,
|
rv = nghttp2_hd_change_table_size(&inflater->ctx,
|
||||||
json_integer_value(table_size));
|
json_integer_value(table_size));
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
@ -157,7 +158,7 @@ static int inflate_hd(json_t *obj, nghttp2_hd_context *inflater, int seq)
|
||||||
|
|
||||||
static int perform(void)
|
static int perform(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
size_t i;
|
size_t i;
|
||||||
json_t *json, *cases;
|
json_t *json, *cases;
|
||||||
json_error_t error;
|
json_error_t error;
|
||||||
|
@ -185,7 +186,7 @@ static int perform(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
nghttp2_hd_inflate_init(&inflater, side);
|
nghttp2_hd_inflate_init(&inflater, side);
|
||||||
nghttp2_hd_change_table_size(&inflater, config.table_size);
|
nghttp2_hd_change_table_size(&inflater.ctx, config.table_size);
|
||||||
|
|
||||||
output_json_header(side);
|
output_json_header(side);
|
||||||
len = json_array_size(cases);
|
len = json_array_size(cases);
|
||||||
|
|
|
@ -69,7 +69,8 @@ static void check_frame_header(uint16_t length, uint8_t type, uint8_t flags,
|
||||||
|
|
||||||
void test_nghttp2_frame_pack_headers()
|
void test_nghttp2_frame_pack_headers()
|
||||||
{
|
{
|
||||||
nghttp2_hd_context deflater, inflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
nghttp2_hd_inflater inflater;
|
||||||
nghttp2_headers frame, oframe;
|
nghttp2_headers frame, oframe;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
|
@ -135,7 +136,7 @@ void test_nghttp2_frame_pack_headers()
|
||||||
|
|
||||||
void test_nghttp2_frame_pack_headers_frame_too_large(void)
|
void test_nghttp2_frame_pack_headers_frame_too_large(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context deflater;
|
nghttp2_hd_deflater deflater;
|
||||||
nghttp2_headers frame;
|
nghttp2_headers frame;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
|
@ -241,7 +242,8 @@ void test_nghttp2_frame_pack_settings()
|
||||||
|
|
||||||
void test_nghttp2_frame_pack_push_promise()
|
void test_nghttp2_frame_pack_push_promise()
|
||||||
{
|
{
|
||||||
nghttp2_hd_context deflater, inflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
nghttp2_hd_inflater inflater;
|
||||||
nghttp2_push_promise frame, oframe;
|
nghttp2_push_promise frame, oframe;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
|
|
|
@ -46,7 +46,8 @@ static void assert_nv_equal(nghttp2_nv *a, nghttp2_nv *b, size_t len)
|
||||||
|
|
||||||
void test_nghttp2_hd_deflate(void)
|
void test_nghttp2_hd_deflate(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context deflater, inflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
nghttp2_hd_inflater inflater;
|
||||||
nghttp2_nv nva1[] = {MAKE_NV(":path", "/my-example/index.html"),
|
nghttp2_nv nva1[] = {MAKE_NV(":path", "/my-example/index.html"),
|
||||||
MAKE_NV(":scheme", "https"),
|
MAKE_NV(":scheme", "https"),
|
||||||
MAKE_NV("hello", "world")};
|
MAKE_NV("hello", "world")};
|
||||||
|
@ -137,7 +138,8 @@ void test_nghttp2_hd_deflate(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_deflate_same_indexed_repr(void)
|
void test_nghttp2_hd_deflate_same_indexed_repr(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context deflater, inflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
nghttp2_hd_inflater inflater;
|
||||||
nghttp2_nv nva1[] = {MAKE_NV("cookie", "alpha"),
|
nghttp2_nv nva1[] = {MAKE_NV("cookie", "alpha"),
|
||||||
MAKE_NV("cookie", "alpha")};
|
MAKE_NV("cookie", "alpha")};
|
||||||
nghttp2_nv nva2[] = {MAKE_NV("cookie", "alpha"),
|
nghttp2_nv nva2[] = {MAKE_NV("cookie", "alpha"),
|
||||||
|
@ -184,7 +186,8 @@ void test_nghttp2_hd_deflate_same_indexed_repr(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_deflate_common_header_eviction(void)
|
void test_nghttp2_hd_deflate_common_header_eviction(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context deflater, inflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
nghttp2_hd_inflater inflater;
|
||||||
nghttp2_nv nva[] = {MAKE_NV("h1", ""),
|
nghttp2_nv nva[] = {MAKE_NV("h1", ""),
|
||||||
MAKE_NV("h2", "")};
|
MAKE_NV("h2", "")};
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
|
@ -234,8 +237,8 @@ void test_nghttp2_hd_deflate_common_header_eviction(void)
|
||||||
|
|
||||||
nva_out_reset(&out);
|
nva_out_reset(&out);
|
||||||
|
|
||||||
CU_ASSERT(1 == deflater.hd_table.len);
|
CU_ASSERT(1 == deflater.ctx.hd_table.len);
|
||||||
CU_ASSERT(1 == inflater.hd_table.len);
|
CU_ASSERT(1 == inflater.ctx.hd_table.len);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
nghttp2_hd_inflate_free(&inflater);
|
nghttp2_hd_inflate_free(&inflater);
|
||||||
|
@ -244,7 +247,8 @@ void test_nghttp2_hd_deflate_common_header_eviction(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_deflate_deflate_buffer(void)
|
void test_nghttp2_hd_deflate_deflate_buffer(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context deflater, inflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
nghttp2_hd_inflater inflater;
|
||||||
size_t i;
|
size_t i;
|
||||||
ssize_t blocklen;
|
ssize_t blocklen;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
|
@ -285,11 +289,11 @@ void test_nghttp2_hd_deflate_deflate_buffer(void)
|
||||||
*
|
*
|
||||||
* name/value of all entries must be NULL.
|
* name/value of all entries must be NULL.
|
||||||
*/
|
*/
|
||||||
CU_ASSERT(2 == deflater.hd_table.len);
|
CU_ASSERT(2 == deflater.ctx.hd_table.len);
|
||||||
CU_ASSERT(0 == deflater.deflate_hd_tablelen);
|
CU_ASSERT(0 == deflater.ctx.deflate_hd_tablelen);
|
||||||
CU_ASSERT(0 == deflater.deflate_hd_table_bufsize);
|
CU_ASSERT(0 == deflater.ctx.deflate_hd_table_bufsize);
|
||||||
for(i = 0; i < 2; ++i) {
|
for(i = 0; i < 2; ++i) {
|
||||||
ent = nghttp2_hd_table_get(&deflater, i);
|
ent = nghttp2_hd_table_get(&deflater.ctx, i);
|
||||||
CU_ASSERT(ent->nv.name == NULL);
|
CU_ASSERT(ent->nv.name == NULL);
|
||||||
CU_ASSERT(ent->nv.value == NULL);
|
CU_ASSERT(ent->nv.value == NULL);
|
||||||
CU_ASSERT(0 == (ent->flags & NGHTTP2_HD_FLAG_REFSET));
|
CU_ASSERT(0 == (ent->flags & NGHTTP2_HD_FLAG_REFSET));
|
||||||
|
@ -317,26 +321,26 @@ void test_nghttp2_hd_deflate_deflate_buffer(void)
|
||||||
* 2: k10, v10
|
* 2: k10, v10
|
||||||
* 3: k1, v1
|
* 3: k1, v1
|
||||||
*/
|
*/
|
||||||
CU_ASSERT(4 == deflater.hd_table.len);
|
CU_ASSERT(4 == deflater.ctx.hd_table.len);
|
||||||
CU_ASSERT(4 == deflater.deflate_hd_tablelen);
|
CU_ASSERT(4 == deflater.ctx.deflate_hd_tablelen);
|
||||||
CU_ASSERT(156 == deflater.deflate_hd_table_bufsize);
|
CU_ASSERT(156 == deflater.ctx.deflate_hd_table_bufsize);
|
||||||
for(i = 0; i < 4; ++i) {
|
for(i = 0; i < 4; ++i) {
|
||||||
CU_ASSERT(nghttp2_hd_table_get(&deflater, i)->nv.name != NULL);
|
CU_ASSERT(nghttp2_hd_table_get(&deflater.ctx, i)->nv.name != NULL);
|
||||||
CU_ASSERT(nghttp2_hd_table_get(&deflater, i)->nv.value != NULL);
|
CU_ASSERT(nghttp2_hd_table_get(&deflater.ctx, i)->nv.value != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
CU_ASSERT(0 == nghttp2_hd_change_table_size(&deflater, 156));
|
CU_ASSERT(0 == nghttp2_hd_change_table_size(&deflater.ctx, 156));
|
||||||
CU_ASSERT(4 == deflater.hd_table.len);
|
CU_ASSERT(4 == deflater.ctx.hd_table.len);
|
||||||
CU_ASSERT(4 == deflater.deflate_hd_tablelen);
|
CU_ASSERT(4 == deflater.ctx.deflate_hd_tablelen);
|
||||||
CU_ASSERT(156 == deflater.deflate_hd_table_bufsize);
|
CU_ASSERT(156 == deflater.ctx.deflate_hd_table_bufsize);
|
||||||
|
|
||||||
blocklen = nghttp2_hd_deflate_hd(&deflater, &buf, &buflen, 0, &nv3, 1);
|
blocklen = nghttp2_hd_deflate_hd(&deflater, &buf, &buflen, 0, &nv3, 1);
|
||||||
CU_ASSERT(blocklen > 0);
|
CU_ASSERT(blocklen > 0);
|
||||||
/* Now header table should be unchanged, because we don't index
|
/* Now header table should be unchanged, because we don't index
|
||||||
large header */
|
large header */
|
||||||
CU_ASSERT(4 == deflater.hd_table.len);
|
CU_ASSERT(4 == deflater.ctx.hd_table.len);
|
||||||
CU_ASSERT(4 == deflater.deflate_hd_tablelen);
|
CU_ASSERT(4 == deflater.ctx.deflate_hd_tablelen);
|
||||||
CU_ASSERT(156 == deflater.deflate_hd_table_bufsize);
|
CU_ASSERT(156 == deflater.ctx.deflate_hd_table_bufsize);
|
||||||
|
|
||||||
nghttp2_hd_deflate_free(&deflater);
|
nghttp2_hd_deflate_free(&deflater);
|
||||||
|
|
||||||
|
@ -356,14 +360,14 @@ void test_nghttp2_hd_deflate_deflate_buffer(void)
|
||||||
* But due to the deflate table size limit, name/value of index=3 must
|
* But due to the deflate table size limit, name/value of index=3 must
|
||||||
* be NULL.
|
* be NULL.
|
||||||
*/
|
*/
|
||||||
CU_ASSERT(4 == deflater.hd_table.len);
|
CU_ASSERT(4 == deflater.ctx.hd_table.len);
|
||||||
CU_ASSERT(3 == deflater.deflate_hd_tablelen);
|
CU_ASSERT(3 == deflater.ctx.deflate_hd_tablelen);
|
||||||
CU_ASSERT(120 == deflater.deflate_hd_table_bufsize);
|
CU_ASSERT(120 == deflater.ctx.deflate_hd_table_bufsize);
|
||||||
for(i = 0; i < 3; ++i) {
|
for(i = 0; i < 3; ++i) {
|
||||||
CU_ASSERT(nghttp2_hd_table_get(&deflater, i)->nv.name != NULL);
|
CU_ASSERT(nghttp2_hd_table_get(&deflater.ctx, i)->nv.name != NULL);
|
||||||
CU_ASSERT(nghttp2_hd_table_get(&deflater, i)->nv.value != NULL);
|
CU_ASSERT(nghttp2_hd_table_get(&deflater.ctx, i)->nv.value != NULL);
|
||||||
}
|
}
|
||||||
ent = nghttp2_hd_table_get(&deflater, 3);
|
ent = nghttp2_hd_table_get(&deflater.ctx, 3);
|
||||||
CU_ASSERT(ent->nv.name == NULL);
|
CU_ASSERT(ent->nv.name == NULL);
|
||||||
CU_ASSERT(ent->nv.value == NULL);
|
CU_ASSERT(ent->nv.value == NULL);
|
||||||
CU_ASSERT(0 == (ent->flags & NGHTTP2_HD_FLAG_REFSET));
|
CU_ASSERT(0 == (ent->flags & NGHTTP2_HD_FLAG_REFSET));
|
||||||
|
@ -386,12 +390,12 @@ void test_nghttp2_hd_deflate_deflate_buffer(void)
|
||||||
* 3: k10, v10 (-) <- name, value must be NULL
|
* 3: k10, v10 (-) <- name, value must be NULL
|
||||||
* 4: k1, v1 (-) <- name, value must be NULL
|
* 4: k1, v1 (-) <- name, value must be NULL
|
||||||
*/
|
*/
|
||||||
CU_ASSERT(5 == deflater.hd_table.len);
|
CU_ASSERT(5 == deflater.ctx.hd_table.len);
|
||||||
CU_ASSERT(3 == deflater.deflate_hd_tablelen);
|
CU_ASSERT(3 == deflater.ctx.deflate_hd_tablelen);
|
||||||
CU_ASSERT(118 == deflater.deflate_hd_table_bufsize);
|
CU_ASSERT(118 == deflater.ctx.deflate_hd_table_bufsize);
|
||||||
ent = nghttp2_hd_table_get(&deflater, 3);
|
ent = nghttp2_hd_table_get(&deflater.ctx, 3);
|
||||||
CU_ASSERT(0 == (ent->flags & NGHTTP2_HD_FLAG_REFSET));
|
CU_ASSERT(0 == (ent->flags & NGHTTP2_HD_FLAG_REFSET));
|
||||||
ent = nghttp2_hd_table_get(&deflater, 3);
|
ent = nghttp2_hd_table_get(&deflater.ctx, 3);
|
||||||
CU_ASSERT(0 == (ent->flags & NGHTTP2_HD_FLAG_REFSET));
|
CU_ASSERT(0 == (ent->flags & NGHTTP2_HD_FLAG_REFSET));
|
||||||
|
|
||||||
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, buf, blocklen));
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, buf, blocklen));
|
||||||
|
@ -411,7 +415,8 @@ void test_nghttp2_hd_deflate_deflate_buffer(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_deflate_clear_refset(void)
|
void test_nghttp2_hd_deflate_clear_refset(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context deflater, inflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
nghttp2_hd_inflater inflater;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
ssize_t blocklen;
|
ssize_t blocklen;
|
||||||
|
@ -447,7 +452,7 @@ void test_nghttp2_hd_deflate_clear_refset(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_inflate_indname_noinc(void)
|
void test_nghttp2_hd_inflate_indname_noinc(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
@ -473,7 +478,7 @@ void test_nghttp2_hd_inflate_indname_noinc(void)
|
||||||
|
|
||||||
CU_ASSERT(1 == out.nvlen);
|
CU_ASSERT(1 == out.nvlen);
|
||||||
assert_nv_equal(&nv[i], out.nva, 1);
|
assert_nv_equal(&nv[i], out.nva, 1);
|
||||||
CU_ASSERT(0 == inflater.hd_table.len);
|
CU_ASSERT(0 == inflater.ctx.hd_table.len);
|
||||||
|
|
||||||
nva_out_reset(&out);
|
nva_out_reset(&out);
|
||||||
}
|
}
|
||||||
|
@ -484,7 +489,7 @@ void test_nghttp2_hd_inflate_indname_noinc(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_inflate_indname_inc(void)
|
void test_nghttp2_hd_inflate_indname_inc(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
@ -501,9 +506,10 @@ void test_nghttp2_hd_inflate_indname_inc(void)
|
||||||
|
|
||||||
CU_ASSERT(1 == out.nvlen);
|
CU_ASSERT(1 == out.nvlen);
|
||||||
assert_nv_equal(&nv, out.nva, 1);
|
assert_nv_equal(&nv, out.nva, 1);
|
||||||
CU_ASSERT(1 == inflater.hd_table.len);
|
CU_ASSERT(1 == inflater.ctx.hd_table.len);
|
||||||
assert_nv_equal(&nv,
|
assert_nv_equal(&nv,
|
||||||
&GET_TABLE_ENT(&inflater, inflater.hd_table.len-1)->nv, 1);
|
&GET_TABLE_ENT(&inflater.ctx,
|
||||||
|
inflater.ctx.hd_table.len-1)->nv, 1);
|
||||||
|
|
||||||
nva_out_reset(&out);
|
nva_out_reset(&out);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@ -512,7 +518,7 @@ void test_nghttp2_hd_inflate_indname_inc(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_inflate_indname_inc_eviction(void)
|
void test_nghttp2_hd_inflate_indname_inc_eviction(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
@ -545,8 +551,8 @@ void test_nghttp2_hd_inflate_indname_inc_eviction(void)
|
||||||
|
|
||||||
nva_out_reset(&out);
|
nva_out_reset(&out);
|
||||||
|
|
||||||
CU_ASSERT(3 == inflater.hd_table.len);
|
CU_ASSERT(3 == inflater.ctx.hd_table.len);
|
||||||
CU_ASSERT(GET_TABLE_ENT(&inflater, 0)->flags & NGHTTP2_HD_FLAG_REFSET);
|
CU_ASSERT(GET_TABLE_ENT(&inflater.ctx, 0)->flags & NGHTTP2_HD_FLAG_REFSET);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
nghttp2_hd_inflate_free(&inflater);
|
nghttp2_hd_inflate_free(&inflater);
|
||||||
|
@ -554,7 +560,7 @@ void test_nghttp2_hd_inflate_indname_inc_eviction(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_inflate_newname_noinc(void)
|
void test_nghttp2_hd_inflate_newname_noinc(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
@ -582,7 +588,7 @@ void test_nghttp2_hd_inflate_newname_noinc(void)
|
||||||
|
|
||||||
CU_ASSERT(1 == out.nvlen);
|
CU_ASSERT(1 == out.nvlen);
|
||||||
assert_nv_equal(&nv[i], out.nva, 1);
|
assert_nv_equal(&nv[i], out.nva, 1);
|
||||||
CU_ASSERT(0 == inflater.hd_table.len);
|
CU_ASSERT(0 == inflater.ctx.hd_table.len);
|
||||||
|
|
||||||
nva_out_reset(&out);
|
nva_out_reset(&out);
|
||||||
}
|
}
|
||||||
|
@ -593,7 +599,7 @@ void test_nghttp2_hd_inflate_newname_noinc(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_inflate_newname_inc(void)
|
void test_nghttp2_hd_inflate_newname_inc(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
@ -610,9 +616,10 @@ void test_nghttp2_hd_inflate_newname_inc(void)
|
||||||
|
|
||||||
CU_ASSERT(1 == out.nvlen);
|
CU_ASSERT(1 == out.nvlen);
|
||||||
assert_nv_equal(&nv, out.nva, 1);
|
assert_nv_equal(&nv, out.nva, 1);
|
||||||
CU_ASSERT(1 == inflater.hd_table.len);
|
CU_ASSERT(1 == inflater.ctx.hd_table.len);
|
||||||
assert_nv_equal(&nv,
|
assert_nv_equal(&nv,
|
||||||
&GET_TABLE_ENT(&inflater, inflater.hd_table.len-1)->nv, 1);
|
&GET_TABLE_ENT(&inflater.ctx,
|
||||||
|
inflater.ctx.hd_table.len-1)->nv, 1);
|
||||||
|
|
||||||
nva_out_reset(&out);
|
nva_out_reset(&out);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@ -621,7 +628,7 @@ void test_nghttp2_hd_inflate_newname_inc(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_inflate_clearall_inc(void)
|
void test_nghttp2_hd_inflate_clearall_inc(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
@ -646,7 +653,7 @@ void test_nghttp2_hd_inflate_clearall_inc(void)
|
||||||
|
|
||||||
CU_ASSERT(1 == out.nvlen);
|
CU_ASSERT(1 == out.nvlen);
|
||||||
assert_nv_equal(&nv, out.nva, 1);
|
assert_nv_equal(&nv, out.nva, 1);
|
||||||
CU_ASSERT(0 == inflater.hd_table.len);
|
CU_ASSERT(0 == inflater.ctx.hd_table.len);
|
||||||
|
|
||||||
nva_out_reset(&out);
|
nva_out_reset(&out);
|
||||||
|
|
||||||
|
@ -655,7 +662,7 @@ void test_nghttp2_hd_inflate_clearall_inc(void)
|
||||||
|
|
||||||
CU_ASSERT(1 == out.nvlen);
|
CU_ASSERT(1 == out.nvlen);
|
||||||
assert_nv_equal(&nv, out.nva, 1);
|
assert_nv_equal(&nv, out.nva, 1);
|
||||||
CU_ASSERT(0 == inflater.hd_table.len);
|
CU_ASSERT(0 == inflater.ctx.hd_table.len);
|
||||||
|
|
||||||
nva_out_reset(&out);
|
nva_out_reset(&out);
|
||||||
|
|
||||||
|
@ -671,7 +678,7 @@ void test_nghttp2_hd_inflate_clearall_inc(void)
|
||||||
|
|
||||||
CU_ASSERT(1 == out.nvlen);
|
CU_ASSERT(1 == out.nvlen);
|
||||||
assert_nv_equal(&nv, out.nva, 1);
|
assert_nv_equal(&nv, out.nva, 1);
|
||||||
CU_ASSERT(1 == inflater.hd_table.len);
|
CU_ASSERT(1 == inflater.ctx.hd_table.len);
|
||||||
|
|
||||||
nva_out_reset(&out);
|
nva_out_reset(&out);
|
||||||
|
|
||||||
|
@ -681,7 +688,7 @@ void test_nghttp2_hd_inflate_clearall_inc(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_inflate_zero_length_huffman(void)
|
void test_nghttp2_hd_inflate_zero_length_huffman(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
uint8_t buf[4];
|
uint8_t buf[4];
|
||||||
nva_out out;
|
nva_out out;
|
||||||
|
|
||||||
|
@ -707,7 +714,7 @@ void test_nghttp2_hd_inflate_zero_length_huffman(void)
|
||||||
|
|
||||||
void test_nghttp2_hd_change_table_size(void)
|
void test_nghttp2_hd_change_table_size(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context deflater;
|
nghttp2_hd_deflater deflater;
|
||||||
nghttp2_nv nva[] = { MAKE_NV(":method", "GET"),
|
nghttp2_nv nva[] = { MAKE_NV(":method", "GET"),
|
||||||
MAKE_NV(":path", "/") };
|
MAKE_NV(":path", "/") };
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
|
@ -715,32 +722,33 @@ void test_nghttp2_hd_change_table_size(void)
|
||||||
ssize_t rv;
|
ssize_t rv;
|
||||||
|
|
||||||
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
||||||
CU_ASSERT(0 == nghttp2_hd_change_table_size(&deflater, 8000));
|
CU_ASSERT(0 == nghttp2_hd_change_table_size(&deflater.ctx, 8000));
|
||||||
CU_ASSERT(255 == deflater.hd_table.mask);
|
CU_ASSERT(255 == deflater.ctx.hd_table.mask);
|
||||||
CU_ASSERT(8000 == deflater.hd_table_bufsize_max);
|
CU_ASSERT(8000 == deflater.ctx.hd_table_bufsize_max);
|
||||||
|
|
||||||
rv = nghttp2_hd_deflate_hd(&deflater, &buf, &buflen, 0, nva, 2);
|
rv = nghttp2_hd_deflate_hd(&deflater, &buf, &buflen, 0, nva, 2);
|
||||||
CU_ASSERT(rv > 0);
|
CU_ASSERT(rv > 0);
|
||||||
CU_ASSERT(2 == deflater.hd_table.len);
|
CU_ASSERT(2 == deflater.ctx.hd_table.len);
|
||||||
|
|
||||||
CU_ASSERT(0 == nghttp2_hd_change_table_size(&deflater, 16384));
|
CU_ASSERT(0 == nghttp2_hd_change_table_size(&deflater.ctx, 16384));
|
||||||
CU_ASSERT(511 == deflater.hd_table.mask);
|
CU_ASSERT(511 == deflater.ctx.hd_table.mask);
|
||||||
CU_ASSERT(2 == deflater.hd_table.len);
|
CU_ASSERT(2 == deflater.ctx.hd_table.len);
|
||||||
CU_ASSERT(2 == deflater.deflate_hd_tablelen);
|
CU_ASSERT(2 == deflater.ctx.deflate_hd_tablelen);
|
||||||
CU_ASSERT(5 ==
|
CU_ASSERT(5 ==
|
||||||
deflater.hd_table.buffer[deflater.hd_table.first]->nv.namelen);
|
deflater.ctx.hd_table.buffer[deflater.ctx.hd_table.first]
|
||||||
|
->nv.namelen);
|
||||||
|
|
||||||
CU_ASSERT(0 == nghttp2_hd_change_table_size(&deflater, 0));
|
CU_ASSERT(0 == nghttp2_hd_change_table_size(&deflater.ctx, 0));
|
||||||
CU_ASSERT(511 == deflater.hd_table.mask);
|
CU_ASSERT(511 == deflater.ctx.hd_table.mask);
|
||||||
CU_ASSERT(0 == deflater.hd_table.len);
|
CU_ASSERT(0 == deflater.ctx.hd_table.len);
|
||||||
CU_ASSERT(0 == deflater.deflate_hd_tablelen);
|
CU_ASSERT(0 == deflater.ctx.deflate_hd_tablelen);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
nghttp2_hd_deflate_free(&deflater);
|
nghttp2_hd_deflate_free(&deflater);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_deflate_inflate(nghttp2_hd_context *deflater,
|
static void check_deflate_inflate(nghttp2_hd_deflater *deflater,
|
||||||
nghttp2_hd_context *inflater,
|
nghttp2_hd_inflater *inflater,
|
||||||
nghttp2_nv *nva, size_t nvlen)
|
nghttp2_nv *nva, size_t nvlen)
|
||||||
{
|
{
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
|
@ -763,7 +771,8 @@ static void check_deflate_inflate(nghttp2_hd_context *deflater,
|
||||||
|
|
||||||
void test_nghttp2_hd_deflate_inflate(void)
|
void test_nghttp2_hd_deflate_inflate(void)
|
||||||
{
|
{
|
||||||
nghttp2_hd_context inflater, deflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
nghttp2_hd_inflater inflater;
|
||||||
nghttp2_nv nv1[] = {
|
nghttp2_nv nv1[] = {
|
||||||
MAKE_NV(":status", "200 OK"),
|
MAKE_NV(":status", "200 OK"),
|
||||||
MAKE_NV("access-control-allow-origin", "*"),
|
MAKE_NV("access-control-allow-origin", "*"),
|
||||||
|
|
|
@ -360,7 +360,7 @@ void test_nghttp2_session_recv(void)
|
||||||
nghttp2_outbound_item *item;
|
nghttp2_outbound_item *item;
|
||||||
nghttp2_nv *nva;
|
nghttp2_nv *nva;
|
||||||
ssize_t nvlen;
|
ssize_t nvlen;
|
||||||
nghttp2_hd_context deflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
|
||||||
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
||||||
callbacks.send_callback = null_send_callback;
|
callbacks.send_callback = null_send_callback;
|
||||||
|
@ -441,7 +441,7 @@ void test_nghttp2_session_recv_invalid_stream_id(void)
|
||||||
size_t framedatalen = 0;
|
size_t framedatalen = 0;
|
||||||
ssize_t framelen;
|
ssize_t framelen;
|
||||||
nghttp2_frame frame;
|
nghttp2_frame frame;
|
||||||
nghttp2_hd_context deflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
|
||||||
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
||||||
callbacks.recv_callback = scripted_recv_callback;
|
callbacks.recv_callback = scripted_recv_callback;
|
||||||
|
@ -484,7 +484,7 @@ void test_nghttp2_session_recv_invalid_frame(void)
|
||||||
nghttp2_frame frame;
|
nghttp2_frame frame;
|
||||||
nghttp2_nv *nva;
|
nghttp2_nv *nva;
|
||||||
ssize_t nvlen;
|
ssize_t nvlen;
|
||||||
nghttp2_hd_context deflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
|
||||||
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
||||||
callbacks.recv_callback = scripted_recv_callback;
|
callbacks.recv_callback = scripted_recv_callback;
|
||||||
|
@ -685,7 +685,7 @@ void test_nghttp2_session_continue(void)
|
||||||
ssize_t nvlen;
|
ssize_t nvlen;
|
||||||
const nghttp2_frame *recv_frame;
|
const nghttp2_frame *recv_frame;
|
||||||
nghttp2_frame_hd data_hd;
|
nghttp2_frame_hd data_hd;
|
||||||
nghttp2_hd_context deflater;
|
nghttp2_hd_deflater deflater;
|
||||||
|
|
||||||
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
||||||
callbacks.send_callback = null_send_callback;
|
callbacks.send_callback = null_send_callback;
|
||||||
|
@ -2045,7 +2045,7 @@ void test_nghttp2_submit_request_without_data(void)
|
||||||
nghttp2_outbound_item *item;
|
nghttp2_outbound_item *item;
|
||||||
my_user_data ud;
|
my_user_data ud;
|
||||||
nghttp2_frame frame;
|
nghttp2_frame frame;
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
nva_out out;
|
nva_out out;
|
||||||
|
|
||||||
nva_out_init(&out);
|
nva_out_init(&out);
|
||||||
|
@ -2116,7 +2116,7 @@ void test_nghttp2_submit_response_without_data(void)
|
||||||
nghttp2_outbound_item *item;
|
nghttp2_outbound_item *item;
|
||||||
my_user_data ud;
|
my_user_data ud;
|
||||||
nghttp2_frame frame;
|
nghttp2_frame frame;
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
nva_out out;
|
nva_out out;
|
||||||
|
|
||||||
nva_out_init(&out);
|
nva_out_init(&out);
|
||||||
|
@ -2285,7 +2285,7 @@ void test_nghttp2_submit_headers(void)
|
||||||
nghttp2_stream *stream;
|
nghttp2_stream *stream;
|
||||||
accumulator acc;
|
accumulator acc;
|
||||||
nghttp2_frame frame;
|
nghttp2_frame frame;
|
||||||
nghttp2_hd_context inflater;
|
nghttp2_hd_inflater inflater;
|
||||||
nva_out out;
|
nva_out out;
|
||||||
|
|
||||||
nva_out_init(&out);
|
nva_out_init(&out);
|
||||||
|
@ -2488,7 +2488,7 @@ void test_nghttp2_submit_settings(void)
|
||||||
CU_ASSERT(1 ==
|
CU_ASSERT(1 ==
|
||||||
session->local_settings[NGHTTP2_SETTINGS_FLOW_CONTROL_OPTIONS]);
|
session->local_settings[NGHTTP2_SETTINGS_FLOW_CONTROL_OPTIONS]);
|
||||||
CU_ASSERT(0 == session->local_flow_control);
|
CU_ASSERT(0 == session->local_flow_control);
|
||||||
CU_ASSERT(0 == session->hd_inflater.hd_table_bufsize_max);
|
CU_ASSERT(0 == session->hd_inflater.ctx.hd_table_bufsize_max);
|
||||||
|
|
||||||
nghttp2_session_del(session);
|
nghttp2_session_del(session);
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ void add_out(nva_out *out, nghttp2_nv *nv)
|
||||||
++out->nvlen;
|
++out->nvlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t inflate_hd(nghttp2_hd_context *inflater, nva_out *out,
|
ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out,
|
||||||
uint8_t *buf, size_t buflen)
|
uint8_t *buf, size_t buflen)
|
||||||
{
|
{
|
||||||
ssize_t rv;
|
ssize_t rv;
|
||||||
|
|
|
@ -54,7 +54,7 @@ void nva_out_reset(nva_out *out);
|
||||||
|
|
||||||
void add_out(nva_out *out, nghttp2_nv *nv);
|
void add_out(nva_out *out, nghttp2_nv *nv);
|
||||||
|
|
||||||
ssize_t inflate_hd(nghttp2_hd_context *inflater, nva_out *out,
|
ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out,
|
||||||
uint8_t *buf, size_t buflen);
|
uint8_t *buf, size_t buflen);
|
||||||
|
|
||||||
#endif /* NGHTTP2_TEST_HELPER_H */
|
#endif /* NGHTTP2_TEST_HELPER_H */
|
||||||
|
|
Loading…
Reference in New Issue