src, python: Only produce header_table_size when it is changed

This commit is contained in:
Tatsuhiro Tsujikawa 2014-02-25 23:55:06 +09:00
parent 7cf574d0d8
commit 13cc3f2fe9
3 changed files with 18 additions and 8 deletions

View File

@ -15,7 +15,7 @@ import nghttp2
def testsuite(testdata, filename, outdir, table_size, deflate_table_size): def testsuite(testdata, filename, outdir, table_size, deflate_table_size):
res = { res = {
'draft':5, 'context': testdata['context'], 'draft':6,
'description': '''\ 'description': '''\
Encoded by nghttp2. The basic encoding strategy is described in \ Encoded by nghttp2. The basic encoding strategy is described in \
http://lists.w3.org/Archives/Public/ietf-http-wg/2013JulSep/1135.html \ http://lists.w3.org/Archives/Public/ietf-http-wg/2013JulSep/1135.html \
@ -28,7 +28,6 @@ result in less bits on the wire.'''
deflater.change_table_size(table_size) deflater.change_table_size(table_size)
for casenum, item in enumerate(testdata['cases']): for casenum, item in enumerate(testdata['cases']):
outitem = { outitem = {
'header_table_size': table_size,
'headers': item['headers'] 'headers': item['headers']
} }
casenum += 1 casenum += 1
@ -37,6 +36,10 @@ result in less bits on the wire.'''
for x in item['headers']] for x in item['headers']]
outitem['wire'] = b2a_hex(deflater.deflate(hdrs)).decode('utf-8') outitem['wire'] = b2a_hex(deflater.deflate(hdrs)).decode('utf-8')
cases.append(outitem) cases.append(outitem)
if cases:
cases[0]['header_table_size'] = table_size
res['cases'] = cases res['cases'] = cases
jsonstr = json.dumps(res, indent=2) jsonstr = json.dumps(res, indent=2)
with open(os.path.join(outdir, filename), 'w') as f: with open(os.path.join(outdir, filename), 'w') as f:

View File

@ -95,8 +95,11 @@ static void output_to_json(nghttp2_hd_deflater *deflater,
json_object_set_new(obj, "wire", json_pack("s#", hex, len * 2)); json_object_set_new(obj, "wire", json_pack("s#", hex, len * 2));
} }
json_object_set_new(obj, "headers", dump_headers(nva, nvlen)); json_object_set_new(obj, "headers", dump_headers(nva, nvlen));
json_object_set_new(obj, "header_table_size", if(seq == 0) {
json_integer(config.table_size)); /* We only change the header table size only once at the beginning */
json_object_set_new(obj, "header_table_size",
json_integer(config.table_size));
}
if(config.dump_header_table) { if(config.dump_header_table) {
json_object_set_new(obj, "header_table", json_object_set_new(obj, "header_table",
dump_header_table(&deflater->ctx)); dump_header_table(&deflater->ctx));

View File

@ -67,7 +67,8 @@ static void decode_hex(uint8_t *dest, const char *src, size_t len)
} }
static void to_json(nghttp2_hd_inflater *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,
size_t old_settings_table_size)
{ {
json_t *obj; json_t *obj;
@ -75,8 +76,10 @@ static void to_json(nghttp2_hd_inflater *inflater,
json_object_set_new(obj, "seq", json_integer(seq)); json_object_set_new(obj, "seq", json_integer(seq));
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", if(old_settings_table_size != inflater->settings_hd_table_bufsize_max) {
json_integer(inflater->ctx.hd_table_bufsize_max)); json_object_set_new(obj, "header_table_size",
json_integer(inflater->settings_hd_table_bufsize_max));
}
if(config.dump_header_table) { if(config.dump_header_table) {
json_object_set_new(obj, "header_table", json_object_set_new(obj, "header_table",
dump_header_table(&inflater->ctx)); dump_header_table(&inflater->ctx));
@ -95,6 +98,7 @@ static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq)
ssize_t rv; ssize_t rv;
nghttp2_nv nv; nghttp2_nv nv;
int inflate_flags; int inflate_flags;
size_t old_settings_table_size = inflater->settings_hd_table_bufsize_max;
wire = json_object_get(obj, "wire"); wire = json_object_get(obj, "wire");
if(wire == NULL) { if(wire == NULL) {
@ -149,7 +153,7 @@ static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq)
} }
assert(buflen == 0); assert(buflen == 0);
nghttp2_hd_inflate_end_headers(inflater); nghttp2_hd_inflate_end_headers(inflater);
to_json(inflater, headers, wire, seq); to_json(inflater, headers, wire, seq, old_settings_table_size);
json_decref(headers); json_decref(headers);
free(buf); free(buf);
return 0; return 0;