Exemplo n.º 1
0
def testsuite(testdata, filename, outdir, table_size, deflate_table_size):
    res = {
        'draft':
        6,
        'description':
        '''\
Encoded by nghttp2. The basic encoding strategy is described in \
http://lists.w3.org/Archives/Public/ietf-http-wg/2013JulSep/1135.html \
We use huffman encoding only if it produces strictly shorter byte string than \
original. We make some headers not indexing at all, but this does not always \
result in less bits on the wire.'''
    }
    cases = []
    deflater = nghttp2.HDDeflater(deflate_table_size)
    deflater.change_table_size(table_size)
    for casenum, item in enumerate(testdata['cases']):
        outitem = {'headers': item['headers']}
        casenum += 1
        hdrs = [(list(x.keys())[0].encode('utf-8'),
                 list(x.values())[0].encode('utf-8')) \
                for x in item['headers']]
        outitem['wire'] = b2a_hex(deflater.deflate(hdrs)).decode('utf-8')
        cases.append(outitem)

    if cases:
        cases[0]['header_table_size'] = table_size

    res['cases'] = cases
    jsonstr = json.dumps(res, indent=2)
    with open(os.path.join(outdir, filename), 'w') as f:
        f.write(jsonstr)
Exemplo n.º 2
0
def testsuite(testdata, filename, outdir, table_size, deflate_table_size,
              simulate_table_size_change):
    res = {
        'draft':9,
        'description': '''\
Encoded by nghttp2. The basic encoding strategy is described in \
http://lists.w3.org/Archives/Public/ietf-http-wg/2013JulSep/1135.html \
We use huffman encoding only if it produces strictly shorter byte string than \
original. We make some headers not indexing at all, but this does not always \
result in less bits on the wire.'''
    }
    cases = []
    deflater = nghttp2.HDDeflater(deflate_table_size)

    if table_size != nghttp2.DEFAULT_HEADER_TABLE_SIZE:
        deflater.change_table_size(table_size)

    num_item = len(testdata['cases'])

    change_points = {}
    if simulate_table_size_change and num_item > 1:
        change_points[num_item * 2 // 3] = table_size * 2 // 3
        change_points[num_item // 3] = table_size // 3

    for casenum, item  in enumerate(testdata['cases']):
        outitem = {
            'seqno': casenum,
            'headers': item['headers']
        }

        if casenum in change_points:
            new_table_size = change_points[casenum]
            deflater.change_table_size(new_table_size)
            outitem['header_table_size'] = new_table_size

        casenum += 1
        hdrs = [(list(x.keys())[0].encode('utf-8'),
                 list(x.values())[0].encode('utf-8')) \
                for x in item['headers']]
        outitem['wire'] = b2a_hex(deflater.deflate(hdrs)).decode('utf-8')
        cases.append(outitem)

    if cases and table_size != nghttp2.DEFAULT_HEADER_TABLE_SIZE:
        cases[0]['header_table_size'] = table_size

    res['cases'] = cases
    jsonstr = json.dumps(res, indent=2)
    with open(os.path.join(outdir, filename), 'w') as f:
        f.write(jsonstr)
Exemplo n.º 3
0
 def __init__(self):
     self._e = nghttp2.HDDeflater()