2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2013, 2014 Tatsuhiro Tsujikawa
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 /* Define WIN32 when build target is Win32 API (borrowed from
30 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
40 #include <sys/types.h>
42 #include <nghttp2/nghttp2ver.h>
44 #ifdef NGHTTP2_STATICLIB
45 #define NGHTTP2_EXTERN
47 #define NGHTTP2_EXTERN __declspec(dllexport)
48 #else /* !defined(WIN32) */
49 #define NGHTTP2_EXTERN
50 #endif /* !defined(WIN32) */
55 * The protocol version identification string of this library
56 * supports. This identifier is used if HTTP/2 is used over TLS.
58 #define NGHTTP2_PROTO_VERSION_ID "h2"
62 * The length of :macro:`NGHTTP2_PROTO_VERSION_ID`.
64 #define NGHTTP2_PROTO_VERSION_ID_LEN 2
69 * The seriazlied form of ALPN protocol identifier this library
70 * supports. Notice that first byte is the length of following
71 * protocol identifier. This is the same wire format of `TLS ALPN
72 * extension <https://tools.ietf.org/html/rfc7301>`_. This is useful
73 * to process incoming ALPN tokens in wire format.
75 #define NGHTTP2_PROTO_ALPN "\x2h2"
80 * The length of :macro:`NGHTTP2_PROTO_ALPN`.
82 #define NGHTTP2_PROTO_ALPN_LEN (sizeof(NGHTTP2_PROTO_ALPN) - 1)
87 * The protocol version identification string of this library
88 * supports. This identifier is used if HTTP/2 is used over cleartext
91 #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c"
96 * The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`.
98 #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 3
100 struct nghttp2_session;
104 * The primary structure to hold the resources needed for a HTTP/2
105 * session. The details of this structure are intentionally hidden
106 * from the public API.
108 typedef struct nghttp2_session nghttp2_session;
113 * The age of :type:`nghttp2_info`
115 #define NGHTTP2_VERSION_AGE 1
120 * This struct is what `nghttp2_version()` returns. It holds
121 * information about the particular nghttp2 version.
125 * Age of this struct. This instance of nghttp2 sets it to
126 * :macro:`NGHTTP2_VERSION_AGE` but a future version may bump it and
127 * add more struct fields at the bottom
131 * the :macro:`NGHTTP2_VERSION_NUM` number (since age ==1)
135 * points to the :macro:`NGHTTP2_VERSION` string (since age ==1)
137 const char *version_str;
139 * points to the :macro:`NGHTTP2_PROTO_VERSION_ID` string this
140 * instance implements (since age ==1)
142 const char *proto_str;
143 /* -------- the above fields all exist when age == 1 */
149 * The default weight of stream dependency.
151 #define NGHTTP2_DEFAULT_WEIGHT 16
156 * The maximum weight of stream dependency.
158 #define NGHTTP2_MAX_WEIGHT 256
163 * The minimum weight of stream dependency.
165 #define NGHTTP2_MIN_WEIGHT 1
170 * The maximum window size
172 #define NGHTTP2_MAX_WINDOW_SIZE ((int32_t)((1U << 31) - 1))
177 * The initial window size for stream level flow control.
179 #define NGHTTP2_INITIAL_WINDOW_SIZE ((1 << 16) - 1)
183 * The initial window size for connection level flow control.
185 #define NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE ((1 << 16) - 1)
190 * The default header table size.
192 #define NGHTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12)
197 * The client magic string, which is the first 24 bytes byte string of
198 * client connection preface.
200 #define NGHTTP2_CLIENT_MAGIC "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
205 * The length of :macro:`NGHTTP2_CLIENT_MAGIC`.
207 #define NGHTTP2_CLIENT_MAGIC_LEN 24
212 * Error codes used in this library. The code range is [-999, -500],
213 * inclusive. The following values are defined:
217 * Invalid argument passed.
219 NGHTTP2_ERR_INVALID_ARGUMENT = -501,
221 * Out of buffer space.
223 NGHTTP2_ERR_BUFFER_ERROR = -502,
225 * The specified protocol version is not supported.
227 NGHTTP2_ERR_UNSUPPORTED_VERSION = -503,
229 * Used as a return value from :type:`nghttp2_send_callback`,
230 * :type:`nghttp2_recv_callback` and
231 * :type:`nghttp2_send_data_callback` to indicate that the operation
234 NGHTTP2_ERR_WOULDBLOCK = -504,
236 * General protocol error
238 NGHTTP2_ERR_PROTO = -505,
240 * The frame is invalid.
242 NGHTTP2_ERR_INVALID_FRAME = -506,
244 * The peer performed a shutdown on the connection.
246 NGHTTP2_ERR_EOF = -507,
248 * Used as a return value from
249 * :func:`nghttp2_data_source_read_callback` to indicate that data
250 * transfer is postponed. See
251 * :func:`nghttp2_data_source_read_callback` for details.
253 NGHTTP2_ERR_DEFERRED = -508,
255 * Stream ID has reached the maximum value. Therefore no stream ID
258 NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509,
260 * The stream is already closed; or the stream ID is invalid.
262 NGHTTP2_ERR_STREAM_CLOSED = -510,
264 * RST_STREAM has been added to the outbound queue. The stream is
267 NGHTTP2_ERR_STREAM_CLOSING = -511,
269 * The transmission is not allowed for this stream (e.g., a frame
270 * with END_STREAM flag set has already sent).
272 NGHTTP2_ERR_STREAM_SHUT_WR = -512,
274 * The stream ID is invalid.
276 NGHTTP2_ERR_INVALID_STREAM_ID = -513,
278 * The state of the stream is not valid (e.g., DATA cannot be sent
279 * to the stream if response HEADERS has not been sent).
281 NGHTTP2_ERR_INVALID_STREAM_STATE = -514,
283 * Another DATA frame has already been deferred.
285 NGHTTP2_ERR_DEFERRED_DATA_EXIST = -515,
287 * Starting new stream is not allowed (e.g., GOAWAY has been sent
290 NGHTTP2_ERR_START_STREAM_NOT_ALLOWED = -516,
292 * GOAWAY has already been sent.
294 NGHTTP2_ERR_GOAWAY_ALREADY_SENT = -517,
296 * The received frame contains the invalid header block (e.g., There
297 * are duplicate header names; or the header names are not encoded
298 * in US-ASCII character set and not lower cased; or the header name
299 * is zero-length string; or the header value contains multiple
300 * in-sequence NUL bytes).
302 NGHTTP2_ERR_INVALID_HEADER_BLOCK = -518,
304 * Indicates that the context is not suitable to perform the
305 * requested operation.
307 NGHTTP2_ERR_INVALID_STATE = -519,
309 * The user callback function failed due to the temporal error.
311 NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE = -521,
313 * The length of the frame is invalid, either too large or too small.
315 NGHTTP2_ERR_FRAME_SIZE_ERROR = -522,
317 * Header block inflate/deflate error.
319 NGHTTP2_ERR_HEADER_COMP = -523,
323 NGHTTP2_ERR_FLOW_CONTROL = -524,
325 * Insufficient buffer size given to function.
327 NGHTTP2_ERR_INSUFF_BUFSIZE = -525,
329 * Callback was paused by the application
331 NGHTTP2_ERR_PAUSE = -526,
333 * There are too many in-flight SETTING frame and no more
334 * transmission of SETTINGS is allowed.
336 NGHTTP2_ERR_TOO_MANY_INFLIGHT_SETTINGS = -527,
338 * The server push is disabled.
340 NGHTTP2_ERR_PUSH_DISABLED = -528,
342 * DATA frame for a given stream has been already submitted and has
343 * not been fully processed yet.
345 NGHTTP2_ERR_DATA_EXIST = -529,
347 * The current session is closing due to a connection error or
348 * `nghttp2_session_terminate_session()` is called.
350 NGHTTP2_ERR_SESSION_CLOSING = -530,
352 * Invalid HTTP header field was received and stream is going to be
355 NGHTTP2_ERR_HTTP_HEADER = -531,
357 * Violation in HTTP messaging rule.
359 NGHTTP2_ERR_HTTP_MESSAGING = -532,
361 * Stream was refused.
363 NGHTTP2_ERR_REFUSED_STREAM = -533,
365 * Unexpected internal error, but recovered.
367 NGHTTP2_ERR_INTERNAL = -534,
369 * The errors < :enum:`NGHTTP2_ERR_FATAL` mean that the library is
370 * under unexpected condition and processing was terminated (e.g.,
371 * out of memory). If application receives this error code, it must
372 * stop using that :type:`nghttp2_session` object and only allowed
373 * operation for that object is deallocate it using
374 * `nghttp2_session_del()`.
376 NGHTTP2_ERR_FATAL = -900,
378 * Out of memory. This is a fatal error.
380 NGHTTP2_ERR_NOMEM = -901,
382 * The user callback function failed. This is a fatal error.
384 NGHTTP2_ERR_CALLBACK_FAILURE = -902,
386 * Invalid client magic (see :macro:`NGHTTP2_CLIENT_MAGIC`) was
387 * received and further processing is not possible.
389 NGHTTP2_ERR_BAD_CLIENT_MAGIC = -903
395 * The flags for header field name/value pair.
401 NGHTTP2_NV_FLAG_NONE = 0,
403 * Indicates that this name/value pair must not be indexed ("Literal
404 * Header Field never Indexed" representation must be used in HPACK
405 * encoding). Other implementation calls this bit as "sensitive".
407 NGHTTP2_NV_FLAG_NO_INDEX = 0x01
413 * The name/value pair, which mainly used to represent header fields.
417 * The |name| byte string. If this struct is presented from library
418 * (e.g., :type:`nghttp2_on_frame_recv_callback`), |name| is
419 * guaranteed to be NULL-terminated. When application is
420 * constructing this struct, |name| is not required to be
425 * The |value| byte string. If this struct is presented from
426 * library (e.g., :type:`nghttp2_on_frame_recv_callback`), |value|
427 * is guaranteed to be NULL-terminated. When application is
428 * constructing this struct, |value| is not required to be
433 * The length of the |name|, excluding terminating NULL.
437 * The length of the |value|, excluding terminating NULL.
441 * Bitwise OR of one or more of :type:`nghttp2_nv_flag`.
449 * The frame types in HTTP/2 specification.
459 NGHTTP2_HEADERS = 0x01,
461 * The PRIORITY frame.
463 NGHTTP2_PRIORITY = 0x02,
465 * The RST_STREAM frame.
467 NGHTTP2_RST_STREAM = 0x03,
469 * The SETTINGS frame.
471 NGHTTP2_SETTINGS = 0x04,
473 * The PUSH_PROMISE frame.
475 NGHTTP2_PUSH_PROMISE = 0x05,
483 NGHTTP2_GOAWAY = 0x07,
485 * The WINDOW_UPDATE frame.
487 NGHTTP2_WINDOW_UPDATE = 0x08,
489 * The CONTINUATION frame. This frame type won't be passed to any
490 * callbacks because the library processes this frame type and its
491 * preceding HEADERS/PUSH_PROMISE as a single frame.
493 NGHTTP2_CONTINUATION = 0x09
494 } nghttp2_frame_type;
499 * The flags for HTTP/2 frames. This enum defines all flags for all
506 NGHTTP2_FLAG_NONE = 0,
508 * The END_STREAM flag.
510 NGHTTP2_FLAG_END_STREAM = 0x01,
512 * The END_HEADERS flag.
514 NGHTTP2_FLAG_END_HEADERS = 0x04,
518 NGHTTP2_FLAG_ACK = 0x01,
522 NGHTTP2_FLAG_PADDED = 0x08,
526 NGHTTP2_FLAG_PRIORITY = 0x20
535 * SETTINGS_HEADER_TABLE_SIZE
537 NGHTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x01,
539 * SETTINGS_ENABLE_PUSH
541 NGHTTP2_SETTINGS_ENABLE_PUSH = 0x02,
543 * SETTINGS_MAX_CONCURRENT_STREAMS
545 NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x03,
547 * SETTINGS_INITIAL_WINDOW_SIZE
549 NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x04,
551 * SETTINGS_MAX_FRAME_SIZE
553 NGHTTP2_SETTINGS_MAX_FRAME_SIZE = 0x05,
555 * SETTINGS_MAX_HEADER_LIST_SIZE
557 NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x06
558 } nghttp2_settings_id;
559 /* Note: If we add SETTINGS, update the capacity of
560 NGHTTP2_INBOUND_NUM_IV as well */
564 * Default maximum concurrent streams.
566 #define NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1)
570 * The status codes for the RST_STREAM and GOAWAY frames.
576 NGHTTP2_NO_ERROR = 0x00,
580 NGHTTP2_PROTOCOL_ERROR = 0x01,
584 NGHTTP2_INTERNAL_ERROR = 0x02,
588 NGHTTP2_FLOW_CONTROL_ERROR = 0x03,
592 NGHTTP2_SETTINGS_TIMEOUT = 0x04,
596 NGHTTP2_STREAM_CLOSED = 0x05,
600 NGHTTP2_FRAME_SIZE_ERROR = 0x06,
604 NGHTTP2_REFUSED_STREAM = 0x07,
608 NGHTTP2_CANCEL = 0x08,
612 NGHTTP2_COMPRESSION_ERROR = 0x09,
616 NGHTTP2_CONNECT_ERROR = 0x0a,
620 NGHTTP2_ENHANCE_YOUR_CALM = 0x0b,
622 * INADEQUATE_SECURITY
624 NGHTTP2_INADEQUATE_SECURITY = 0x0c,
628 NGHTTP2_HTTP_1_1_REQUIRED = 0x0d
629 } nghttp2_error_code;
637 * The length field of this frame, excluding frame header.
641 * The stream identifier (aka, stream ID)
645 * The type of this frame. See `nghttp2_frame_type`.
653 * Reserved bit in frame header. Currently, this is always set to 0
654 * and application should not expect something useful in here.
662 * This union represents the some kind of data source passed to
663 * :type:`nghttp2_data_source_read_callback`.
667 * The integer field, suitable for a file descriptor.
671 * The pointer to an arbitrary object.
674 } nghttp2_data_source;
679 * The flags used to set in |data_flags| output parameter in
680 * :type:`nghttp2_data_source_read_callback`.
686 NGHTTP2_DATA_FLAG_NONE = 0,
688 * Indicates EOF was sensed.
690 NGHTTP2_DATA_FLAG_EOF = 0x01,
692 * Indicates that END_STREAM flag must not be set even if
693 * NGHTTP2_DATA_FLAG_EOF is set. Usually this flag is used to send
694 * trailer header fields with `nghttp2_submit_request()` or
695 * `nghttp2_submit_response()`.
697 NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02,
699 * Indicates that application will send complete DATA frame in
700 * :type:`nghttp2_send_data_callback`.
702 NGHTTP2_DATA_FLAG_NO_COPY = 0x04
708 * Callback function invoked when the library wants to read data from
709 * the |source|. The read data is sent in the stream |stream_id|.
710 * The implementation of this function must read at most |length|
711 * bytes of data from |source| (or possibly other places) and store
712 * them in |buf| and return number of data stored in |buf|. If EOF is
713 * reached, set :enum:`NGHTTP2_DATA_FLAG_EOF` flag in |*data_flags|.
715 * Sometime it is desirable to avoid copying data into |buf| and let
716 * application to send data directly. To achieve this, set
717 * :enum:`NGHTTP2_DATA_FLAG_NO_COPY` to |*data_flags| (and possibly
718 * other flags, just like when we do copy), and return the number of
719 * bytes to send without copying data into |buf|. The library, seeing
720 * :enum:`NGHTTP2_DATA_FLAG_NO_COPY`, will invoke
721 * :type:`nghttp2_send_data_callback`. The application must send
722 * complete DATA frame in that callback.
724 * If this callback is set by `nghttp2_submit_request()`,
725 * `nghttp2_submit_response()` or `nghttp2_submit_headers()` and
726 * `nghttp2_submit_data()` with flag parameter
727 * :enum:`NGHTTP2_FLAG_END_STREAM` set, and
728 * :enum:`NGHTTP2_DATA_FLAG_EOF` flag is set to |*data_flags|, DATA
729 * frame will have END_STREAM flag set. Usually, this is expected
730 * behaviour and all are fine. One exception is send trailer header
731 * fields. You cannot send trailers after sending frame with
732 * END_STREAM set. To avoid this problem, one can set
733 * :enum:`NGHTTP2_DATA_FLAG_NO_END_STREAM` along with
734 * :enum:`NGHTTP2_DATA_FLAG_EOF` to signal the library not to set
735 * END_STREAM in DATA frame. Then application can use
736 * `nghttp2_submit_trailer()` to send trailers.
737 * `nghttp2_submit_trailer()` can be called inside this callback.
739 * If the application wants to postpone DATA frames (e.g.,
740 * asynchronous I/O, or reading data blocks for long time), it is
741 * achieved by returning :enum:`NGHTTP2_ERR_DEFERRED` without reading
742 * any data in this invocation. The library removes DATA frame from
743 * the outgoing queue temporarily. To move back deferred DATA frame
744 * to outgoing queue, call `nghttp2_session_resume_data()`. In case
745 * of error, there are 2 choices. Returning
746 * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close the stream
747 * by issuing RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. If a
748 * different error code is desirable, use
749 * `nghttp2_submit_rst_stream()` with a desired error code and then
750 * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Returning
751 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the entire session
754 typedef ssize_t (*nghttp2_data_source_read_callback)(
755 nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length,
756 uint32_t *data_flags, nghttp2_data_source *source, void *user_data);
761 * This struct represents the data source and the way to read a chunk
768 nghttp2_data_source source;
770 * The callback function to read a chunk of data from the |source|.
772 nghttp2_data_source_read_callback read_callback;
773 } nghttp2_data_provider;
778 * The DATA frame. The received data is delivered via
779 * :type:`nghttp2_on_data_chunk_recv_callback`.
784 * The length of the padding in this frame. This includes PAD_HIGH
793 * The category of HEADERS, which indicates the role of the frame. In
794 * HTTP/2 spec, request, response, push response and other arbitrary
795 * headers (e.g., trailers) are all called just HEADERS. To give the
796 * application the role of incoming HEADERS frame, we define several
801 * The HEADERS frame is opening new stream, which is analogous to
802 * SYN_STREAM in SPDY.
804 NGHTTP2_HCAT_REQUEST = 0,
806 * The HEADERS frame is the first response headers, which is
807 * analogous to SYN_REPLY in SPDY.
809 NGHTTP2_HCAT_RESPONSE = 1,
811 * The HEADERS frame is the first headers sent against reserved
814 NGHTTP2_HCAT_PUSH_RESPONSE = 2,
816 * The HEADERS frame which does not apply for the above categories,
817 * which is analogous to HEADERS in SPDY. If non-final response
818 * (e.g., status 1xx) is used, final response HEADERS frame will be
821 NGHTTP2_HCAT_HEADERS = 3
822 } nghttp2_headers_category;
827 * The structure to specify stream dependency.
831 * The stream ID of the stream to depend on. Specifying 0 makes
832 * stream not depend any other stream.
836 * The weight of this dependency.
840 * nonzero means exclusive dependency
843 } nghttp2_priority_spec;
848 * The HEADERS frame. It has the following members:
856 * The length of the padding in this frame. This includes PAD_HIGH
861 * The priority specification
863 nghttp2_priority_spec pri_spec;
865 * The name/value pairs.
869 * The number of name/value pairs in |nva|.
873 * The category of this HEADERS frame.
875 nghttp2_headers_category cat;
881 * The PRIORITY frame. It has the following members:
889 * The priority specification.
891 nghttp2_priority_spec pri_spec;
897 * The RST_STREAM frame. It has the following members:
905 * The error code. See :type:`nghttp2_error_code`.
908 } nghttp2_rst_stream;
913 * The SETTINGS ID/Value pair. It has the following members:
917 * The SETTINGS ID. See :type:`nghttp2_settings_id`.
921 * The value of this entry.
924 } nghttp2_settings_entry;
929 * The SETTINGS frame. It has the following members:
937 * The number of SETTINGS ID/Value pairs in |iv|.
941 * The pointer to the array of SETTINGS ID/Value pair.
943 nghttp2_settings_entry *iv;
949 * The PUSH_PROMISE frame. It has the following members:
957 * The length of the padding in this frame. This includes PAD_HIGH
962 * The name/value pairs.
966 * The number of name/value pairs in |nva|.
970 * The promised stream ID
972 int32_t promised_stream_id;
974 * Reserved bit. Currently this is always set to 0 and application
975 * should not expect something useful in here.
978 } nghttp2_push_promise;
983 * The PING frame. It has the following members:
993 uint8_t opaque_data[8];
999 * The GOAWAY frame. It has the following members:
1005 nghttp2_frame_hd hd;
1007 * The last stream stream ID.
1009 int32_t last_stream_id;
1011 * The error code. See :type:`nghttp2_error_code`.
1013 uint32_t error_code;
1015 * The additional debug data
1017 uint8_t *opaque_data;
1019 * The length of |opaque_data| member.
1021 size_t opaque_data_len;
1023 * Reserved bit. Currently this is always set to 0 and application
1024 * should not expect something useful in here.
1032 * The WINDOW_UPDATE frame. It has the following members:
1038 nghttp2_frame_hd hd;
1040 * The window size increment.
1042 int32_t window_size_increment;
1044 * Reserved bit. Currently this is always set to 0 and application
1045 * should not expect something useful in here.
1048 } nghttp2_window_update;
1053 * The extension frame. It has following members:
1059 nghttp2_frame_hd hd;
1061 * The pointer to extension payload. The exact pointer type is
1062 * determined by hd.type.
1064 * Currently, no extension is supported. This is a place holder for
1065 * the future extensions.
1068 } nghttp2_extension;
1073 * This union includes all frames to pass them to various function
1074 * calls as nghttp2_frame type. The CONTINUATION frame is omitted
1075 * from here because the library deals with it internally.
1079 * The frame header, which is convenient to inspect frame header.
1081 nghttp2_frame_hd hd;
1087 * The HEADERS frame.
1089 nghttp2_headers headers;
1091 * The PRIORITY frame.
1093 nghttp2_priority priority;
1095 * The RST_STREAM frame.
1097 nghttp2_rst_stream rst_stream;
1099 * The SETTINGS frame.
1101 nghttp2_settings settings;
1103 * The PUSH_PROMISE frame.
1105 nghttp2_push_promise push_promise;
1113 nghttp2_goaway goaway;
1115 * The WINDOW_UPDATE frame.
1117 nghttp2_window_update window_update;
1119 * The extension frame.
1121 nghttp2_extension ext;
1127 * Callback function invoked when |session| wants to send data to the
1128 * remote peer. The implementation of this function must send at most
1129 * |length| bytes of data stored in |data|. The |flags| is currently
1130 * not used and always 0. It must return the number of bytes sent if
1131 * it succeeds. If it cannot send any single byte without blocking,
1132 * it must return :enum:`NGHTTP2_ERR_WOULDBLOCK`. For other errors,
1133 * it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. The
1134 * |user_data| pointer is the third argument passed in to the call to
1135 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1137 * This callback is required if the application uses
1138 * `nghttp2_session_send()` to send data to the remote endpoint. If
1139 * the application uses solely `nghttp2_session_mem_send()` instead,
1140 * this callback function is unnecessary.
1142 * To set this callback to :type:`nghttp2_session_callbacks`, use
1143 * `nghttp2_session_callbacks_set_send_callback()`.
1145 typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session,
1146 const uint8_t *data, size_t length,
1147 int flags, void *user_data);
1152 * Callback function invoked when :enum:`NGHTTP2_DATA_FLAG_NO_COPY` is
1153 * used in :type:`nghttp2_data_source_read_callback` to send complete
1156 * The |frame| is a DATA frame to send. The |framehd| is the
1157 * serialized frame header (9 bytes). The |length| is the length of
1158 * application data to send (this does not include padding). The
1159 * |source| is the same pointer passed to
1160 * :type:`nghttp2_data_source_read_callback`.
1162 * The application first must send frame header |framehd| of length 9
1163 * bytes. If ``frame->padlen > 0``, send 1 byte of value
1164 * ``frame->padlen - 1``. Then send exactly |length| bytes of
1165 * application data. Finally, if ``frame->padlen > 0``, send
1166 * ``frame->padlen - 1`` bytes of zero (they are padding).
1168 * The application has to send complete DATA frame in this callback.
1169 * If all data were written successfully, return 0.
1171 * If it cannot send it all, just return
1172 * :enum:`NGHTTP2_ERR_WOULDBLOCK`; the library will call this callback
1173 * with the same parameters later (It is recommended to send complete
1174 * DATA frame at once in this function to deal with error; if partial
1175 * frame data has already sent, it is impossible to send another data
1176 * in that state, and all we can do is tear down connection). If
1177 * application decided to reset this stream, return
1178 * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`, then the library
1179 * will send RST_STREAM with INTERNAL_ERROR as error code. The
1180 * application can also return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`,
1181 * which will result in connection closure. Returning any other value
1182 * is treated as :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned.
1184 typedef int (*nghttp2_send_data_callback)(nghttp2_session *session,
1185 nghttp2_frame *frame,
1186 const uint8_t *framehd, size_t length,
1187 nghttp2_data_source *source,
1193 * Callback function invoked when |session| wants to receive data from
1194 * the remote peer. The implementation of this function must read at
1195 * most |length| bytes of data and store it in |buf|. The |flags| is
1196 * currently not used and always 0. It must return the number of
1197 * bytes written in |buf| if it succeeds. If it cannot read any
1198 * single byte without blocking, it must return
1199 * :enum:`NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF before it reads any
1200 * single byte, it must return :enum:`NGHTTP2_ERR_EOF`. For other
1201 * errors, it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1202 * Returning 0 is treated as :enum:`NGHTTP2_ERR_WOULDBLOCK`. The
1203 * |user_data| pointer is the third argument passed in to the call to
1204 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1206 * This callback is required if the application uses
1207 * `nghttp2_session_recv()` to receive data from the remote endpoint.
1208 * If the application uses solely `nghttp2_session_mem_recv()`
1209 * instead, this callback function is unnecessary.
1211 * To set this callback to :type:`nghttp2_session_callbacks`, use
1212 * `nghttp2_session_callbacks_set_recv_callback()`.
1214 typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf,
1215 size_t length, int flags,
1221 * Callback function invoked by `nghttp2_session_recv()` and
1222 * `nghttp2_session_mem_recv()` when a frame is received. The
1223 * |user_data| pointer is the third argument passed in to the call to
1224 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1226 * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen``
1227 * member of their data structure are always ``NULL`` and 0
1228 * respectively. The header name/value pairs are emitted via
1229 * :type:`nghttp2_on_header_callback`.
1231 * For HEADERS, PUSH_PROMISE and DATA frames, this callback may be
1232 * called after stream is closed (see
1233 * :type:`nghttp2_on_stream_close_callback`). The application should
1234 * check that stream is still alive using its own stream management or
1235 * :func:`nghttp2_session_get_stream_user_data()`.
1237 * Only HEADERS and DATA frame can signal the end of incoming data.
1238 * If ``frame->hd.flags & NGHTTP2_FLAG_END_STREAM`` is nonzero, the
1239 * |frame| is the last frame from the remote peer in this stream.
1241 * This callback won't be called for CONTINUATION frames.
1242 * HEADERS/PUSH_PROMISE + CONTINUATIONs are treated as single frame.
1244 * The implementation of this function must return 0 if it succeeds.
1245 * If nonzero value is returned, it is treated as fatal error and
1246 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1247 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1249 * To set this callback to :type:`nghttp2_session_callbacks`, use
1250 * `nghttp2_session_callbacks_set_on_frame_recv_callback()`.
1252 typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session,
1253 const nghttp2_frame *frame,
1259 * Callback function invoked by `nghttp2_session_recv()` and
1260 * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is
1261 * received. The error is indicated by the |lib_error_code|, which is
1262 * one of the values defined in :type:`nghttp2_error`. When this
1263 * callback function is invoked, the library automatically submits
1264 * either RST_STREAM or GOAWAY frame. The |user_data| pointer is the
1265 * third argument passed in to the call to
1266 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1268 * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen``
1269 * member of their data structure are always ``NULL`` and 0
1272 * The implementation of this function must return 0 if it succeeds.
1273 * If nonzero is returned, it is treated as fatal error and
1274 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1275 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1277 * To set this callback to :type:`nghttp2_session_callbacks`, use
1278 * `nghttp2_session_callbacks_set_on_invalid_frame_recv_callback()`.
1280 typedef int (*nghttp2_on_invalid_frame_recv_callback)(
1281 nghttp2_session *session, const nghttp2_frame *frame, int lib_error_code,
1287 * Callback function invoked when a chunk of data in DATA frame is
1288 * received. The |stream_id| is the stream ID this DATA frame belongs
1289 * to. The |flags| is the flags of DATA frame which this data chunk
1290 * is contained. ``(flags & NGHTTP2_FLAG_END_STREAM) != 0`` does not
1291 * necessarily mean this chunk of data is the last one in the stream.
1292 * You should use :type:`nghttp2_on_frame_recv_callback` to know all
1293 * data frames are received. The |user_data| pointer is the third
1294 * argument passed in to the call to `nghttp2_session_client_new()` or
1295 * `nghttp2_session_server_new()`.
1297 * If the application uses `nghttp2_session_mem_recv()`, it can return
1298 * :enum:`NGHTTP2_ERR_PAUSE` to make `nghttp2_session_mem_recv()`
1299 * return without processing further input bytes. The memory by
1300 * pointed by the |data| is retained until
1301 * `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called.
1302 * The application must retain the input bytes which was used to
1303 * produce the |data| parameter, because it may refer to the memory
1304 * region included in the input bytes.
1306 * The implementation of this function must return 0 if it succeeds.
1307 * If nonzero is returned, it is treated as fatal error, and
1308 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1309 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1311 * To set this callback to :type:`nghttp2_session_callbacks`, use
1312 * `nghttp2_session_callbacks_set_on_data_chunk_recv_callback()`.
1314 typedef int (*nghttp2_on_data_chunk_recv_callback)(nghttp2_session *session,
1317 const uint8_t *data,
1318 size_t len, void *user_data);
1323 * Callback function invoked just before the non-DATA frame |frame| is
1324 * sent. The |user_data| pointer is the third argument passed in to
1325 * the call to `nghttp2_session_client_new()` or
1326 * `nghttp2_session_server_new()`.
1328 * The implementation of this function must return 0 if it succeeds.
1329 * If nonzero is returned, it is treated as fatal error and
1330 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
1331 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1333 * To set this callback to :type:`nghttp2_session_callbacks`, use
1334 * `nghttp2_session_callbacks_set_before_frame_send_callback()`.
1336 typedef int (*nghttp2_before_frame_send_callback)(nghttp2_session *session,
1337 const nghttp2_frame *frame,
1343 * Callback function invoked after the frame |frame| is sent. The
1344 * |user_data| pointer is the third argument passed in to the call to
1345 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1347 * The implementation of this function must return 0 if it succeeds.
1348 * If nonzero is returned, it is treated as fatal error and
1349 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
1350 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1352 * To set this callback to :type:`nghttp2_session_callbacks`, use
1353 * `nghttp2_session_callbacks_set_on_frame_send_callback()`.
1355 typedef int (*nghttp2_on_frame_send_callback)(nghttp2_session *session,
1356 const nghttp2_frame *frame,
1362 * Callback function invoked after the non-DATA frame |frame| is not
1363 * sent because of the error. The error is indicated by the
1364 * |lib_error_code|, which is one of the values defined in
1365 * :type:`nghttp2_error`. The |user_data| pointer is the third
1366 * argument passed in to the call to `nghttp2_session_client_new()` or
1367 * `nghttp2_session_server_new()`.
1369 * The implementation of this function must return 0 if it succeeds.
1370 * If nonzero is returned, it is treated as fatal error and
1371 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
1372 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1374 * `nghttp2_session_get_stream_user_data()` can be used to get
1377 * To set this callback to :type:`nghttp2_session_callbacks`, use
1378 * `nghttp2_session_callbacks_set_on_frame_not_send_callback()`.
1380 typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session,
1381 const nghttp2_frame *frame,
1388 * Callback function invoked when the stream |stream_id| is closed.
1389 * The reason of closure is indicated by the |error_code|. The
1390 * |error_code| is usually one of :enum:`nghttp2_error_code`, but that
1391 * is not guaranteed. The stream_user_data, which was specified in
1392 * `nghttp2_submit_request()` or `nghttp2_submit_headers()`, is still
1393 * available in this function. The |user_data| pointer is the third
1394 * argument passed in to the call to `nghttp2_session_client_new()` or
1395 * `nghttp2_session_server_new()`.
1397 * This function is also called for a stream in reserved state.
1399 * The implementation of this function must return 0 if it succeeds.
1400 * If nonzero is returned, it is treated as fatal error and
1401 * `nghttp2_session_recv()`, `nghttp2_session_mem_recv()`,
1402 * `nghttp2_session_send()`, and `nghttp2_session_mem_send()`
1403 * functions immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1405 * To set this callback to :type:`nghttp2_session_callbacks`, use
1406 * `nghttp2_session_callbacks_set_on_stream_close_callback()`.
1408 typedef int (*nghttp2_on_stream_close_callback)(nghttp2_session *session,
1410 uint32_t error_code,
1416 * Callback function invoked when the reception of header block in
1417 * HEADERS or PUSH_PROMISE is started. Each header name/value pair
1418 * will be emitted by :type:`nghttp2_on_header_callback`.
1420 * The ``frame->hd.flags`` may not have
1421 * :enum:`NGHTTP2_FLAG_END_HEADERS` flag set, which indicates that one
1422 * or more CONTINUATION frames are involved. But the application does
1423 * not need to care about that because the header name/value pairs are
1424 * emitted transparently regardless of CONTINUATION frames.
1426 * The server applications probably create an object to store
1427 * information about new stream if ``frame->hd.type ==
1428 * NGHTTP2_HEADERS`` and ``frame->headers.cat ==
1429 * NGHTTP2_HCAT_REQUEST``. If |session| is configured as server side,
1430 * ``frame->headers.cat`` is either ``NGHTTP2_HCAT_REQUEST``
1431 * containing request headers or ``NGHTTP2_HCAT_HEADERS`` containing
1432 * trailer headers and never get PUSH_PROMISE in this callback.
1434 * For the client applications, ``frame->hd.type`` is either
1435 * ``NGHTTP2_HEADERS`` or ``NGHTTP2_PUSH_PROMISE``. In case of
1436 * ``NGHTTP2_HEADERS``, ``frame->headers.cat ==
1437 * NGHTTP2_HCAT_RESPONSE`` means that it is the first response
1438 * headers, but it may be non-final response which is indicated by 1xx
1439 * status code. In this case, there may be zero or more HEADERS frame
1440 * with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` which has
1441 * non-final response code and finally client gets exactly one HEADERS
1442 * frame with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS``
1443 * containing final response headers (non-1xx status code). The
1444 * trailer headers also has ``frame->headers.cat ==
1445 * NGHTTP2_HCAT_HEADERS`` which does not contain any status code.
1447 * Returning :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close
1448 * the stream (promised stream if frame is PUSH_PROMISE) by issuing
1449 * RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. In this case,
1450 * :type:`nghttp2_on_header_callback` and
1451 * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a
1452 * different error code is desirable, use
1453 * `nghttp2_submit_rst_stream()` with a desired error code and then
1454 * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Again, use
1455 * ``frame->push_promise.promised_stream_id`` as stream_id parameter
1456 * in `nghttp2_submit_rst_stream()` if frame is PUSH_PROMISE.
1458 * The implementation of this function must return 0 if it succeeds.
1459 * It can return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` to
1460 * reset the stream (promised stream if frame is PUSH_PROMISE). For
1461 * critical errors, it must return
1462 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the other value is
1463 * returned, it is treated as if :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
1464 * is returned. If :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned,
1465 * `nghttp2_session_mem_recv()` function will immediately return
1466 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1468 * To set this callback to :type:`nghttp2_session_callbacks`, use
1469 * `nghttp2_session_callbacks_set_on_begin_headers_callback()`.
1471 typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session,
1472 const nghttp2_frame *frame,
1478 * Callback function invoked when a header name/value pair is received
1479 * for the |frame|. The |name| of length |namelen| is header name.
1480 * The |value| of length |valuelen| is header value. The |flags| is
1481 * bitwise OR of one or more of :type:`nghttp2_nv_flag`.
1483 * If :enum:`NGHTTP2_NV_FLAG_NO_INDEX` is set in |flags|, the receiver
1484 * must not index this name/value pair when forwarding it to the next
1485 * hop. More specifically, "Literal Header Field never Indexed"
1486 * representation must be used in HPACK encoding.
1488 * When this callback is invoked, ``frame->hd.type`` is either
1489 * :enum:`NGHTTP2_HEADERS` or :enum:`NGHTTP2_PUSH_PROMISE`. After all
1490 * header name/value pairs are processed with this callback, and no
1491 * error has been detected, :type:`nghttp2_on_frame_recv_callback`
1492 * will be invoked. If there is an error in decompression,
1493 * :type:`nghttp2_on_frame_recv_callback` for the |frame| will not be
1496 * Both |name| and |value| are guaranteed to be NULL-terminated. The
1497 * |namelen| and |valuelen| do not include terminal NULL. If
1498 * `nghttp2_option_set_no_http_messaging()` is used with nonzero
1499 * value, NULL character may be included in |name| or |value| before
1502 * Please note that unless `nghttp2_option_set_no_http_messaging()` is
1503 * used, nghttp2 library does perform validation against the |name|
1504 * and the |value| using `nghttp2_check_header_name()` and
1505 * `nghttp2_check_header_value()`. In addition to this, nghttp2
1506 * performs vaidation based on HTTP Messaging rule, which is briefly
1507 * explained in :ref:`http-messaging` section.
1509 * If the application uses `nghttp2_session_mem_recv()`, it can return
1510 * :enum:`NGHTTP2_ERR_PAUSE` to make `nghttp2_session_mem_recv()`
1511 * return without processing further input bytes. The memory pointed
1512 * by |frame|, |name| and |value| parameters are retained until
1513 * `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called.
1514 * The application must retain the input bytes which was used to
1515 * produce these parameters, because it may refer to the memory region
1516 * included in the input bytes.
1518 * Returning :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close
1519 * the stream (promised stream if frame is PUSH_PROMISE) by issuing
1520 * RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. In this case,
1521 * :type:`nghttp2_on_header_callback` and
1522 * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a
1523 * different error code is desirable, use
1524 * `nghttp2_submit_rst_stream()` with a desired error code and then
1525 * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Again, use
1526 * ``frame->push_promise.promised_stream_id`` as stream_id parameter
1527 * in `nghttp2_submit_rst_stream()` if frame is PUSH_PROMISE.
1529 * The implementation of this function must return 0 if it succeeds.
1530 * It may return :enum:`NGHTTP2_ERR_PAUSE` or
1531 * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. For other critical
1532 * failures, it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If
1533 * the other nonzero value is returned, it is treated as
1534 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If
1535 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned,
1536 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1537 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1539 * To set this callback to :type:`nghttp2_session_callbacks`, use
1540 * `nghttp2_session_callbacks_set_on_header_callback()`.
1542 typedef int (*nghttp2_on_header_callback)(nghttp2_session *session,
1543 const nghttp2_frame *frame,
1544 const uint8_t *name, size_t namelen,
1545 const uint8_t *value, size_t valuelen,
1546 uint8_t flags, void *user_data);
1551 * Callback function invoked when the library asks application how
1552 * many padding bytes are required for the transmission of the
1553 * |frame|. The application must choose the total length of payload
1554 * including padded bytes in range [frame->hd.length, max_payloadlen],
1555 * inclusive. Choosing number not in this range will be treated as
1556 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. Returning
1557 * ``frame->hd.length`` means no padding is added. Returning
1558 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will make
1559 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
1560 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1562 * To set this callback to :type:`nghttp2_session_callbacks`, use
1563 * `nghttp2_session_callbacks_set_select_padding_callback()`.
1565 typedef ssize_t (*nghttp2_select_padding_callback)(nghttp2_session *session,
1566 const nghttp2_frame *frame,
1567 size_t max_payloadlen,
1573 * Callback function invoked when library wants to get max length of
1574 * data to send data to the remote peer. The implementation of this
1575 * function should return a value in the following range. [1,
1576 * min(|session_remote_window_size|, |stream_remote_window_size|,
1577 * |remote_max_frame_size|)]. If a value greater than this range is
1578 * returned than the max allow value will be used. Returning a value
1579 * smaller than this range is treated as
1580 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. The |frame_type| is provided
1581 * for future extensibility and identifies the type of frame (see
1582 * :type:`nghttp2_frame_type`) for which to get the length for.
1583 * Currently supported frame types are: :enum:`NGHTTP2_DATA`.
1585 * This callback can be used to control the length in bytes for which
1586 * :type:`nghttp2_data_source_read_callback` is allowed to send to the
1587 * remote endpoint. This callback is optional. Returning
1588 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the entire session
1591 * To set this callback to :type:`nghttp2_session_callbacks`, use
1592 * `nghttp2_session_callbacks_set_data_source_read_length_callback()`.
1594 typedef ssize_t (*nghttp2_data_source_read_length_callback)(
1595 nghttp2_session *session, uint8_t frame_type, int32_t stream_id,
1596 int32_t session_remote_window_size, int32_t stream_remote_window_size,
1597 uint32_t remote_max_frame_size, void *user_data);
1602 * Callback function invoked when a frame header is received. The
1603 * |hd| points to received frame header.
1605 * Unlike :type:`nghttp2_on_frame_recv_callback`, this callback will
1606 * also be called when frame header of CONTINUATION frame is received.
1608 * If both :type:`nghttp2_on_begin_frame_callback` and
1609 * :type:`nghttp2_on_begin_headers_callback` are set and HEADERS or
1610 * PUSH_PROMISE is received, :type:`nghttp2_on_begin_frame_callback`
1611 * will be called first.
1613 * The implementation of this function must return 0 if it succeeds.
1614 * If nonzero value is returned, it is treated as fatal error and
1615 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1616 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1618 * To set this callback to :type:`nghttp2_session_callbacks`, use
1619 * `nghttp2_session_callbacks_set_on_begin_frame_callback()`.
1621 typedef int (*nghttp2_on_begin_frame_callback)(nghttp2_session *session,
1622 const nghttp2_frame_hd *hd,
1625 struct nghttp2_session_callbacks;
1630 * Callback functions for :type:`nghttp2_session`. The details of
1631 * this structure are intentionally hidden from the public API.
1633 typedef struct nghttp2_session_callbacks nghttp2_session_callbacks;
1638 * Initializes |*callbacks_ptr| with NULL values.
1640 * The initialized object can be used when initializing multiple
1641 * :type:`nghttp2_session` objects.
1643 * When the application finished using this object, it can use
1644 * `nghttp2_session_callbacks_del()` to free its memory.
1646 * This function returns 0 if it succeeds, or one of the following
1647 * negative error codes:
1649 * :enum:`NGHTTP2_ERR_NOMEM`
1653 nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr);
1658 * Frees any resources allocated for |callbacks|. If |callbacks| is
1659 * ``NULL``, this function does nothing.
1662 nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks);
1667 * Sets callback function invoked when a session wants to send data to
1668 * the remote peer. This callback is not necessary if the application
1669 * uses solely `nghttp2_session_mem_send()` to serialize data to
1672 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback(
1673 nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback);
1678 * Sets callback function invoked when the a session wants to receive
1679 * data from the remote peer. This callback is not necessary if the
1680 * application uses solely `nghttp2_session_mem_recv()` to process
1683 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback(
1684 nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback);
1689 * Sets callback function invoked by `nghttp2_session_recv()` and
1690 * `nghttp2_session_mem_recv()` when a frame is received.
1692 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback(
1693 nghttp2_session_callbacks *cbs,
1694 nghttp2_on_frame_recv_callback on_frame_recv_callback);
1699 * Sets callback function invoked by `nghttp2_session_recv()` and
1700 * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is
1704 nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(
1705 nghttp2_session_callbacks *cbs,
1706 nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback);
1711 * Sets callback function invoked when a chunk of data in DATA frame
1714 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_data_chunk_recv_callback(
1715 nghttp2_session_callbacks *cbs,
1716 nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback);
1721 * Sets callback function invoked before a non-DATA frame is sent.
1723 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_before_frame_send_callback(
1724 nghttp2_session_callbacks *cbs,
1725 nghttp2_before_frame_send_callback before_frame_send_callback);
1730 * Sets callback function invoked after a frame is sent.
1732 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_send_callback(
1733 nghttp2_session_callbacks *cbs,
1734 nghttp2_on_frame_send_callback on_frame_send_callback);
1739 * Sets callback function invoked when a non-DATA frame is not sent
1740 * because of an error.
1742 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_not_send_callback(
1743 nghttp2_session_callbacks *cbs,
1744 nghttp2_on_frame_not_send_callback on_frame_not_send_callback);
1749 * Sets callback function invoked when the stream is closed.
1751 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_stream_close_callback(
1752 nghttp2_session_callbacks *cbs,
1753 nghttp2_on_stream_close_callback on_stream_close_callback);
1758 * Sets callback function invoked when the reception of header block
1759 * in HEADERS or PUSH_PROMISE is started.
1761 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_headers_callback(
1762 nghttp2_session_callbacks *cbs,
1763 nghttp2_on_begin_headers_callback on_begin_headers_callback);
1768 * Sets callback function invoked when a header name/value pair is
1771 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback(
1772 nghttp2_session_callbacks *cbs,
1773 nghttp2_on_header_callback on_header_callback);
1778 * Sets callback function invoked when the library asks application
1779 * how many padding bytes are required for the transmission of the
1782 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback(
1783 nghttp2_session_callbacks *cbs,
1784 nghttp2_select_padding_callback select_padding_callback);
1789 * Sets callback function determine the length allowed in
1790 * :type:`nghttp2_data_source_read_callback`.
1793 nghttp2_session_callbacks_set_data_source_read_length_callback(
1794 nghttp2_session_callbacks *cbs,
1795 nghttp2_data_source_read_length_callback data_source_read_length_callback);
1800 * Sets callback function invoked when a frame header is received.
1802 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_frame_callback(
1803 nghttp2_session_callbacks *cbs,
1804 nghttp2_on_begin_frame_callback on_begin_frame_callback);
1809 * Sets callback function invoked when
1810 * :enum:`NGHTTP2_DATA_FLAG_NO_COPY` is used in
1811 * :type:`nghttp2_data_source_read_callback` to avoid data copy.
1813 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_data_callback(
1814 nghttp2_session_callbacks *cbs,
1815 nghttp2_send_data_callback send_data_callback);
1820 * Custom memory allocator to replace malloc(). The |mem_user_data|
1821 * is the mem_user_data member of :type:`nghttp2_mem` structure.
1823 typedef void *(*nghttp2_malloc)(size_t size, void *mem_user_data);
1828 * Custom memory allocator to replace free(). The |mem_user_data| is
1829 * the mem_user_data member of :type:`nghttp2_mem` structure.
1831 typedef void (*nghttp2_free)(void *ptr, void *mem_user_data);
1836 * Custom memory allocator to replace calloc(). The |mem_user_data|
1837 * is the mem_user_data member of :type:`nghttp2_mem` structure.
1839 typedef void *(*nghttp2_calloc)(size_t nmemb, size_t size, void *mem_user_data);
1844 * Custom memory allocator to replace realloc(). The |mem_user_data|
1845 * is the mem_user_data member of :type:`nghttp2_mem` structure.
1847 typedef void *(*nghttp2_realloc)(void *ptr, size_t size, void *mem_user_data);
1852 * Custom memory allocator functions and user defined pointer. The
1853 * |mem_user_data| member is passed to each allocator function. This
1854 * can be used, for example, to achieve per-session memory pool.
1856 * In the following example code, ``my_malloc``, ``my_free``,
1857 * ``my_calloc`` and ``my_realloc`` are the replacement of the
1858 * standard allocators ``malloc``, ``free``, ``calloc`` and
1859 * ``realloc`` respectively::
1861 * void *my_malloc_cb(size_t size, void *mem_user_data) {
1862 * return my_malloc(size);
1865 * void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); }
1867 * void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) {
1868 * return my_calloc(nmemb, size);
1871 * void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) {
1872 * return my_realloc(ptr, size);
1875 * void session_new() {
1876 * nghttp2_session *session;
1877 * nghttp2_session_callbacks *callbacks;
1878 * nghttp2_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb,
1883 * nghttp2_session_client_new3(&session, callbacks, NULL, NULL, &mem);
1890 * An arbitrary user supplied data. This is passed to each
1891 * allocator function.
1893 void *mem_user_data;
1895 * Custom allocator function to replace malloc().
1897 nghttp2_malloc malloc;
1899 * Custom allocator function to replace free().
1903 * Custom allocator function to replace calloc().
1905 nghttp2_calloc calloc;
1907 * Custom allocator function to replace realloc().
1909 nghttp2_realloc realloc;
1912 struct nghttp2_option;
1917 * Configuration options for :type:`nghttp2_session`. The details of
1918 * this structure are intentionally hidden from the public API.
1920 typedef struct nghttp2_option nghttp2_option;
1925 * Initializes |*option_ptr| with default values.
1927 * When the application finished using this object, it can use
1928 * `nghttp2_option_del()` to free its memory.
1930 * This function returns 0 if it succeeds, or one of the following
1931 * negative error codes:
1933 * :enum:`NGHTTP2_ERR_NOMEM`
1936 NGHTTP2_EXTERN int nghttp2_option_new(nghttp2_option **option_ptr);
1941 * Frees any resources allocated for |option|. If |option| is
1942 * ``NULL``, this function does nothing.
1944 NGHTTP2_EXTERN void nghttp2_option_del(nghttp2_option *option);
1949 * This option prevents the library from sending WINDOW_UPDATE for a
1950 * connection automatically. If this option is set to nonzero, the
1951 * library won't send WINDOW_UPDATE for DATA until application calls
1952 * `nghttp2_session_consume()` to indicate the consumed amount of
1953 * data. Don't use `nghttp2_submit_window_update()` for this purpose.
1954 * By default, this option is set to zero.
1957 nghttp2_option_set_no_auto_window_update(nghttp2_option *option, int val);
1962 * This option sets the SETTINGS_MAX_CONCURRENT_STREAMS value of
1963 * remote endpoint as if it is received in SETTINGS frame. Without
1964 * specifying this option, before the local endpoint receives
1965 * SETTINGS_MAX_CONCURRENT_STREAMS in SETTINGS frame from remote
1966 * endpoint, SETTINGS_MAX_CONCURRENT_STREAMS is unlimited. This may
1967 * cause problem if local endpoint submits lots of requests initially
1968 * and sending them at once to the remote peer may lead to the
1969 * rejection of some requests. Specifying this option to the sensible
1970 * value, say 100, may avoid this kind of issue. This value will be
1971 * overwritten if the local endpoint receives
1972 * SETTINGS_MAX_CONCURRENT_STREAMS from the remote endpoint.
1975 nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option,
1981 * By default, nghttp2 library, if configured as server, requires
1982 * first 24 bytes of client magic byte string (MAGIC). In most cases,
1983 * this will simplify the implementation of server. But sometimes
1984 * server may want to detect the application protocol based on first
1985 * few bytes on clear text communication.
1987 * If this option is used with nonzero |val|, nghttp2 library does not
1988 * handle MAGIC. It still checks following SETTINGS frame. This
1989 * means that applications should deal with MAGIC by themselves.
1991 * If this option is not used or used with zero value, if MAGIC does
1992 * not match :macro:`NGHTTP2_CLIENT_MAGIC`, `nghttp2_session_recv()`
1993 * and `nghttp2_session_mem_recv()` will return error
1994 * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`, which is fatal error.
1997 nghttp2_option_set_no_recv_client_magic(nghttp2_option *option, int val);
2002 * By default, nghttp2 library enforces subset of HTTP Messaging rules
2003 * described in `HTTP/2 specification, section 8
2004 * <https://tools.ietf.org/html/rfc7540#section-8>`_. See
2005 * :ref:`http-messaging` section for details. For those applications
2006 * who use nghttp2 library as non-HTTP use, give nonzero to |val| to
2007 * disable this enforcement.
2009 NGHTTP2_EXTERN void nghttp2_option_set_no_http_messaging(nghttp2_option *option,
2015 * Initializes |*session_ptr| for client use. The all members of
2016 * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|
2017 * does not store |callbacks|. The |user_data| is an arbitrary user
2018 * supplied data, which will be passed to the callback functions.
2020 * The :type:`nghttp2_send_callback` must be specified. If the
2021 * application code uses `nghttp2_session_recv()`, the
2022 * :type:`nghttp2_recv_callback` must be specified. The other members
2023 * of |callbacks| can be ``NULL``.
2025 * If this function fails, |*session_ptr| is left untouched.
2027 * This function returns 0 if it succeeds, or one of the following
2028 * negative error codes:
2030 * :enum:`NGHTTP2_ERR_NOMEM`
2034 nghttp2_session_client_new(nghttp2_session **session_ptr,
2035 const nghttp2_session_callbacks *callbacks,
2041 * Initializes |*session_ptr| for server use. The all members of
2042 * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|
2043 * does not store |callbacks|. The |user_data| is an arbitrary user
2044 * supplied data, which will be passed to the callback functions.
2046 * The :type:`nghttp2_send_callback` must be specified. If the
2047 * application code uses `nghttp2_session_recv()`, the
2048 * :type:`nghttp2_recv_callback` must be specified. The other members
2049 * of |callbacks| can be ``NULL``.
2051 * If this function fails, |*session_ptr| is left untouched.
2053 * This function returns 0 if it succeeds, or one of the following
2054 * negative error codes:
2056 * :enum:`NGHTTP2_ERR_NOMEM`
2060 nghttp2_session_server_new(nghttp2_session **session_ptr,
2061 const nghttp2_session_callbacks *callbacks,
2067 * Like `nghttp2_session_client_new()`, but with additional options
2068 * specified in the |option|.
2070 * The |option| can be ``NULL`` and the call is equivalent to
2071 * `nghttp2_session_client_new()`.
2073 * This function does not take ownership |option|. The application is
2074 * responsible for freeing |option| if it finishes using the object.
2076 * The library code does not refer to |option| after this function
2079 * This function returns 0 if it succeeds, or one of the following
2080 * negative error codes:
2082 * :enum:`NGHTTP2_ERR_NOMEM`
2086 nghttp2_session_client_new2(nghttp2_session **session_ptr,
2087 const nghttp2_session_callbacks *callbacks,
2088 void *user_data, const nghttp2_option *option);
2093 * Like `nghttp2_session_server_new()`, but with additional options
2094 * specified in the |option|.
2096 * The |option| can be ``NULL`` and the call is equivalent to
2097 * `nghttp2_session_server_new()`.
2099 * This function does not take ownership |option|. The application is
2100 * responsible for freeing |option| if it finishes using the object.
2102 * The library code does not refer to |option| after this function
2105 * This function returns 0 if it succeeds, or one of the following
2106 * negative error codes:
2108 * :enum:`NGHTTP2_ERR_NOMEM`
2112 nghttp2_session_server_new2(nghttp2_session **session_ptr,
2113 const nghttp2_session_callbacks *callbacks,
2114 void *user_data, const nghttp2_option *option);
2119 * Like `nghttp2_session_client_new2()`, but with additional custom
2120 * memory allocator specified in the |mem|.
2122 * The |mem| can be ``NULL`` and the call is equivalent to
2123 * `nghttp2_session_client_new2()`.
2125 * This function does not take ownership |mem|. The application is
2126 * responsible for freeing |mem|.
2128 * The library code does not refer to |mem| pointer after this
2129 * function returns, so the application can safely free it.
2131 * This function returns 0 if it succeeds, or one of the following
2132 * negative error codes:
2134 * :enum:`NGHTTP2_ERR_NOMEM`
2137 NGHTTP2_EXTERN int nghttp2_session_client_new3(
2138 nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,
2139 void *user_data, const nghttp2_option *option, nghttp2_mem *mem);
2144 * Like `nghttp2_session_server_new2()`, but with additional custom
2145 * memory allocator specified in the |mem|.
2147 * The |mem| can be ``NULL`` and the call is equivalent to
2148 * `nghttp2_session_server_new2()`.
2150 * This function does not take ownership |mem|. The application is
2151 * responsible for freeing |mem|.
2153 * The library code does not refer to |mem| pointer after this
2154 * function returns, so the application can safely free it.
2156 * This function returns 0 if it succeeds, or one of the following
2157 * negative error codes:
2159 * :enum:`NGHTTP2_ERR_NOMEM`
2162 NGHTTP2_EXTERN int nghttp2_session_server_new3(
2163 nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,
2164 void *user_data, const nghttp2_option *option, nghttp2_mem *mem);
2169 * Frees any resources allocated for |session|. If |session| is
2170 * ``NULL``, this function does nothing.
2172 NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session);
2177 * Sends pending frames to the remote peer.
2179 * This function retrieves the highest prioritized frame from the
2180 * outbound queue and sends it to the remote peer. It does this as
2181 * many as possible until the user callback
2182 * :type:`nghttp2_send_callback` returns
2183 * :enum:`NGHTTP2_ERR_WOULDBLOCK` or the outbound queue becomes empty.
2184 * This function calls several callback functions which are passed
2185 * when initializing the |session|. Here is the simple time chart
2186 * which tells when each callback is invoked:
2188 * 1. Get the next frame to send from outbound queue.
2190 * 2. Prepare transmission of the frame.
2192 * 3. If the control frame cannot be sent because some preconditions
2193 * are not met (e.g., request HEADERS cannot be sent after GOAWAY),
2194 * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort
2195 * the following steps.
2197 * 4. If the frame is HEADERS, PUSH_PROMISE or DATA,
2198 * :type:`nghttp2_select_padding_callback` is invoked.
2200 * 5. If the frame is request HEADERS, the stream is opened here.
2202 * 6. :type:`nghttp2_before_frame_send_callback` is invoked.
2204 * 7. :type:`nghttp2_send_callback` is invoked one or more times to
2207 * 8. :type:`nghttp2_on_frame_send_callback` is invoked.
2209 * 9. If the transmission of the frame triggers closure of the stream,
2210 * the stream is closed and
2211 * :type:`nghttp2_on_stream_close_callback` is invoked.
2213 * This function returns 0 if it succeeds, or one of the following
2214 * negative error codes:
2216 * :enum:`NGHTTP2_ERR_NOMEM`
2218 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
2219 * The callback function failed.
2221 NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session);
2226 * Returns the serialized data to send.
2228 * This function behaves like `nghttp2_session_send()` except that it
2229 * does not use :type:`nghttp2_send_callback` to transmit data.
2230 * Instead, it assigns the pointer to the serialized data to the
2231 * |*data_ptr| and returns its length. The other callbacks are called
2232 * in the same way as they are in `nghttp2_session_send()`.
2234 * If no data is available to send, this function returns 0.
2236 * This function may not return all serialized data in one invocation.
2237 * To get all data, call this function repeatedly until it returns 0
2238 * or one of negative error codes.
2240 * The assigned |*data_ptr| is valid until the next call of
2241 * `nghttp2_session_mem_send()` or `nghttp2_session_send()`.
2243 * The caller must send all data before sending the next chunk of
2246 * This function returns the length of the data pointed by the
2247 * |*data_ptr| if it succeeds, or one of the following negative error
2250 * :enum:`NGHTTP2_ERR_NOMEM`
2253 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session,
2254 const uint8_t **data_ptr);
2259 * Receives frames from the remote peer.
2261 * This function receives as many frames as possible until the user
2262 * callback :type:`nghttp2_recv_callback` returns
2263 * :enum:`NGHTTP2_ERR_WOULDBLOCK`. This function calls several
2264 * callback functions which are passed when initializing the
2265 * |session|. Here is the simple time chart which tells when each
2266 * callback is invoked:
2268 * 1. :type:`nghttp2_recv_callback` is invoked one or more times to
2269 * receive frame header.
2271 * 2. When frame header is received,
2272 * :type:`nghttp2_on_begin_frame_callback` is invoked.
2274 * 3. If the frame is DATA frame:
2276 * 1. :type:`nghttp2_recv_callback` is invoked to receive DATA
2277 * payload. For each chunk of data,
2278 * :type:`nghttp2_on_data_chunk_recv_callback` is invoked.
2280 * 2. If one DATA frame is completely received,
2281 * :type:`nghttp2_on_frame_recv_callback` is invoked. If the
2282 * reception of the frame triggers the closure of the stream,
2283 * :type:`nghttp2_on_stream_close_callback` is invoked.
2285 * 4. If the frame is the control frame:
2287 * 1. :type:`nghttp2_recv_callback` is invoked one or more times to
2288 * receive whole frame.
2290 * 2. If the received frame is valid, then following actions are
2291 * taken. If the frame is either HEADERS or PUSH_PROMISE,
2292 * :type:`nghttp2_on_begin_headers_callback` is invoked. Then
2293 * :type:`nghttp2_on_header_callback` is invoked for each header
2294 * name/value pair. After all name/value pairs are emitted
2295 * successfully, :type:`nghttp2_on_frame_recv_callback` is
2296 * invoked. For other frames,
2297 * :type:`nghttp2_on_frame_recv_callback` is invoked. If the
2298 * reception of the frame triggers the closure of the stream,
2299 * :type:`nghttp2_on_stream_close_callback` is invoked.
2301 * 3. If the received frame is unpacked but is interpreted as
2302 * invalid, :type:`nghttp2_on_invalid_frame_recv_callback` is
2305 * This function returns 0 if it succeeds, or one of the following
2306 * negative error codes:
2308 * :enum:`NGHTTP2_ERR_EOF`
2309 * The remote peer did shutdown on the connection.
2310 * :enum:`NGHTTP2_ERR_NOMEM`
2312 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
2313 * The callback function failed.
2314 * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`
2315 * Invalid client magic was detected. This error only returns
2316 * when |session| was configured as server and
2317 * `nghttp2_option_set_no_recv_client_magic()` is not used with
2320 NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session);
2325 * Processes data |in| as an input from the remote endpoint. The
2326 * |inlen| indicates the number of bytes in the |in|.
2328 * This function behaves like `nghttp2_session_recv()` except that it
2329 * does not use :type:`nghttp2_recv_callback` to receive data; the
2330 * |in| is the only data for the invocation of this function. If all
2331 * bytes are processed, this function returns. The other callbacks
2332 * are called in the same way as they are in `nghttp2_session_recv()`.
2334 * In the current implementation, this function always tries to
2335 * processes all input data unless either an error occurs or
2336 * :enum:`NGHTTP2_ERR_PAUSE` is returned from
2337 * :type:`nghttp2_on_header_callback` or
2338 * :type:`nghttp2_on_data_chunk_recv_callback`. If
2339 * :enum:`NGHTTP2_ERR_PAUSE` is used, the return value includes the
2340 * number of bytes which was used to produce the data or frame for the
2343 * This function returns the number of processed bytes, or one of the
2344 * following negative error codes:
2346 * :enum:`NGHTTP2_ERR_NOMEM`
2348 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
2349 * The callback function failed.
2350 * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`
2351 * Invalid client magic was detected. This error only returns
2352 * when |session| was configured as server and
2353 * `nghttp2_option_set_no_recv_client_magic()` is not used with
2356 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
2363 * Puts back previously deferred DATA frame in the stream |stream_id|
2364 * to the outbound queue.
2366 * This function returns 0 if it succeeds, or one of the following
2367 * negative error codes:
2369 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
2370 * The stream does not exist; or no deferred data exist.
2371 * :enum:`NGHTTP2_ERR_NOMEM`
2374 NGHTTP2_EXTERN int nghttp2_session_resume_data(nghttp2_session *session,
2380 * Returns nonzero value if |session| wants to receive data from the
2383 * If both `nghttp2_session_want_read()` and
2384 * `nghttp2_session_want_write()` return 0, the application should
2385 * drop the connection.
2387 NGHTTP2_EXTERN int nghttp2_session_want_read(nghttp2_session *session);
2392 * Returns nonzero value if |session| wants to send data to the remote
2395 * If both `nghttp2_session_want_read()` and
2396 * `nghttp2_session_want_write()` return 0, the application should
2397 * drop the connection.
2399 NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session);
2404 * Returns stream_user_data for the stream |stream_id|. The
2405 * stream_user_data is provided by `nghttp2_submit_request()`,
2406 * `nghttp2_submit_headers()` or
2407 * `nghttp2_session_set_stream_user_data()`. Unless it is set using
2408 * `nghttp2_session_set_stream_user_data()`, if the stream is
2409 * initiated by the remote endpoint, stream_user_data is always
2410 * ``NULL``. If the stream does not exist, this function returns
2413 NGHTTP2_EXTERN void *
2414 nghttp2_session_get_stream_user_data(nghttp2_session *session,
2420 * Sets the |stream_user_data| to the stream denoted by the
2421 * |stream_id|. If a stream user data is already set to the stream,
2422 * it is replaced with the |stream_user_data|. It is valid to specify
2423 * ``NULL`` in the |stream_user_data|, which nullifies the associated
2426 * It is valid to set the |stream_user_data| to the stream reserved by
2427 * PUSH_PROMISE frame.
2429 * This function returns 0 if it succeeds, or one of following
2430 * negative error codes:
2432 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
2433 * The stream does not exist
2436 nghttp2_session_set_stream_user_data(nghttp2_session *session,
2437 int32_t stream_id, void *stream_user_data);
2442 * Returns the number of frames in the outbound queue. This does not
2443 * include the deferred DATA frames.
2445 NGHTTP2_EXTERN size_t
2446 nghttp2_session_get_outbound_queue_size(nghttp2_session *session);
2451 * Returns the number of DATA payload in bytes received without
2452 * WINDOW_UPDATE transmission for the stream |stream_id|. The local
2453 * (receive) window size can be adjusted by
2454 * `nghttp2_submit_window_update()`. This function takes into account
2455 * that and returns effective data length. In particular, if the
2456 * local window size is reduced by submitting negative
2457 * window_size_increment with `nghttp2_submit_window_update()`, this
2458 * function returns the number of bytes less than actually received.
2460 * This function returns -1 if it fails.
2462 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_recv_data_length(
2463 nghttp2_session *session, int32_t stream_id);
2468 * Returns the local (receive) window size for the stream |stream_id|.
2469 * The local window size can be adjusted by
2470 * `nghttp2_submit_window_update()`. This function takes into account
2471 * that and returns effective window size.
2473 * This function returns -1 if it fails.
2475 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_local_window_size(
2476 nghttp2_session *session, int32_t stream_id);
2481 * Returns the number of DATA payload in bytes received without
2482 * WINDOW_UPDATE transmission for a connection. The local (receive)
2483 * window size can be adjusted by `nghttp2_submit_window_update()`.
2484 * This function takes into account that and returns effective data
2485 * length. In particular, if the local window size is reduced by
2486 * submitting negative window_size_increment with
2487 * `nghttp2_submit_window_update()`, this function returns the number
2488 * of bytes less than actually received.
2490 * This function returns -1 if it fails.
2492 NGHTTP2_EXTERN int32_t
2493 nghttp2_session_get_effective_recv_data_length(nghttp2_session *session);
2498 * Returns the local (receive) window size for a connection. The
2499 * local window size can be adjusted by
2500 * `nghttp2_submit_window_update()`. This function takes into account
2501 * that and returns effective window size.
2503 * This function returns -1 if it fails.
2505 NGHTTP2_EXTERN int32_t
2506 nghttp2_session_get_effective_local_window_size(nghttp2_session *session);
2511 * Returns the remote window size for a given stream |stream_id|.
2513 * This is the amount of flow-controlled payload (e.g., DATA) that the
2514 * local endpoint can send without stream level WINDOW_UPDATE. There
2515 * is also connection level flow control, so the effective size of
2516 * payload that the local endpoint can actually send is
2517 * min(`nghttp2_session_get_stream_remote_window_size()`,
2518 * `nghttp2_session_get_remote_window_size()`).
2520 * This function returns -1 if it fails.
2522 NGHTTP2_EXTERN int32_t
2523 nghttp2_session_get_stream_remote_window_size(nghttp2_session *session,
2529 * Returns the remote window size for a connection.
2531 * This function always succeeds.
2533 NGHTTP2_EXTERN int32_t
2534 nghttp2_session_get_remote_window_size(nghttp2_session *session);
2539 * Returns 1 if local peer half closed the given stream |stream_id|.
2540 * Returns 0 if it did not. Returns -1 if no such stream exists.
2543 nghttp2_session_get_stream_local_close(nghttp2_session *session,
2549 * Returns 1 if remote peer half closed the given stream |stream_id|.
2550 * Returns 0 if it did not. Returns -1 if no such stream exists.
2553 nghttp2_session_get_stream_remote_close(nghttp2_session *session,
2559 * Signals the session so that the connection should be terminated.
2561 * The last stream ID is the minimum value between the stream ID of a
2562 * stream for which :type:`nghttp2_on_frame_recv_callback` was called
2563 * most recently and the last stream ID we have sent to the peer
2566 * The |error_code| is the error code of this GOAWAY frame. The
2567 * pre-defined error code is one of :enum:`nghttp2_error_code`.
2569 * After the transmission, both `nghttp2_session_want_read()` and
2570 * `nghttp2_session_want_write()` return 0.
2572 * This function should be called when the connection should be
2573 * terminated after sending GOAWAY. If the remaining streams should
2574 * be processed after GOAWAY, use `nghttp2_submit_goaway()` instead.
2576 * This function returns 0 if it succeeds, or one of the following
2577 * negative error codes:
2579 * :enum:`NGHTTP2_ERR_NOMEM`
2582 NGHTTP2_EXTERN int nghttp2_session_terminate_session(nghttp2_session *session,
2583 uint32_t error_code);
2588 * Signals the session so that the connection should be terminated.
2590 * This function behaves like `nghttp2_session_terminate_session()`,
2591 * but the last stream ID can be specified by the application for fine
2592 * grained control of stream. The HTTP/2 specification does not allow
2593 * last_stream_id to be increased. So the actual value sent as
2594 * last_stream_id is the minimum value between the given
2595 * |last_stream_id| and the last_stream_id we have previously sent to
2598 * The |last_stream_id| is peer's stream ID or 0. So if |session| is
2599 * initialized as client, |last_stream_id| must be even or 0. If
2600 * |session| is initialized as server, |last_stream_id| must be odd or
2603 * This function returns 0 if it succeeds, or one of the following
2604 * negative error codes:
2606 * :enum:`NGHTTP2_ERR_NOMEM`
2608 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
2609 * The |last_stream_id| is invalid.
2611 NGHTTP2_EXTERN int nghttp2_session_terminate_session2(nghttp2_session *session,
2612 int32_t last_stream_id,
2613 uint32_t error_code);
2618 * Signals to the client that the server started graceful shutdown
2621 * This function is only usable for server. If this function is
2622 * called with client side session, this function returns
2623 * :enum:`NGHTTP2_ERR_INVALID_STATE`.
2625 * To gracefully shutdown HTTP/2 session, server should call this
2626 * function to send GOAWAY with last_stream_id (1u << 31) - 1. And
2627 * after some delay (e.g., 1 RTT), send another GOAWAY with the stream
2628 * ID that the server has some processing using
2629 * `nghttp2_submit_goaway()`. See also
2630 * `nghttp2_session_get_last_proc_stream_id()`.
2632 * Unlike `nghttp2_submit_goaway()`, this function just sends GOAWAY
2633 * and does nothing more. This is a mere indication to the client
2634 * that session shutdown is imminent. The application should call
2635 * `nghttp2_submit_goaway()` with appropriate last_stream_id after
2638 * If one or more GOAWAY frame have been already sent by either
2639 * `nghttp2_submit_goaway()` or `nghttp2_session_terminate_session()`,
2640 * this function has no effect.
2642 * This function returns 0 if it succeeds, or one of the following
2643 * negative error codes:
2645 * :enum:`NGHTTP2_ERR_NOMEM`
2647 * :enum:`NGHTTP2_ERR_INVALID_STATE`
2648 * The |session| is initialized as client.
2650 NGHTTP2_EXTERN int nghttp2_submit_shutdown_notice(nghttp2_session *session);
2655 * Returns the value of SETTINGS |id| notified by a remote endpoint.
2656 * The |id| must be one of values defined in
2657 * :enum:`nghttp2_settings_id`.
2659 NGHTTP2_EXTERN uint32_t
2660 nghttp2_session_get_remote_settings(nghttp2_session *session,
2661 nghttp2_settings_id id);
2666 * Tells the |session| that next stream ID is |next_stream_id|. The
2667 * |next_stream_id| must be equal or greater than the value returned
2668 * by `nghttp2_session_get_next_stream_id()`.
2670 * This function returns 0 if it succeeds, or one of the following
2671 * negative error codes:
2673 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
2674 * The |next_stream_id| is strictly less than the value
2675 * `nghttp2_session_get_next_stream_id()` returns; or
2676 * |next_stream_id| is invalid (e.g., even integer for client, or
2677 * odd integer for server).
2679 NGHTTP2_EXTERN int nghttp2_session_set_next_stream_id(nghttp2_session *session,
2680 int32_t next_stream_id);
2685 * Returns the next outgoing stream ID. Notice that return type is
2686 * uint32_t. If we run out of stream ID for this session, this
2687 * function returns 1 << 31.
2689 NGHTTP2_EXTERN uint32_t
2690 nghttp2_session_get_next_stream_id(nghttp2_session *session);
2695 * Tells the |session| that |size| bytes for a stream denoted by
2696 * |stream_id| were consumed by application and are ready to
2697 * WINDOW_UPDATE. The consumed bytes are counted towards both
2698 * connection and stream level WINDOW_UPDATE (see
2699 * `nghttp2_session_consume_connection()` and
2700 * `nghttp2_session_consume_stream()` to update consumption
2701 * independently). This function is intended to be used without
2702 * automatic window update (see
2703 * `nghttp2_option_set_no_auto_window_update()`).
2705 * This function returns 0 if it succeeds, or one of the following
2706 * negative error codes:
2708 * :enum:`NGHTTP2_ERR_NOMEM`
2710 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
2711 * The |stream_id| is 0.
2712 * :enum:`NGHTTP2_ERR_INVALID_STATE`
2713 * Automatic WINDOW_UPDATE is not disabled.
2715 NGHTTP2_EXTERN int nghttp2_session_consume(nghttp2_session *session,
2716 int32_t stream_id, size_t size);
2721 * Like `nghttp2_session_consume()`, but this only tells library that
2722 * |size| bytes were consumed only for connection level. Note that
2723 * HTTP/2 maintains connection and stream level flow control windows
2726 * This function returns 0 if it succeeds, or one of the following
2727 * negative error codes:
2729 * :enum:`NGHTTP2_ERR_NOMEM`
2731 * :enum:`NGHTTP2_ERR_INVALID_STATE`
2732 * Automatic WINDOW_UPDATE is not disabled.
2734 NGHTTP2_EXTERN int nghttp2_session_consume_connection(nghttp2_session *session,
2740 * Like `nghttp2_session_consume()`, but this only tells library that
2741 * |size| bytes were consumed only for stream denoted by |stream_id|.
2742 * Note that HTTP/2 maintains connection and stream level flow control
2743 * windows independently.
2745 * This function returns 0 if it succeeds, or one of the following
2746 * negative error codes:
2748 * :enum:`NGHTTP2_ERR_NOMEM`
2750 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
2751 * The |stream_id| is 0.
2752 * :enum:`NGHTTP2_ERR_INVALID_STATE`
2753 * Automatic WINDOW_UPDATE is not disabled.
2755 NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session,
2762 * Performs post-process of HTTP Upgrade request. This function can
2763 * be called from both client and server, but the behavior is very
2764 * different in each other.
2766 * If called from client side, the |settings_payload| must be the
2767 * value sent in ``HTTP2-Settings`` header field and must be decoded
2768 * by base64url decoder. The |settings_payloadlen| is the length of
2769 * |settings_payload|. The |settings_payload| is unpacked and its
2770 * setting values will be submitted using `nghttp2_submit_settings()`.
2771 * This means that the client application code does not need to submit
2772 * SETTINGS by itself. The stream with stream ID=1 is opened and the
2773 * |stream_user_data| is used for its stream_user_data. The opened
2774 * stream becomes half-closed (local) state.
2776 * If called from server side, the |settings_payload| must be the
2777 * value received in ``HTTP2-Settings`` header field and must be
2778 * decoded by base64url decoder. The |settings_payloadlen| is the
2779 * length of |settings_payload|. It is treated as if the SETTINGS
2780 * frame with that payload is received. Thus, callback functions for
2781 * the reception of SETTINGS frame will be invoked. The stream with
2782 * stream ID=1 is opened. The |stream_user_data| is ignored. The
2783 * opened stream becomes half-closed (remote).
2785 * This function returns 0 if it succeeds, or one of the following
2786 * negative error codes:
2788 * :enum:`NGHTTP2_ERR_NOMEM`
2790 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
2791 * The |settings_payload| is badly formed.
2792 * :enum:`NGHTTP2_ERR_PROTO`
2793 * The stream ID 1 is already used or closed; or is not available.
2795 NGHTTP2_EXTERN int nghttp2_session_upgrade(nghttp2_session *session,
2796 const uint8_t *settings_payload,
2797 size_t settings_payloadlen,
2798 void *stream_user_data);
2803 * Serializes the SETTINGS values |iv| in the |buf|. The size of the
2804 * |buf| is specified by |buflen|. The number of entries in the |iv|
2805 * array is given by |niv|. The required space in |buf| for the |niv|
2806 * entries is ``8*niv`` bytes and if the given buffer is too small, an
2807 * error is returned. This function is used mainly for creating a
2808 * SETTINGS payload to be sent with the ``HTTP2-Settings`` header
2809 * field in an HTTP Upgrade request. The data written in |buf| is NOT
2810 * base64url encoded and the application is responsible for encoding.
2812 * This function returns the number of bytes written in |buf|, or one
2813 * of the following negative error codes:
2815 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
2816 * The |iv| contains duplicate settings ID or invalid value.
2818 * :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`
2819 * The provided |buflen| size is too small to hold the output.
2821 NGHTTP2_EXTERN ssize_t
2822 nghttp2_pack_settings_payload(uint8_t *buf, size_t buflen,
2823 const nghttp2_settings_entry *iv, size_t niv);
2828 * Returns string describing the |lib_error_code|. The
2829 * |lib_error_code| must be one of the :enum:`nghttp2_error`.
2831 NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code);
2836 * Initializes |pri_spec| with the |stream_id| of the stream to depend
2837 * on with |weight| and its exclusive flag. If |exclusive| is
2838 * nonzero, exclusive flag is set.
2840 * The |weight| must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
2841 * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive.
2843 NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec,
2845 int32_t weight, int exclusive);
2850 * Initializes |pri_spec| with the default values. The default values
2851 * are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and
2855 nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec);
2860 * Returns nonzero if the |pri_spec| is filled with default values.
2863 nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec);
2868 * Submits HEADERS frame and optionally one or more DATA frames.
2870 * The |pri_spec| is priority specification of this request. ``NULL``
2871 * means the default priority (see
2872 * `nghttp2_priority_spec_default_init()`). To specify the priority,
2873 * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``,
2874 * this function will copy its data members.
2876 * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
2877 * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is
2878 * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
2879 * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
2880 * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
2882 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
2883 * |nvlen| elements. The application is responsible to include
2884 * required pseudo-header fields (header field whose name starts with
2885 * ":") in |nva| and must place pseudo-headers before regular header
2888 * This function creates copies of all name/value pairs in |nva|. It
2889 * also lower-cases all names in |nva|. The order of elements in
2890 * |nva| is preserved.
2892 * HTTP/2 specification has requirement about header fields in the
2893 * request HEADERS. See the specification for more details.
2895 * If |data_prd| is not ``NULL``, it provides data which will be sent
2896 * in subsequent DATA frames. In this case, a method that allows
2897 * request message bodies
2898 * (https://tools.ietf.org/html/rfc7231#section-4) must be specified
2899 * with ``:method`` key in |nva| (e.g. ``POST``). This function does
2900 * not take ownership of the |data_prd|. The function copies the
2901 * members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have
2902 * END_STREAM set. The |stream_user_data| is data associated to the
2903 * stream opened by this request and can be an arbitrary pointer,
2904 * which can be retrieved later by
2905 * `nghttp2_session_get_stream_user_data()`.
2907 * This function returns assigned stream ID if it succeeds, or one of
2908 * the following negative error codes:
2910 * :enum:`NGHTTP2_ERR_NOMEM`
2912 * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
2913 * No stream ID is available because maximum stream ID was
2918 * This function returns assigned stream ID if it succeeds. But
2919 * that stream is not opened yet. The application must not submit
2920 * frame to that stream ID before
2921 * :type:`nghttp2_before_frame_send_callback` is called for this
2925 NGHTTP2_EXTERN int32_t
2926 nghttp2_submit_request(nghttp2_session *session,
2927 const nghttp2_priority_spec *pri_spec,
2928 const nghttp2_nv *nva, size_t nvlen,
2929 const nghttp2_data_provider *data_prd,
2930 void *stream_user_data);
2935 * Submits response HEADERS frame and optionally one or more DATA
2936 * frames against the stream |stream_id|.
2938 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
2939 * |nvlen| elements. The application is responsible to include
2940 * required pseudo-header fields (header field whose name starts with
2941 * ":") in |nva| and must place pseudo-headers before regular header
2944 * This function creates copies of all name/value pairs in |nva|. It
2945 * also lower-cases all names in |nva|. The order of elements in
2946 * |nva| is preserved.
2948 * HTTP/2 specification has requirement about header fields in the
2949 * response HEADERS. See the specification for more details.
2951 * If |data_prd| is not ``NULL``, it provides data which will be sent
2952 * in subsequent DATA frames. This function does not take ownership
2953 * of the |data_prd|. The function copies the members of the
2954 * |data_prd|. If |data_prd| is ``NULL``, HEADERS will have
2955 * END_STREAM flag set.
2957 * This method can be used as normal HTTP response and push response.
2958 * When pushing a resource using this function, the |session| must be
2959 * configured using `nghttp2_session_server_new()` or its variants and
2960 * the target stream denoted by the |stream_id| must be reserved using
2961 * `nghttp2_submit_push_promise()`.
2963 * To send non-final response headers (e.g., HTTP status 101), don't
2964 * use this function because this function half-closes the outbound
2965 * stream. Instead, use `nghttp2_submit_headers()` for this purpose.
2967 * This function returns 0 if it succeeds, or one of the following
2968 * negative error codes:
2970 * :enum:`NGHTTP2_ERR_NOMEM`
2972 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
2973 * The |stream_id| is 0.
2977 * Calling this function twice for the same stream ID may lead to
2978 * program crash. It is generally considered to a programming error
2979 * to commit response twice.
2982 nghttp2_submit_response(nghttp2_session *session, int32_t stream_id,
2983 const nghttp2_nv *nva, size_t nvlen,
2984 const nghttp2_data_provider *data_prd);
2989 * Submits trailer HEADERS against the stream |stream_id|.
2991 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
2992 * |nvlen| elements. The application is responsible not to include
2993 * required pseudo-header fields (header field whose name starts with
2996 * This function creates copies of all name/value pairs in |nva|. It
2997 * also lower-cases all names in |nva|. The order of elements in
2998 * |nva| is preserved.
3000 * For server, trailer must be followed by response HEADERS or
3001 * response DATA. The library does not check that response HEADERS
3002 * has already sent and if `nghttp2_submit_trailer()` is called before
3003 * any response HEADERS submission (usually by
3004 * `nghttp2_submit_response()`), the content of |nva| will be sent as
3005 * reponse headers, which will result in error.
3007 * This function has the same effect with `nghttp2_submit_headers()`,
3008 * with flags = :enum:`NGHTTP2_FLAG_END_HEADERS` and both pri_spec and
3009 * stream_user_data to NULL.
3011 * To submit trailer after `nghttp2_submit_response()` is called, the
3012 * application has to specify :type:`nghttp2_data_provider` to
3013 * `nghttp2_submit_response()`. In side
3014 * :type:`nghttp2_data_source_read_callback`, when setting
3015 * :enum:`NGHTTP2_DATA_FLAG_EOF`, also set
3016 * :enum:`NGHTTP2_DATA_FLAG_NO_END_STREAM`. After that, the
3017 * application can send trailer using `nghttp2_submit_trailer()`.
3018 * `nghttp2_submit_trailer()` can be used inside
3019 * :type:`nghttp2_data_source_read_callback`.
3021 * This function returns 0 if it succeeds and |stream_id| is -1.
3022 * Otherwise, this function returns 0 if it succeeds, or one of the
3023 * following negative error codes:
3025 * :enum:`NGHTTP2_ERR_NOMEM`
3027 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3028 * The |stream_id| is 0.
3030 NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session,
3032 const nghttp2_nv *nva, size_t nvlen);
3037 * Submits HEADERS frame. The |flags| is bitwise OR of the
3040 * * :enum:`NGHTTP2_FLAG_END_STREAM`
3042 * If |flags| includes :enum:`NGHTTP2_FLAG_END_STREAM`, this frame has
3043 * END_STREAM flag set.
3045 * The library handles the CONTINUATION frame internally and it
3046 * correctly sets END_HEADERS to the last sequence of the PUSH_PROMISE
3047 * or CONTINUATION frame.
3049 * If the |stream_id| is -1, this frame is assumed as request (i.e.,
3050 * request HEADERS frame which opens new stream). In this case, the
3051 * assigned stream ID will be returned. Otherwise, specify stream ID
3054 * The |pri_spec| is priority specification of this request. ``NULL``
3055 * means the default priority (see
3056 * `nghttp2_priority_spec_default_init()`). To specify the priority,
3057 * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``,
3058 * this function will copy its data members.
3060 * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
3061 * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is
3062 * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
3063 * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
3064 * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
3066 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
3067 * |nvlen| elements. The application is responsible to include
3068 * required pseudo-header fields (header field whose name starts with
3069 * ":") in |nva| and must place pseudo-headers before regular header
3072 * This function creates copies of all name/value pairs in |nva|. It
3073 * also lower-cases all names in |nva|. The order of elements in
3074 * |nva| is preserved.
3076 * The |stream_user_data| is a pointer to an arbitrary data which is
3077 * associated to the stream this frame will open. Therefore it is
3078 * only used if this frame opens streams, in other words, it changes
3079 * stream state from idle or reserved to open.
3081 * This function is low-level in a sense that the application code can
3082 * specify flags directly. For usual HTTP request,
3083 * `nghttp2_submit_request()` is useful.
3085 * This function returns newly assigned stream ID if it succeeds and
3086 * |stream_id| is -1. Otherwise, this function returns 0 if it
3087 * succeeds, or one of the following negative error codes:
3089 * :enum:`NGHTTP2_ERR_NOMEM`
3091 * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
3092 * No stream ID is available because maximum stream ID was
3094 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3095 * The |stream_id| is 0.
3099 * This function returns assigned stream ID if it succeeds and
3100 * |stream_id| is -1. But that stream is not opened yet. The
3101 * application must not submit frame to that stream ID before
3102 * :type:`nghttp2_before_frame_send_callback` is called for this
3106 NGHTTP2_EXTERN int32_t
3107 nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
3109 const nghttp2_priority_spec *pri_spec,
3110 const nghttp2_nv *nva, size_t nvlen,
3111 void *stream_user_data);
3116 * Submits one or more DATA frames to the stream |stream_id|. The
3117 * data to be sent are provided by |data_prd|. If |flags| contains
3118 * :enum:`NGHTTP2_FLAG_END_STREAM`, the last DATA frame has END_STREAM
3121 * This function does not take ownership of the |data_prd|. The
3122 * function copies the members of the |data_prd|.
3124 * This function returns 0 if it succeeds, or one of the following
3125 * negative error codes:
3127 * :enum:`NGHTTP2_ERR_NOMEM`
3129 * :enum:`NGHTTP2_ERR_DATA_EXIST`
3130 * DATA has been already submitted and not fully processed yet.
3131 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3132 * The |stream_id| is 0.
3133 * :enum:`NGHTTP2_ERR_STREAM_CLOSED`
3134 * The stream was alreay closed; or the |stream_id| is invalid.
3138 * Currently, only one data is allowed for a stream at a time.
3139 * Submitting data more than once before first data is finished
3140 * results in :enum:`NGHTTP2_ERR_DATA_EXIST` error code. The
3141 * earliest callback which tells that previous data is done is
3142 * :type:`nghttp2_on_frame_send_callback`. In side that callback,
3143 * new data can be submitted using `nghttp2_submit_data()`. Of
3144 * course, all data except for last one must not have
3145 * :enum:`NGHTTP2_FLAG_END_STREAM` flag set in |flags|.
3147 NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
3149 const nghttp2_data_provider *data_prd);
3154 * Submits PRIORITY frame to change the priority of stream |stream_id|
3155 * to the priority specification |pri_spec|.
3157 * The |flags| is currently ignored and should be
3158 * :enum:`NGHTTP2_FLAG_NONE`.
3160 * The |pri_spec| is priority specification of this request. ``NULL``
3161 * is not allowed for this function. To specify the priority, use
3162 * `nghttp2_priority_spec_init()`. This function will copy its data
3165 * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
3166 * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is
3167 * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
3168 * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
3169 * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
3171 * This function returns 0 if it succeeds, or one of the following
3172 * negative error codes:
3174 * :enum:`NGHTTP2_ERR_NOMEM`
3176 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3177 * The |stream_id| is 0; or the |pri_spec| is NULL; or trying to
3181 nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,
3183 const nghttp2_priority_spec *pri_spec);
3188 * Submits RST_STREAM frame to cancel/reject the stream |stream_id|
3189 * with the error code |error_code|.
3191 * The pre-defined error code is one of :enum:`nghttp2_error_code`.
3193 * The |flags| is currently ignored and should be
3194 * :enum:`NGHTTP2_FLAG_NONE`.
3196 * This function returns 0 if it succeeds, or one of the following
3197 * negative error codes:
3199 * :enum:`NGHTTP2_ERR_NOMEM`
3201 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3202 * The |stream_id| is 0.
3204 NGHTTP2_EXTERN int nghttp2_submit_rst_stream(nghttp2_session *session,
3205 uint8_t flags, int32_t stream_id,
3206 uint32_t error_code);
3211 * Stores local settings and submits SETTINGS frame. The |iv| is the
3212 * pointer to the array of :type:`nghttp2_settings_entry`. The |niv|
3213 * indicates the number of :type:`nghttp2_settings_entry`.
3215 * The |flags| is currently ignored and should be
3216 * :enum:`NGHTTP2_FLAG_NONE`.
3218 * This function does not take ownership of the |iv|. This function
3219 * copies all the elements in the |iv|.
3221 * While updating individual stream's local window size, if the window
3222 * size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE,
3223 * RST_STREAM is issued against such a stream.
3225 * SETTINGS with :enum:`NGHTTP2_FLAG_ACK` is automatically submitted
3226 * by the library and application could not send it at its will.
3228 * This function returns 0 if it succeeds, or one of the following
3229 * negative error codes:
3231 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3232 * The |iv| contains invalid value (e.g., initial window size
3233 * strictly greater than (1 << 31) - 1.
3234 * :enum:`NGHTTP2_ERR_TOO_MANY_INFLIGHT_SETTINGS`
3235 * There is already another in-flight SETTINGS. Note that the
3236 * current implementation only allows 1 in-flight SETTINGS frame
3237 * without ACK flag set.
3238 * :enum:`NGHTTP2_ERR_NOMEM`
3241 NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session,
3243 const nghttp2_settings_entry *iv,
3249 * Submits PUSH_PROMISE frame.
3251 * The |flags| is currently ignored. The library handles the
3252 * CONTINUATION frame internally and it correctly sets END_HEADERS to
3253 * the last sequence of the PUSH_PROMISE or CONTINUATION frame.
3255 * The |stream_id| must be client initiated stream ID.
3257 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
3258 * |nvlen| elements. The application is responsible to include
3259 * required pseudo-header fields (header field whose name starts with
3260 * ":") in |nva| and must place pseudo-headers before regular header
3263 * This function creates copies of all name/value pairs in |nva|. It
3264 * also lower-cases all names in |nva|. The order of elements in
3265 * |nva| is preserved.
3267 * The |promised_stream_user_data| is a pointer to an arbitrary data
3268 * which is associated to the promised stream this frame will open and
3269 * make it in reserved state. It is available using
3270 * `nghttp2_session_get_stream_user_data()`. The application can
3271 * access it in :type:`nghttp2_before_frame_send_callback` and
3272 * :type:`nghttp2_on_frame_send_callback` of this frame.
3274 * The client side is not allowed to use this function.
3276 * To submit response headers and data, use
3277 * `nghttp2_submit_response()`.
3279 * This function returns assigned promised stream ID if it succeeds,
3280 * or one of the following negative error codes:
3282 * :enum:`NGHTTP2_ERR_NOMEM`
3284 * :enum:`NGHTTP2_ERR_PROTO`
3285 * This function was invoked when |session| is initialized as
3287 * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
3288 * No stream ID is available because maximum stream ID was
3290 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3291 * The |stream_id| is 0; The |stream_id| does not designate stream
3292 * that peer initiated.
3296 * This function returns assigned promised stream ID if it succeeds.
3297 * But that stream is not opened yet. The application must not
3298 * submit frame to that stream ID before
3299 * :type:`nghttp2_before_frame_send_callback` is called for this
3303 NGHTTP2_EXTERN int32_t
3304 nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
3305 int32_t stream_id, const nghttp2_nv *nva,
3306 size_t nvlen, void *promised_stream_user_data);
3311 * Submits PING frame. You don't have to send PING back when you
3312 * received PING frame. The library automatically submits PING frame
3315 * The |flags| is currently ignored and should be
3316 * :enum:`NGHTTP2_FLAG_NONE`.
3318 * If the |opaque_data| is non ``NULL``, then it should point to the 8
3319 * bytes array of memory to specify opaque data to send with PING
3320 * frame. If the |opaque_data| is ``NULL``, zero-cleared 8 bytes will
3321 * be sent as opaque data.
3323 * This function returns 0 if it succeeds, or one of the following
3324 * negative error codes:
3326 * :enum:`NGHTTP2_ERR_NOMEM`
3329 NGHTTP2_EXTERN int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags,
3330 const uint8_t *opaque_data);
3335 * Submits GOAWAY frame with the last stream ID |last_stream_id| and
3336 * the error code |error_code|.
3338 * The pre-defined error code is one of :enum:`nghttp2_error_code`.
3340 * The |flags| is currently ignored and should be
3341 * :enum:`NGHTTP2_FLAG_NONE`.
3343 * The |last_stream_id| is peer's stream ID or 0. So if |session| is
3344 * initialized as client, |last_stream_id| must be even or 0. If
3345 * |session| is initialized as server, |last_stream_id| must be odd or
3348 * The HTTP/2 specification says last_stream_id must not be increased
3349 * from the value previously sent. So the actual value sent as
3350 * last_stream_id is the minimum value between the given
3351 * |last_stream_id| and the last_stream_id previously sent to the
3354 * If the |opaque_data| is not ``NULL`` and |opaque_data_len| is not
3355 * zero, those data will be sent as additional debug data. The
3356 * library makes a copy of the memory region pointed by |opaque_data|
3357 * with the length |opaque_data_len|, so the caller does not need to
3358 * keep this memory after the return of this function. If the
3359 * |opaque_data_len| is 0, the |opaque_data| could be ``NULL``.
3361 * After successful transmission of GOAWAY, following things happen.
3362 * All incoming streams having strictly more than |last_stream_id| are
3363 * closed. All incoming HEADERS which starts new stream are simply
3364 * ignored. After all active streams are handled, both
3365 * `nghttp2_session_want_read()` and `nghttp2_session_want_write()`
3366 * return 0 and the application can close session.
3368 * This function returns 0 if it succeeds, or one of the following
3369 * negative error codes:
3371 * :enum:`NGHTTP2_ERR_NOMEM`
3373 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3374 * The |opaque_data_len| is too large; the |last_stream_id| is
3377 NGHTTP2_EXTERN int nghttp2_submit_goaway(nghttp2_session *session,
3378 uint8_t flags, int32_t last_stream_id,
3379 uint32_t error_code,
3380 const uint8_t *opaque_data,
3381 size_t opaque_data_len);
3386 * Returns the last stream ID of a stream for which
3387 * :type:`nghttp2_on_frame_recv_callback` was invoked most recently.
3388 * The returned value can be used as last_stream_id parameter for
3389 * `nghttp2_submit_goaway()` and
3390 * `nghttp2_session_terminate_session2()`.
3392 * This function always succeeds.
3394 NGHTTP2_EXTERN int32_t
3395 nghttp2_session_get_last_proc_stream_id(nghttp2_session *session);
3400 * Submits WINDOW_UPDATE frame.
3402 * The |flags| is currently ignored and should be
3403 * :enum:`NGHTTP2_FLAG_NONE`.
3405 * The |stream_id| is the stream ID to send this WINDOW_UPDATE. To
3406 * send connection level WINDOW_UPDATE, specify 0 to |stream_id|.
3408 * If the |window_size_increment| is positive, the WINDOW_UPDATE with
3409 * that value as window_size_increment is queued. If the
3410 * |window_size_increment| is larger than the received bytes from the
3411 * remote endpoint, the local window size is increased by that
3414 * If the |window_size_increment| is negative, the local window size
3415 * is decreased by -|window_size_increment|. If automatic
3416 * WINDOW_UPDATE is enabled
3417 * (`nghttp2_option_set_no_auto_window_update()`), and the library
3418 * decided that the WINDOW_UPDATE should be submitted, then
3419 * WINDOW_UPDATE is queued with the current received bytes count.
3421 * If the |window_size_increment| is 0, the function does nothing and
3424 * This function returns 0 if it succeeds, or one of the following
3425 * negative error codes:
3427 * :enum:`NGHTTP2_ERR_FLOW_CONTROL`
3428 * The local window size overflow or gets negative.
3429 * :enum:`NGHTTP2_ERR_NOMEM`
3432 NGHTTP2_EXTERN int nghttp2_submit_window_update(nghttp2_session *session,
3435 int32_t window_size_increment);
3440 * Compares ``lhs->name`` of length ``lhs->namelen`` bytes and
3441 * ``rhs->name`` of length ``rhs->namelen`` bytes. Returns negative
3442 * integer if ``lhs->name`` is found to be less than ``rhs->name``; or
3443 * returns positive integer if ``lhs->name`` is found to be greater
3444 * than ``rhs->name``; or returns 0 otherwise.
3446 NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs,
3447 const nghttp2_nv *rhs);
3452 * A helper function for dealing with NPN in client side or ALPN in
3453 * server side. The |in| contains peer's protocol list in preferable
3454 * order. The format of |in| is length-prefixed and not
3455 * null-terminated. For example, ``h2`` and
3456 * ``http/1.1`` stored in |in| like this::
3461 * in[4..11] = "http/1.1"
3464 * The selection algorithm is as follows:
3466 * 1. If peer's list contains HTTP/2 protocol the library supports,
3467 * it is selected and returns 1. The following step is not taken.
3469 * 2. If peer's list contains ``http/1.1``, this function selects
3470 * ``http/1.1`` and returns 0. The following step is not taken.
3472 * 3. This function selects nothing and returns -1 (So called
3473 * non-overlap case). In this case, |out| and |outlen| are left
3476 * Selecting ``h2`` means that ``h2`` is written into |*out| and its
3477 * length (which is 2) is assigned to |*outlen|.
3479 * For ALPN, refer to https://tools.ietf.org/html/rfc7301
3481 * See http://technotes.googlecode.com/git/nextprotoneg.html for more
3482 * details about NPN.
3484 * For NPN, to use this method you should do something like::
3486 * static int select_next_proto_cb(SSL* ssl,
3487 * unsigned char **out,
3488 * unsigned char *outlen,
3489 * const unsigned char *in,
3490 * unsigned int inlen,
3494 * rv = nghttp2_select_next_protocol(out, outlen, in, inlen);
3496 * return SSL_TLSEXT_ERR_NOACK;
3499 * ((MyType*)arg)->http2_selected = 1;
3501 * return SSL_TLSEXT_ERR_OK;
3504 * SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, my_obj);
3507 NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out,
3508 unsigned char *outlen,
3509 const unsigned char *in,
3510 unsigned int inlen);
3515 * Returns a pointer to a nghttp2_info struct with version information
3516 * about the run-time library in use. The |least_version| argument
3517 * can be set to a 24 bit numerical value for the least accepted
3518 * version number and if the condition is not met, this function will
3519 * return a ``NULL``. Pass in 0 to skip the version checking.
3521 NGHTTP2_EXTERN nghttp2_info *nghttp2_version(int least_version);
3526 * Returns nonzero if the :type:`nghttp2_error` library error code
3527 * |lib_error| is fatal.
3529 NGHTTP2_EXTERN int nghttp2_is_fatal(int lib_error_code);
3534 * Returns nonzero if HTTP header field name |name| of length |len| is
3535 * valid according to http://tools.ietf.org/html/rfc7230#section-3.2
3537 * Because this is a header field name in HTTP2, the upper cased alphabet
3538 * is treated as error.
3540 NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len);
3545 * Returns nonzero if HTTP header field value |value| of length |len|
3546 * is valid according to
3547 * http://tools.ietf.org/html/rfc7230#section-3.2
3549 NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len);
3553 struct nghttp2_hd_deflater;
3558 * HPACK deflater object.
3560 typedef struct nghttp2_hd_deflater nghttp2_hd_deflater;
3565 * Initializes |*deflater_ptr| for deflating name/values pairs.
3567 * The |deflate_hd_table_bufsize_max| is the upper bound of header
3568 * table size the deflater will use.
3570 * If this function fails, |*deflater_ptr| is left untouched.
3572 * This function returns 0 if it succeeds, or one of the following
3573 * negative error codes:
3575 * :enum:`NGHTTP2_ERR_NOMEM`
3578 NGHTTP2_EXTERN int nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,
3579 size_t deflate_hd_table_bufsize_max);
3584 * Like `nghttp2_hd_deflate_new()`, but with additional custom memory
3585 * allocator specified in the |mem|.
3587 * The |mem| can be ``NULL`` and the call is equivalent to
3588 * `nghttp2_hd_deflate_new()`.
3590 * This function does not take ownership |mem|. The application is
3591 * responsible for freeing |mem|.
3593 * The library code does not refer to |mem| pointer after this
3594 * function returns, so the application can safely free it.
3596 NGHTTP2_EXTERN int nghttp2_hd_deflate_new2(nghttp2_hd_deflater **deflater_ptr,
3597 size_t deflate_hd_table_bufsize_max,
3603 * Deallocates any resources allocated for |deflater|.
3605 NGHTTP2_EXTERN void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater);
3610 * Changes header table size of the |deflater| to
3611 * |settings_hd_table_bufsize_max| bytes. This may trigger eviction
3612 * in the dynamic table.
3614 * The |settings_hd_table_bufsize_max| should be the value received in
3615 * SETTINGS_HEADER_TABLE_SIZE.
3617 * The deflater never uses more memory than
3618 * ``deflate_hd_table_bufsize_max`` bytes specified in
3619 * `nghttp2_hd_deflate_new()`. Therefore, if
3620 * |settings_hd_table_bufsize_max| > ``deflate_hd_table_bufsize_max``,
3621 * resulting maximum table size becomes
3622 * ``deflate_hd_table_bufsize_max``.
3624 * This function returns 0 if it succeeds, or one of the following
3625 * negative error codes:
3627 * :enum:`NGHTTP2_ERR_NOMEM`
3631 nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater,
3632 size_t settings_hd_table_bufsize_max);
3637 * Deflates the |nva|, which has the |nvlen| name/value pairs, into
3638 * the |buf| of length |buflen|.
3640 * If |buf| is not large enough to store the deflated header block,
3641 * this function fails with :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`. The
3642 * caller should use `nghttp2_hd_deflate_bound()` to know the upper
3643 * bound of buffer size required to deflate given header name/value
3646 * Once this function fails, subsequent call of this function always
3647 * returns :enum:`NGHTTP2_ERR_HEADER_COMP`.
3649 * After this function returns, it is safe to delete the |nva|.
3651 * This function returns 0 if it succeeds, or one of the following
3652 * negative error codes:
3654 * :enum:`NGHTTP2_ERR_NOMEM`
3656 * :enum:`NGHTTP2_ERR_HEADER_COMP`
3657 * Deflation process has failed.
3658 * :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`
3659 * The provided |buflen| size is too small to hold the output.
3661 NGHTTP2_EXTERN ssize_t
3662 nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, uint8_t *buf,
3663 size_t buflen, const nghttp2_nv *nva, size_t nvlen);
3668 * Returns an upper bound on the compressed size after deflation of
3669 * |nva| of length |nvlen|.
3671 NGHTTP2_EXTERN size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
3672 const nghttp2_nv *nva,
3675 struct nghttp2_hd_inflater;
3680 * HPACK inflater object.
3682 typedef struct nghttp2_hd_inflater nghttp2_hd_inflater;
3687 * Initializes |*inflater_ptr| for inflating name/values pairs.
3689 * If this function fails, |*inflater_ptr| is left untouched.
3691 * This function returns 0 if it succeeds, or one of the following
3692 * negative error codes:
3694 * :enum:`NGHTTP2_ERR_NOMEM`
3697 NGHTTP2_EXTERN int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr);
3702 * Like `nghttp2_hd_inflate_new()`, but with additional custom memory
3703 * allocator specified in the |mem|.
3705 * The |mem| can be ``NULL`` and the call is equivalent to
3706 * `nghttp2_hd_inflate_new()`.
3708 * This function does not take ownership |mem|. The application is
3709 * responsible for freeing |mem|.
3711 * The library code does not refer to |mem| pointer after this
3712 * function returns, so the application can safely free it.
3714 NGHTTP2_EXTERN int nghttp2_hd_inflate_new2(nghttp2_hd_inflater **inflater_ptr,
3720 * Deallocates any resources allocated for |inflater|.
3722 NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater);
3727 * Changes header table size in the |inflater|. This may trigger
3728 * eviction in the dynamic table.
3730 * The |settings_hd_table_bufsize_max| should be the value transmitted
3731 * in SETTINGS_HEADER_TABLE_SIZE.
3733 * This function returns 0 if it succeeds, or one of the following
3734 * negative error codes:
3736 * :enum:`NGHTTP2_ERR_NOMEM`
3740 nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater,
3741 size_t settings_hd_table_bufsize_max);
3746 * The flags for header inflation.
3752 NGHTTP2_HD_INFLATE_NONE = 0,
3754 * Indicates all headers were inflated.
3756 NGHTTP2_HD_INFLATE_FINAL = 0x01,
3758 * Indicates a header was emitted.
3760 NGHTTP2_HD_INFLATE_EMIT = 0x02
3761 } nghttp2_hd_inflate_flag;
3766 * Inflates name/value block stored in |in| with length |inlen|. This
3767 * function performs decompression. For each successful emission of
3768 * header name/value pair, :enum:`NGHTTP2_HD_INFLATE_EMIT` is set in
3769 * |*inflate_flags| and name/value pair is assigned to the |nv_out|
3770 * and the function returns. The caller must not free the members of
3773 * The |nv_out| may include pointers to the memory region in the |in|.
3774 * The caller must retain the |in| while the |nv_out| is used.
3776 * The application should call this function repeatedly until the
3777 * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
3778 * return value is non-negative. This means the all input values are
3779 * processed successfully. Then the application must call
3780 * `nghttp2_hd_inflate_end_headers()` to prepare for the next header
3783 * The caller can feed complete compressed header block. It also can
3784 * feed it in several chunks. The caller must set |in_final| to
3785 * nonzero if the given input is the last block of the compressed
3788 * This function returns the number of bytes processed if it succeeds,
3789 * or one of the following negative error codes:
3791 * :enum:`NGHTTP2_ERR_NOMEM`
3793 * :enum:`NGHTTP2_ERR_HEADER_COMP`
3794 * Inflation process has failed.
3795 * :enum:`NGHTTP2_ERR_BUFFER_ERROR`
3796 * The heder field name or value is too large.
3800 * int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
3801 * uint8_t *in, size_t inlen, int final)
3807 * int inflate_flags = 0;
3809 * rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags,
3810 * in, inlen, final);
3813 * fprintf(stderr, "inflate failed with error code %zd", rv);
3820 * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
3821 * fwrite(nv.name, nv.namelen, 1, stderr);
3822 * fprintf(stderr, ": ");
3823 * fwrite(nv.value, nv.valuelen, 1, stderr);
3824 * fprintf(stderr, "\n");
3826 * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
3827 * nghttp2_hd_inflate_end_headers(hd_inflater);
3830 * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
3840 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
3842 int *inflate_flags, uint8_t *in,
3843 size_t inlen, int in_final);
3848 * Signals the end of decompression for one header block.
3850 * This function returns 0 if it succeeds. Currently this function
3854 nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater);
3860 #endif /* NGHTTP2_H */