1
2nghttp2_hd_inflate_hd
3=====================
4
5Synopsis
6--------
7
8*#include <nghttp2/nghttp2.h>*
9
10.. function:: ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags, uint8_t *in, size_t inlen, int in_final)
11
12
13    .. warning::
14
15      Deprecated.  Use `nghttp2_hd_inflate_hd2()` instead.
16
17    Inflates name/value block stored in *in* with length *inlen*.  This
18    function performs decompression.  For each successful emission of
19    header name/value pair,
20    :macro:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in
21    *\*inflate_flags* and name/value pair is assigned to the *nv_out*
22    and the function returns.  The caller must not free the members of
23    *nv_out*.
24
25    The *nv_out* may include pointers to the memory region in the *in*.
26    The caller must retain the *in* while the *nv_out* is used.
27
28    The application should call this function repeatedly until the
29    ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
30    return value is non-negative.  This means the all input values are
31    processed successfully.  Then the application must call
32    `nghttp2_hd_inflate_end_headers()` to prepare for the next header
33    block input.
34
35    The caller can feed complete compressed header block.  It also can
36    feed it in several chunks.  The caller must set *in_final* to
37    nonzero if the given input is the last block of the compressed
38    header.
39
40    This function returns the number of bytes processed if it succeeds,
41    or one of the following negative error codes:
42
43    :macro:`nghttp2_error.NGHTTP2_ERR_NOMEM`
44        Out of memory.
45    :macro:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
46        Inflation process has failed.
47    :macro:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR`
48        The header field name or value is too large.
49
50    Example follows::
51
52        int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
53                                 uint8_t *in, size_t inlen, int final)
54        {
55            ssize_t rv;
56
57            for(;;) {
58                nghttp2_nv nv;
59                int inflate_flags = 0;
60
61                rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags,
62                                           in, inlen, final);
63
64                if(rv < 0) {
65                    fprintf(stderr, "inflate failed with error code %zd", rv);
66                    return -1;
67                }
68
69                in += rv;
70                inlen -= rv;
71
72                if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
73                    fwrite(nv.name, nv.namelen, 1, stderr);
74                    fprintf(stderr, ": ");
75                    fwrite(nv.value, nv.valuelen, 1, stderr);
76                    fprintf(stderr, "\n");
77                }
78                if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
79                    nghttp2_hd_inflate_end_headers(hd_inflater);
80                    break;
81                }
82                if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
83                   inlen == 0) {
84                   break;
85                }
86            }
87
88            return 0;
89        }
90
91