From 9683f88e6a7b6801cc8dc6412df8f6cb1ee36c18 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 11 May 2014 21:38:30 +0900 Subject: [PATCH] Add NGHTTP2_DEFAULT_HEADER_TABLE_SIZE macro Use this macro in Python sources. Python module constant HD_DEFLATE_HD_TABLE_BUFSIZE_MAX was renamed as DEFLATE_MAX_HEADER_TABLE_SIZE since the previous name was awkward. --- lib/includes/nghttp2/nghttp2.h | 6 ++++++ lib/nghttp2_hd.h | 2 +- python/cnghttp2.pxd | 1 + python/hpackmake.py | 8 ++++---- python/nghttp2.pyx | 6 +++--- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 034b0f72..21672cd2 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -159,6 +159,12 @@ typedef struct { */ #define NGHTTP2_MAX_HEADER_TABLE_SIZE (1 << 28) +/** + * @macro + * + * The default header table size. + */ +#define NGHTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12) /** * @macro diff --git a/lib/nghttp2_hd.h b/lib/nghttp2_hd.h index 9ec70e72..4b94dbcc 100644 --- a/lib/nghttp2_hd.h +++ b/lib/nghttp2_hd.h @@ -34,7 +34,7 @@ #include "nghttp2_hd_huffman.h" #include "nghttp2_buf.h" -#define NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE (1 << 12) +#define NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE NGHTTP2_DEFAULT_HEADER_TABLE_SIZE #define NGHTTP2_HD_ENTRY_OVERHEAD 32 /* The maximum value length of name/value pair. This is not specified diff --git a/python/cnghttp2.pxd b/python/cnghttp2.pxd index 24be808a..38a170d0 100644 --- a/python/cnghttp2.pxd +++ b/python/cnghttp2.pxd @@ -27,6 +27,7 @@ cdef extern from 'nghttp2/nghttp2.h': const char NGHTTP2_PROTO_VERSION_ID[] const char NGHTTP2_CLIENT_CONNECTION_PREFACE[] const size_t NGHTTP2_INITIAL_WINDOW_SIZE + const size_t NGHTTP2_DEFAULT_HEADER_TABLE_SIZE ctypedef struct nghttp2_session: pass diff --git a/python/hpackmake.py b/python/hpackmake.py index 2ab8ea16..e53aa664 100755 --- a/python/hpackmake.py +++ b/python/hpackmake.py @@ -26,7 +26,7 @@ result in less bits on the wire.''' cases = [] deflater = nghttp2.HDDeflater(deflate_table_size) - if table_size != 4096: + if table_size != nghttp2.DEFAULT_HEADER_TABLE_SIZE: deflater.change_table_size(table_size) for casenum, item in enumerate(testdata['cases']): @@ -41,7 +41,7 @@ result in less bits on the wire.''' outitem['wire'] = b2a_hex(deflater.deflate(hdrs)).decode('utf-8') cases.append(outitem) - if cases and table_size != 4096: + if cases and table_size != nghttp2.DEFAULT_HEADER_TABLE_SIZE: cases[0]['header_table_size'] = table_size res['cases'] = cases @@ -53,10 +53,10 @@ if __name__ == '__main__': ap = argparse.ArgumentParser(description='HPACK test case generator') ap.add_argument('-d', '--dir', help='output directory', default='out') ap.add_argument('-s', '--table-size', help='max header table size', - type=int, default=4096) + type=int, default=nghttp2.DEFAULT_HEADER_TABLE_SIZE) ap.add_argument('-S', '--deflate-table-size', help='max header table size for deflater', - type=int, default=4096) + type=int, default=nghttp2.DEFLATE_MAX_HEADER_TABLE_SIZE) ap.add_argument('file', nargs='*', help='input file') args = ap.parse_args() try: diff --git a/python/nghttp2.pyx b/python/nghttp2.pyx index faa2ed2e..7000f455 100644 --- a/python/nghttp2.pyx +++ b/python/nghttp2.pyx @@ -26,7 +26,8 @@ from libc.stdlib cimport malloc, free from libc.string cimport memcpy, memset from libc.stdint cimport uint8_t, uint16_t, uint32_t, int32_t -HD_DEFLATE_HD_TABLE_BUFSIZE_MAX = 4096 +DEFAULT_HEADER_TABLE_SIZE = cnghttp2.NGHTTP2_DEFAULT_HEADER_TABLE_SIZE +DEFLATE_MAX_HEADER_TABLE_SIZE = 4096 HD_ENTRY_OVERHEAD = cnghttp2.NGHTTP2_HD_ENTRY_OVERHEAD @@ -83,8 +84,7 @@ cdef class HDDeflater: cdef cnghttp2.nghttp2_hd_deflater _deflater - def __cinit__(self, - hd_table_bufsize_max = HD_DEFLATE_HD_TABLE_BUFSIZE_MAX): + def __cinit__(self, hd_table_bufsize_max = DEFLATE_MAX_HEADER_TABLE_SIZE): rv = cnghttp2.nghttp2_hd_deflate_init2(&self._deflater, hd_table_bufsize_max) if rv != 0: