Author: rhuijben Date: Sat Oct 31 23:27:54 2015 New Revision: 1711709 URL: http://svn.apache.org/viewvc?rev=1711709&view=rev Log: Stop telling http2 servers that we only have a 0 byte hpack cache table to allow receive more efficiently encoded headers. Fix a few bugs found by running this against live http/2 servers.
* buckets/hpack_buckets.c (read_hpack_int): Allow reading values that exactly fit in the first byte, but thereby need a second 0 byte. (handle_read_entry_and_clear): Properly store length and store incoming items as remote->local instead of the other way around. * protocols/http2_protocol.c (serf__http2_protocol_init): Stop notifying that we have a 0 byte header table size. Modified: serf/trunk/buckets/hpack_buckets.c serf/trunk/protocols/http2_protocol.c Modified: serf/trunk/buckets/hpack_buckets.c URL: http://svn.apache.org/viewvc/serf/trunk/buckets/hpack_buckets.c?rev=1711709&r1=1711708&r2=1711709&view=diff ============================================================================== --- serf/trunk/buckets/hpack_buckets.c (original) +++ serf/trunk/buckets/hpack_buckets.c Sat Oct 31 23:27:54 2015 @@ -1000,8 +1000,12 @@ read_hpack_int(apr_uint64_t *v, } while (ctx->buffer[ctx->buffer_used - 1] & 0x80); - /* Check if the value could have been stored more efficiently */ - if (ctx->buffer[ctx->buffer_used - 1] == 0) + /* Check if the value could have been stored more efficiently. If it + can then this is a compression error. + + The value where all the bits in the first byte are 1 really + needs the next byte as 0, to encode that. */ + if (ctx->buffer_used > 2 && ctx->buffer[ctx->buffer_used - 1] == 0) return SERF_ERROR_HTTP2_COMPRESSION_ERROR; vv = value_mask; @@ -1122,14 +1126,16 @@ handle_read_entry_and_clear(serf_hpack_d entry->key = own_key ? ctx->key : serf_bstrmemdup(tbl->alloc, ctx->key, ctx->key_size); + entry->key_len = ctx->key_size; entry->value = own_val ? ctx->val : serf_bstrmemdup(tbl->alloc, ctx->val, ctx->val_size); + entry->value_len = ctx->val_size; entry->free_key = entry->free_val = TRUE; entry->next = tbl->rl_first; - tbl->lr_first = entry; - tbl->lr_count++; - tbl->lr_size += HPACK_ENTRY_SIZE(entry); + tbl->rl_first = entry; + tbl->rl_count++; + tbl->rl_size += HPACK_ENTRY_SIZE(entry); if (entry->next) entry->next->prev = entry; Modified: serf/trunk/protocols/http2_protocol.c URL: http://svn.apache.org/viewvc/serf/trunk/protocols/http2_protocol.c?rev=1711709&r1=1711708&r2=1711709&view=diff ============================================================================== --- serf/trunk/protocols/http2_protocol.c (original) +++ serf/trunk/protocols/http2_protocol.c Sat Oct 31 23:27:54 2015 @@ -258,10 +258,7 @@ void serf__http2_protocol_init(serf_conn serf_bucket_t *settings; serf_bucket_t *window_size; - settings = serf_bucket_create_numberv(conn->allocator, "24", - (apr_int16_t)HTTP2_SETTING_HEADER_TABLE_SIZE, - (apr_int32_t)0); - tmp = serf__bucket_http2_frame_create(settings, HTTP2_FRAME_TYPE_SETTINGS, 0, + tmp = serf__bucket_http2_frame_create(NULL, HTTP2_FRAME_TYPE_SETTINGS, 0, NULL, NULL, NULL, /* Static id: 0*/ HTTP2_DEFAULT_MAX_FRAMESIZE, NULL, NULL, conn->allocator);