python: Update to latest nghttp2_hd spec

This commit is contained in:
Tatsuhiro Tsujikawa 2014-01-17 02:27:42 +09:00
parent 707a0b4103
commit 7048c56583
2 changed files with 19 additions and 14 deletions

View File

@ -86,10 +86,10 @@ cdef extern from 'nghttp2_hd.h':
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_context *inflater,
nghttp2_nv **nva_ptr, nghttp2_nv *nv_out, int *final,
uint8_t *input, size_t inlen) uint8_t *input, size_t inlen)
int nghttp2_hd_end_headers(nghttp2_hd_context *deflater_or_inflater) int nghttp2_hd_inflate_end_headers(nghttp2_hd_context *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)

View File

@ -199,19 +199,24 @@ cdef class HDInflater(_HDContextBase):
byte string (not unicode string). byte string (not unicode string).
''' '''
cdef cnghttp2.nghttp2_nv *nva cdef cnghttp2.nghttp2_nv nv
cdef int final
cdef ssize_t rv cdef ssize_t rv
cdef uint8_t *buf = data
rv = cnghttp2.nghttp2_hd_inflate_hd(&self._ctx, &nva, cdef size_t buflen = len(data)
data, len(data)) res = []
while True:
rv = cnghttp2.nghttp2_hd_inflate_hd(&self._ctx, &nv, &final,
buf, buflen)
if rv < 0: if rv < 0:
raise Exception(_strerror(rv)) raise Exception(_strerror(rv))
try: if final:
res = [(nva[i].name[:nva[i].namelen], break
nva[i].value[:nva[i].valuelen]) for i in range(rv)] buf += rv
finally: buflen -= rv
cnghttp2.nghttp2_nv_array_del(nva) # may throw
cnghttp2.nghttp2_hd_end_headers(&self._ctx) res.append((nv.name[:nv.namelen], nv.value[:nv.valuelen]))
cnghttp2.nghttp2_hd_inflate_end_headers(&self._ctx)
return res return res
cdef _strerror(int liberror_code): cdef _strerror(int liberror_code):