diff --git a/python/cnghttp2.pxd b/python/cnghttp2.pxd index 33115efe..09ae1fd8 100644 --- a/python/cnghttp2.pxd +++ b/python/cnghttp2.pxd @@ -86,10 +86,10 @@ cdef extern from 'nghttp2_hd.h': nghttp2_nv *nva, size_t nvlen) 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) - 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, size_t index) diff --git a/python/nghttp2.pyx b/python/nghttp2.pyx index 0b875813..47acbe2b 100644 --- a/python/nghttp2.pyx +++ b/python/nghttp2.pyx @@ -199,19 +199,24 @@ cdef class HDInflater(_HDContextBase): byte string (not unicode string). ''' - cdef cnghttp2.nghttp2_nv *nva + cdef cnghttp2.nghttp2_nv nv + cdef int final cdef ssize_t rv - - rv = cnghttp2.nghttp2_hd_inflate_hd(&self._ctx, &nva, - data, len(data)) - if rv < 0: - raise Exception(_strerror(rv)) - try: - res = [(nva[i].name[:nva[i].namelen], - nva[i].value[:nva[i].valuelen]) for i in range(rv)] - finally: - cnghttp2.nghttp2_nv_array_del(nva) - cnghttp2.nghttp2_hd_end_headers(&self._ctx) + cdef uint8_t *buf = data + cdef size_t buflen = len(data) + res = [] + while True: + rv = cnghttp2.nghttp2_hd_inflate_hd(&self._ctx, &nv, &final, + buf, buflen) + if rv < 0: + raise Exception(_strerror(rv)) + if final: + break + buf += rv + buflen -= rv + # may throw + res.append((nv.name[:nv.namelen], nv.value[:nv.valuelen])) + cnghttp2.nghttp2_hd_inflate_end_headers(&self._ctx) return res cdef _strerror(int liberror_code):