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)
34 /* Compatibility for non-Clang compilers */
35 #ifndef __has_declspec_attribute
36 # define __has_declspec_attribute(x) 0
44 #if defined(_MSC_VER) && (_MSC_VER < 1800)
45 /* MSVC < 2013 does not have inttypes.h because it is not C99
46 compliant. See compiler macros and version number in
47 https://sourceforge.net/p/predef/wiki/Compilers/ */
49 #else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
50 # include <inttypes.h>
51 #endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
52 #include <sys/types.h>
55 #include <nghttp2/nghttp2ver.h>
57 #ifdef NGHTTP2_STATICLIB
58 # define NGHTTP2_EXTERN
59 #elif defined(WIN32) || (__has_declspec_attribute(dllexport) && \
60 __has_declspec_attribute(dllimport))
61 # ifdef BUILDING_NGHTTP2
62 # define NGHTTP2_EXTERN __declspec(dllexport)
63 # else /* !BUILDING_NGHTTP2 */
64 # define NGHTTP2_EXTERN __declspec(dllimport)
65 # endif /* !BUILDING_NGHTTP2 */
66 #else /* !defined(WIN32) */
67 # ifdef BUILDING_NGHTTP2
68 # define NGHTTP2_EXTERN __attribute__((visibility("default")))
69 # else /* !BUILDING_NGHTTP2 */
70 # define NGHTTP2_EXTERN
71 # endif /* !BUILDING_NGHTTP2 */
72 #endif /* !defined(WIN32) */
77 * The protocol version identification string of this library
78 * supports. This identifier is used if HTTP/2 is used over TLS.
80 #define NGHTTP2_PROTO_VERSION_ID "h2"
84 * The length of :macro:`NGHTTP2_PROTO_VERSION_ID`.
86 #define NGHTTP2_PROTO_VERSION_ID_LEN 2
91 * The serialized form of ALPN protocol identifier this library
92 * supports. Notice that first byte is the length of following
93 * protocol identifier. This is the same wire format of `TLS ALPN
94 * extension <https://tools.ietf.org/html/rfc7301>`_. This is useful
95 * to process incoming ALPN tokens in wire format.
97 #define NGHTTP2_PROTO_ALPN "\x2h2"
102 * The length of :macro:`NGHTTP2_PROTO_ALPN`.
104 #define NGHTTP2_PROTO_ALPN_LEN (sizeof(NGHTTP2_PROTO_ALPN) - 1)
109 * The protocol version identification string of this library
110 * supports. This identifier is used if HTTP/2 is used over cleartext
113 #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c"
118 * The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`.
120 #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 3
122 struct nghttp2_session;
126 * The primary structure to hold the resources needed for a HTTP/2
127 * session. The details of this structure are intentionally hidden
128 * from the public API.
130 typedef struct nghttp2_session nghttp2_session;
135 * The age of :type:`nghttp2_info`
137 #define NGHTTP2_VERSION_AGE 1
142 * This struct is what `nghttp2_version()` returns. It holds
143 * information about the particular nghttp2 version.
147 * Age of this struct. This instance of nghttp2 sets it to
148 * :macro:`NGHTTP2_VERSION_AGE` but a future version may bump it and
149 * add more struct fields at the bottom
153 * the :macro:`NGHTTP2_VERSION_NUM` number (since age ==1)
157 * points to the :macro:`NGHTTP2_VERSION` string (since age ==1)
159 const char *version_str;
161 * points to the :macro:`NGHTTP2_PROTO_VERSION_ID` string this
162 * instance implements (since age ==1)
164 const char *proto_str;
165 /* -------- the above fields all exist when age == 1 */
171 * The default weight of stream dependency.
173 #define NGHTTP2_DEFAULT_WEIGHT 16
178 * The maximum weight of stream dependency.
180 #define NGHTTP2_MAX_WEIGHT 256
185 * The minimum weight of stream dependency.
187 #define NGHTTP2_MIN_WEIGHT 1
192 * The maximum window size
194 #define NGHTTP2_MAX_WINDOW_SIZE ((int32_t)((1U << 31) - 1))
199 * The initial window size for stream level flow control.
201 #define NGHTTP2_INITIAL_WINDOW_SIZE ((1 << 16) - 1)
205 * The initial window size for connection level flow control.
207 #define NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE ((1 << 16) - 1)
212 * The default header table size.
214 #define NGHTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12)
219 * The client magic string, which is the first 24 bytes byte string of
220 * client connection preface.
222 #define NGHTTP2_CLIENT_MAGIC "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
227 * The length of :macro:`NGHTTP2_CLIENT_MAGIC`.
229 #define NGHTTP2_CLIENT_MAGIC_LEN 24
234 * The default max number of settings per SETTINGS frame
236 #define NGHTTP2_DEFAULT_MAX_SETTINGS 32
241 * Error codes used in this library. The code range is [-999, -500],
242 * inclusive. The following values are defined:
246 * Invalid argument passed.
248 NGHTTP2_ERR_INVALID_ARGUMENT = -501,
250 * Out of buffer space.
252 NGHTTP2_ERR_BUFFER_ERROR = -502,
254 * The specified protocol version is not supported.
256 NGHTTP2_ERR_UNSUPPORTED_VERSION = -503,
258 * Used as a return value from :type:`nghttp2_send_callback`,
259 * :type:`nghttp2_recv_callback` and
260 * :type:`nghttp2_send_data_callback` to indicate that the operation
263 NGHTTP2_ERR_WOULDBLOCK = -504,
265 * General protocol error
267 NGHTTP2_ERR_PROTO = -505,
269 * The frame is invalid.
271 NGHTTP2_ERR_INVALID_FRAME = -506,
273 * The peer performed a shutdown on the connection.
275 NGHTTP2_ERR_EOF = -507,
277 * Used as a return value from
278 * :func:`nghttp2_data_source_read_callback` to indicate that data
279 * transfer is postponed. See
280 * :func:`nghttp2_data_source_read_callback` for details.
282 NGHTTP2_ERR_DEFERRED = -508,
284 * Stream ID has reached the maximum value. Therefore no stream ID
287 NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509,
289 * The stream is already closed; or the stream ID is invalid.
291 NGHTTP2_ERR_STREAM_CLOSED = -510,
293 * RST_STREAM has been added to the outbound queue. The stream is
296 NGHTTP2_ERR_STREAM_CLOSING = -511,
298 * The transmission is not allowed for this stream (e.g., a frame
299 * with END_STREAM flag set has already sent).
301 NGHTTP2_ERR_STREAM_SHUT_WR = -512,
303 * The stream ID is invalid.
305 NGHTTP2_ERR_INVALID_STREAM_ID = -513,
307 * The state of the stream is not valid (e.g., DATA cannot be sent
308 * to the stream if response HEADERS has not been sent).
310 NGHTTP2_ERR_INVALID_STREAM_STATE = -514,
312 * Another DATA frame has already been deferred.
314 NGHTTP2_ERR_DEFERRED_DATA_EXIST = -515,
316 * Starting new stream is not allowed (e.g., GOAWAY has been sent
319 NGHTTP2_ERR_START_STREAM_NOT_ALLOWED = -516,
321 * GOAWAY has already been sent.
323 NGHTTP2_ERR_GOAWAY_ALREADY_SENT = -517,
325 * The received frame contains the invalid header block (e.g., There
326 * are duplicate header names; or the header names are not encoded
327 * in US-ASCII character set and not lower cased; or the header name
328 * is zero-length string; or the header value contains multiple
329 * in-sequence NUL bytes).
331 NGHTTP2_ERR_INVALID_HEADER_BLOCK = -518,
333 * Indicates that the context is not suitable to perform the
334 * requested operation.
336 NGHTTP2_ERR_INVALID_STATE = -519,
338 * The user callback function failed due to the temporal error.
340 NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE = -521,
342 * The length of the frame is invalid, either too large or too small.
344 NGHTTP2_ERR_FRAME_SIZE_ERROR = -522,
346 * Header block inflate/deflate error.
348 NGHTTP2_ERR_HEADER_COMP = -523,
352 NGHTTP2_ERR_FLOW_CONTROL = -524,
354 * Insufficient buffer size given to function.
356 NGHTTP2_ERR_INSUFF_BUFSIZE = -525,
358 * Callback was paused by the application
360 NGHTTP2_ERR_PAUSE = -526,
362 * There are too many in-flight SETTING frame and no more
363 * transmission of SETTINGS is allowed.
365 NGHTTP2_ERR_TOO_MANY_INFLIGHT_SETTINGS = -527,
367 * The server push is disabled.
369 NGHTTP2_ERR_PUSH_DISABLED = -528,
371 * DATA or HEADERS frame for a given stream has been already
372 * submitted and has not been fully processed yet. Application
373 * should wait for the transmission of the previously submitted
374 * frame before submitting another.
376 NGHTTP2_ERR_DATA_EXIST = -529,
378 * The current session is closing due to a connection error or
379 * `nghttp2_session_terminate_session()` is called.
381 NGHTTP2_ERR_SESSION_CLOSING = -530,
383 * Invalid HTTP header field was received and stream is going to be
386 NGHTTP2_ERR_HTTP_HEADER = -531,
388 * Violation in HTTP messaging rule.
390 NGHTTP2_ERR_HTTP_MESSAGING = -532,
392 * Stream was refused.
394 NGHTTP2_ERR_REFUSED_STREAM = -533,
396 * Unexpected internal error, but recovered.
398 NGHTTP2_ERR_INTERNAL = -534,
400 * Indicates that a processing was canceled.
402 NGHTTP2_ERR_CANCEL = -535,
404 * When a local endpoint expects to receive SETTINGS frame, it
405 * receives an other type of frame.
407 NGHTTP2_ERR_SETTINGS_EXPECTED = -536,
409 * When a local endpoint receives too many settings entries
410 * in a single SETTINGS frame.
412 NGHTTP2_ERR_TOO_MANY_SETTINGS = -537,
414 * The errors < :enum:`NGHTTP2_ERR_FATAL` mean that the library is
415 * under unexpected condition and processing was terminated (e.g.,
416 * out of memory). If application receives this error code, it must
417 * stop using that :type:`nghttp2_session` object and only allowed
418 * operation for that object is deallocate it using
419 * `nghttp2_session_del()`.
421 NGHTTP2_ERR_FATAL = -900,
423 * Out of memory. This is a fatal error.
425 NGHTTP2_ERR_NOMEM = -901,
427 * The user callback function failed. This is a fatal error.
429 NGHTTP2_ERR_CALLBACK_FAILURE = -902,
431 * Invalid client magic (see :macro:`NGHTTP2_CLIENT_MAGIC`) was
432 * received and further processing is not possible.
434 NGHTTP2_ERR_BAD_CLIENT_MAGIC = -903,
436 * Possible flooding by peer was detected in this HTTP/2 session.
437 * Flooding is measured by how many PING and SETTINGS frames with
438 * ACK flag set are queued for transmission. These frames are
439 * response for the peer initiated frames, and peer can cause memory
440 * exhaustion on server side to send these frames forever and does
443 NGHTTP2_ERR_FLOODED = -904
449 * The object representing single contiguous buffer.
453 * The pointer to the buffer.
457 * The length of the buffer.
462 struct nghttp2_rcbuf;
467 * The object representing reference counted buffer. The details of
468 * this structure are intentionally hidden from the public API.
470 typedef struct nghttp2_rcbuf nghttp2_rcbuf;
475 * Increments the reference count of |rcbuf| by 1.
477 NGHTTP2_EXTERN void nghttp2_rcbuf_incref(nghttp2_rcbuf *rcbuf);
482 * Decrements the reference count of |rcbuf| by 1. If the reference
483 * count becomes zero, the object pointed by |rcbuf| will be freed.
484 * In this case, application must not use |rcbuf| again.
486 NGHTTP2_EXTERN void nghttp2_rcbuf_decref(nghttp2_rcbuf *rcbuf);
491 * Returns the underlying buffer managed by |rcbuf|.
493 NGHTTP2_EXTERN nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf);
498 * Returns nonzero if the underlying buffer is statically allocated,
499 * and 0 otherwise. This can be useful for language bindings that wish
500 * to avoid creating duplicate strings for these buffers.
502 NGHTTP2_EXTERN int nghttp2_rcbuf_is_static(const nghttp2_rcbuf *rcbuf);
507 * The flags for header field name/value pair.
513 NGHTTP2_NV_FLAG_NONE = 0,
515 * Indicates that this name/value pair must not be indexed ("Literal
516 * Header Field never Indexed" representation must be used in HPACK
517 * encoding). Other implementation calls this bit as "sensitive".
519 NGHTTP2_NV_FLAG_NO_INDEX = 0x01,
521 * This flag is set solely by application. If this flag is set, the
522 * library does not make a copy of header field name. This could
523 * improve performance.
525 NGHTTP2_NV_FLAG_NO_COPY_NAME = 0x02,
527 * This flag is set solely by application. If this flag is set, the
528 * library does not make a copy of header field value. This could
529 * improve performance.
531 NGHTTP2_NV_FLAG_NO_COPY_VALUE = 0x04
537 * The name/value pair, which mainly used to represent header fields.
541 * The |name| byte string. If this struct is presented from library
542 * (e.g., :type:`nghttp2_on_frame_recv_callback`), |name| is
543 * guaranteed to be NULL-terminated. For some callbacks
544 * (:type:`nghttp2_before_frame_send_callback`,
545 * :type:`nghttp2_on_frame_send_callback`, and
546 * :type:`nghttp2_on_frame_not_send_callback`), it may not be
547 * NULL-terminated if header field is passed from application with
548 * the flag :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`). When application
549 * is constructing this struct, |name| is not required to be
554 * The |value| byte string. If this struct is presented from
555 * library (e.g., :type:`nghttp2_on_frame_recv_callback`), |value|
556 * is guaranteed to be NULL-terminated. For some callbacks
557 * (:type:`nghttp2_before_frame_send_callback`,
558 * :type:`nghttp2_on_frame_send_callback`, and
559 * :type:`nghttp2_on_frame_not_send_callback`), it may not be
560 * NULL-terminated if header field is passed from application with
561 * the flag :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE`). When
562 * application is constructing this struct, |value| is not required
563 * to be NULL-terminated.
567 * The length of the |name|, excluding terminating NULL.
571 * The length of the |value|, excluding terminating NULL.
575 * Bitwise OR of one or more of :type:`nghttp2_nv_flag`.
583 * The frame types in HTTP/2 specification.
593 NGHTTP2_HEADERS = 0x01,
595 * The PRIORITY frame.
597 NGHTTP2_PRIORITY = 0x02,
599 * The RST_STREAM frame.
601 NGHTTP2_RST_STREAM = 0x03,
603 * The SETTINGS frame.
605 NGHTTP2_SETTINGS = 0x04,
607 * The PUSH_PROMISE frame.
609 NGHTTP2_PUSH_PROMISE = 0x05,
617 NGHTTP2_GOAWAY = 0x07,
619 * The WINDOW_UPDATE frame.
621 NGHTTP2_WINDOW_UPDATE = 0x08,
623 * The CONTINUATION frame. This frame type won't be passed to any
624 * callbacks because the library processes this frame type and its
625 * preceding HEADERS/PUSH_PROMISE as a single frame.
627 NGHTTP2_CONTINUATION = 0x09,
629 * The ALTSVC frame, which is defined in `RFC 7383
630 * <https://tools.ietf.org/html/rfc7838#section-4>`_.
632 NGHTTP2_ALTSVC = 0x0a,
634 * The ORIGIN frame, which is defined by `RFC 8336
635 * <https://tools.ietf.org/html/rfc8336>`_.
637 NGHTTP2_ORIGIN = 0x0c
638 } nghttp2_frame_type;
643 * The flags for HTTP/2 frames. This enum defines all flags for all
650 NGHTTP2_FLAG_NONE = 0,
652 * The END_STREAM flag.
654 NGHTTP2_FLAG_END_STREAM = 0x01,
656 * The END_HEADERS flag.
658 NGHTTP2_FLAG_END_HEADERS = 0x04,
662 NGHTTP2_FLAG_ACK = 0x01,
666 NGHTTP2_FLAG_PADDED = 0x08,
670 NGHTTP2_FLAG_PRIORITY = 0x20
679 * SETTINGS_HEADER_TABLE_SIZE
681 NGHTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x01,
683 * SETTINGS_ENABLE_PUSH
685 NGHTTP2_SETTINGS_ENABLE_PUSH = 0x02,
687 * SETTINGS_MAX_CONCURRENT_STREAMS
689 NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x03,
691 * SETTINGS_INITIAL_WINDOW_SIZE
693 NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x04,
695 * SETTINGS_MAX_FRAME_SIZE
697 NGHTTP2_SETTINGS_MAX_FRAME_SIZE = 0x05,
699 * SETTINGS_MAX_HEADER_LIST_SIZE
701 NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x06,
703 * SETTINGS_ENABLE_CONNECT_PROTOCOL
704 * (`RFC 8441 <https://tools.ietf.org/html/rfc8441>`_)
706 NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL = 0x08
707 } nghttp2_settings_id;
708 /* Note: If we add SETTINGS, update the capacity of
709 NGHTTP2_INBOUND_NUM_IV as well */
716 * Deprecated. The initial max concurrent streams is 0xffffffffu.
718 * Default maximum number of incoming concurrent streams. Use
719 * `nghttp2_submit_settings()` with
720 * :enum:`NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS` to change the
721 * maximum number of incoming concurrent streams.
725 * The maximum number of outgoing concurrent streams is 100 by
728 #define NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1)
732 * The status codes for the RST_STREAM and GOAWAY frames.
738 NGHTTP2_NO_ERROR = 0x00,
742 NGHTTP2_PROTOCOL_ERROR = 0x01,
746 NGHTTP2_INTERNAL_ERROR = 0x02,
750 NGHTTP2_FLOW_CONTROL_ERROR = 0x03,
754 NGHTTP2_SETTINGS_TIMEOUT = 0x04,
758 NGHTTP2_STREAM_CLOSED = 0x05,
762 NGHTTP2_FRAME_SIZE_ERROR = 0x06,
766 NGHTTP2_REFUSED_STREAM = 0x07,
770 NGHTTP2_CANCEL = 0x08,
774 NGHTTP2_COMPRESSION_ERROR = 0x09,
778 NGHTTP2_CONNECT_ERROR = 0x0a,
782 NGHTTP2_ENHANCE_YOUR_CALM = 0x0b,
784 * INADEQUATE_SECURITY
786 NGHTTP2_INADEQUATE_SECURITY = 0x0c,
790 NGHTTP2_HTTP_1_1_REQUIRED = 0x0d
791 } nghttp2_error_code;
799 * The length field of this frame, excluding frame header.
803 * The stream identifier (aka, stream ID)
807 * The type of this frame. See `nghttp2_frame_type`.
815 * Reserved bit in frame header. Currently, this is always set to 0
816 * and application should not expect something useful in here.
824 * This union represents the some kind of data source passed to
825 * :type:`nghttp2_data_source_read_callback`.
829 * The integer field, suitable for a file descriptor.
833 * The pointer to an arbitrary object.
836 } nghttp2_data_source;
841 * The flags used to set in |data_flags| output parameter in
842 * :type:`nghttp2_data_source_read_callback`.
848 NGHTTP2_DATA_FLAG_NONE = 0,
850 * Indicates EOF was sensed.
852 NGHTTP2_DATA_FLAG_EOF = 0x01,
854 * Indicates that END_STREAM flag must not be set even if
855 * NGHTTP2_DATA_FLAG_EOF is set. Usually this flag is used to send
856 * trailer fields with `nghttp2_submit_request()` or
857 * `nghttp2_submit_response()`.
859 NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02,
861 * Indicates that application will send complete DATA frame in
862 * :type:`nghttp2_send_data_callback`.
864 NGHTTP2_DATA_FLAG_NO_COPY = 0x04
870 * Callback function invoked when the library wants to read data from
871 * the |source|. The read data is sent in the stream |stream_id|.
872 * The implementation of this function must read at most |length|
873 * bytes of data from |source| (or possibly other places) and store
874 * them in |buf| and return number of data stored in |buf|. If EOF is
875 * reached, set :enum:`NGHTTP2_DATA_FLAG_EOF` flag in |*data_flags|.
877 * Sometime it is desirable to avoid copying data into |buf| and let
878 * application to send data directly. To achieve this, set
879 * :enum:`NGHTTP2_DATA_FLAG_NO_COPY` to |*data_flags| (and possibly
880 * other flags, just like when we do copy), and return the number of
881 * bytes to send without copying data into |buf|. The library, seeing
882 * :enum:`NGHTTP2_DATA_FLAG_NO_COPY`, will invoke
883 * :type:`nghttp2_send_data_callback`. The application must send
884 * complete DATA frame in that callback.
886 * If this callback is set by `nghttp2_submit_request()`,
887 * `nghttp2_submit_response()` or `nghttp2_submit_headers()` and
888 * `nghttp2_submit_data()` with flag parameter
889 * :enum:`NGHTTP2_FLAG_END_STREAM` set, and
890 * :enum:`NGHTTP2_DATA_FLAG_EOF` flag is set to |*data_flags|, DATA
891 * frame will have END_STREAM flag set. Usually, this is expected
892 * behaviour and all are fine. One exception is send trailer fields.
893 * You cannot send trailer fields after sending frame with END_STREAM
894 * set. To avoid this problem, one can set
895 * :enum:`NGHTTP2_DATA_FLAG_NO_END_STREAM` along with
896 * :enum:`NGHTTP2_DATA_FLAG_EOF` to signal the library not to set
897 * END_STREAM in DATA frame. Then application can use
898 * `nghttp2_submit_trailer()` to send trailer fields.
899 * `nghttp2_submit_trailer()` can be called inside this callback.
901 * If the application wants to postpone DATA frames (e.g.,
902 * asynchronous I/O, or reading data blocks for long time), it is
903 * achieved by returning :enum:`NGHTTP2_ERR_DEFERRED` without reading
904 * any data in this invocation. The library removes DATA frame from
905 * the outgoing queue temporarily. To move back deferred DATA frame
906 * to outgoing queue, call `nghttp2_session_resume_data()`.
908 * By default, |length| is limited to 16KiB at maximum. If peer
909 * allows larger frames, application can enlarge transmission buffer
910 * size. See :type:`nghttp2_data_source_read_length_callback` for
913 * If the application just wants to return from
914 * `nghttp2_session_send()` or `nghttp2_session_mem_send()` without
915 * sending anything, return :enum:`NGHTTP2_ERR_PAUSE`.
917 * In case of error, there are 2 choices. Returning
918 * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close the stream
919 * by issuing RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. If a
920 * different error code is desirable, use
921 * `nghttp2_submit_rst_stream()` with a desired error code and then
922 * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Returning
923 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the entire session
926 typedef ssize_t (*nghttp2_data_source_read_callback)(
927 nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length,
928 uint32_t *data_flags, nghttp2_data_source *source, void *user_data);
933 * This struct represents the data source and the way to read a chunk
940 nghttp2_data_source source;
942 * The callback function to read a chunk of data from the |source|.
944 nghttp2_data_source_read_callback read_callback;
945 } nghttp2_data_provider;
950 * The DATA frame. The received data is delivered via
951 * :type:`nghttp2_on_data_chunk_recv_callback`.
956 * The length of the padding in this frame. This includes PAD_HIGH
965 * The category of HEADERS, which indicates the role of the frame. In
966 * HTTP/2 spec, request, response, push response and other arbitrary
967 * headers (e.g., trailer fields) are all called just HEADERS. To
968 * give the application the role of incoming HEADERS frame, we define
969 * several categories.
973 * The HEADERS frame is opening new stream, which is analogous to
974 * SYN_STREAM in SPDY.
976 NGHTTP2_HCAT_REQUEST = 0,
978 * The HEADERS frame is the first response headers, which is
979 * analogous to SYN_REPLY in SPDY.
981 NGHTTP2_HCAT_RESPONSE = 1,
983 * The HEADERS frame is the first headers sent against reserved
986 NGHTTP2_HCAT_PUSH_RESPONSE = 2,
988 * The HEADERS frame which does not apply for the above categories,
989 * which is analogous to HEADERS in SPDY. If non-final response
990 * (e.g., status 1xx) is used, final response HEADERS frame will be
993 NGHTTP2_HCAT_HEADERS = 3
994 } nghttp2_headers_category;
999 * The structure to specify stream dependency.
1003 * The stream ID of the stream to depend on. Specifying 0 makes
1004 * stream not depend any other stream.
1008 * The weight of this dependency.
1012 * nonzero means exclusive dependency
1015 } nghttp2_priority_spec;
1020 * The HEADERS frame. It has the following members:
1026 nghttp2_frame_hd hd;
1028 * The length of the padding in this frame. This includes PAD_HIGH
1033 * The priority specification
1035 nghttp2_priority_spec pri_spec;
1037 * The name/value pairs.
1041 * The number of name/value pairs in |nva|.
1045 * The category of this HEADERS frame.
1047 nghttp2_headers_category cat;
1053 * The PRIORITY frame. It has the following members:
1059 nghttp2_frame_hd hd;
1061 * The priority specification.
1063 nghttp2_priority_spec pri_spec;
1069 * The RST_STREAM frame. It has the following members:
1075 nghttp2_frame_hd hd;
1077 * The error code. See :type:`nghttp2_error_code`.
1079 uint32_t error_code;
1080 } nghttp2_rst_stream;
1085 * The SETTINGS ID/Value pair. It has the following members:
1089 * The SETTINGS ID. See :type:`nghttp2_settings_id`.
1091 int32_t settings_id;
1093 * The value of this entry.
1096 } nghttp2_settings_entry;
1101 * The SETTINGS frame. It has the following members:
1107 nghttp2_frame_hd hd;
1109 * The number of SETTINGS ID/Value pairs in |iv|.
1113 * The pointer to the array of SETTINGS ID/Value pair.
1115 nghttp2_settings_entry *iv;
1121 * The PUSH_PROMISE frame. It has the following members:
1127 nghttp2_frame_hd hd;
1129 * The length of the padding in this frame. This includes PAD_HIGH
1134 * The name/value pairs.
1138 * The number of name/value pairs in |nva|.
1142 * The promised stream ID
1144 int32_t promised_stream_id;
1146 * Reserved bit. Currently this is always set to 0 and application
1147 * should not expect something useful in here.
1150 } nghttp2_push_promise;
1155 * The PING frame. It has the following members:
1161 nghttp2_frame_hd hd;
1165 uint8_t opaque_data[8];
1171 * The GOAWAY frame. It has the following members:
1177 nghttp2_frame_hd hd;
1179 * The last stream stream ID.
1181 int32_t last_stream_id;
1183 * The error code. See :type:`nghttp2_error_code`.
1185 uint32_t error_code;
1187 * The additional debug data
1189 uint8_t *opaque_data;
1191 * The length of |opaque_data| member.
1193 size_t opaque_data_len;
1195 * Reserved bit. Currently this is always set to 0 and application
1196 * should not expect something useful in here.
1204 * The WINDOW_UPDATE frame. It has the following members:
1210 nghttp2_frame_hd hd;
1212 * The window size increment.
1214 int32_t window_size_increment;
1216 * Reserved bit. Currently this is always set to 0 and application
1217 * should not expect something useful in here.
1220 } nghttp2_window_update;
1225 * The extension frame. It has following members:
1231 nghttp2_frame_hd hd;
1233 * The pointer to extension payload. The exact pointer type is
1234 * determined by hd.type.
1236 * Currently, no extension is supported. This is a place holder for
1237 * the future extensions.
1240 } nghttp2_extension;
1245 * This union includes all frames to pass them to various function
1246 * calls as nghttp2_frame type. The CONTINUATION frame is omitted
1247 * from here because the library deals with it internally.
1251 * The frame header, which is convenient to inspect frame header.
1253 nghttp2_frame_hd hd;
1259 * The HEADERS frame.
1261 nghttp2_headers headers;
1263 * The PRIORITY frame.
1265 nghttp2_priority priority;
1267 * The RST_STREAM frame.
1269 nghttp2_rst_stream rst_stream;
1271 * The SETTINGS frame.
1273 nghttp2_settings settings;
1275 * The PUSH_PROMISE frame.
1277 nghttp2_push_promise push_promise;
1285 nghttp2_goaway goaway;
1287 * The WINDOW_UPDATE frame.
1289 nghttp2_window_update window_update;
1291 * The extension frame.
1293 nghttp2_extension ext;
1299 * Callback function invoked when |session| wants to send data to the
1300 * remote peer. The implementation of this function must send at most
1301 * |length| bytes of data stored in |data|. The |flags| is currently
1302 * not used and always 0. It must return the number of bytes sent if
1303 * it succeeds. If it cannot send any single byte without blocking,
1304 * it must return :enum:`NGHTTP2_ERR_WOULDBLOCK`. For other errors,
1305 * it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. The
1306 * |user_data| pointer is the third argument passed in to the call to
1307 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1309 * This callback is required if the application uses
1310 * `nghttp2_session_send()` to send data to the remote endpoint. If
1311 * the application uses solely `nghttp2_session_mem_send()` instead,
1312 * this callback function is unnecessary.
1314 * To set this callback to :type:`nghttp2_session_callbacks`, use
1315 * `nghttp2_session_callbacks_set_send_callback()`.
1319 * The |length| may be very small. If that is the case, and
1320 * application disables Nagle algorithm (``TCP_NODELAY``), then just
1321 * writing |data| to the network stack leads to very small packet,
1322 * and it is very inefficient. An application should be responsible
1323 * to buffer up small chunks of data as necessary to avoid this
1326 typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session,
1327 const uint8_t *data, size_t length,
1328 int flags, void *user_data);
1333 * Callback function invoked when :enum:`NGHTTP2_DATA_FLAG_NO_COPY` is
1334 * used in :type:`nghttp2_data_source_read_callback` to send complete
1337 * The |frame| is a DATA frame to send. The |framehd| is the
1338 * serialized frame header (9 bytes). The |length| is the length of
1339 * application data to send (this does not include padding). The
1340 * |source| is the same pointer passed to
1341 * :type:`nghttp2_data_source_read_callback`.
1343 * The application first must send frame header |framehd| of length 9
1344 * bytes. If ``frame->data.padlen > 0``, send 1 byte of value
1345 * ``frame->data.padlen - 1``. Then send exactly |length| bytes of
1346 * application data. Finally, if ``frame->data.padlen > 1``, send
1347 * ``frame->data.padlen - 1`` bytes of zero as padding.
1349 * The application has to send complete DATA frame in this callback.
1350 * If all data were written successfully, return 0.
1352 * If it cannot send any data at all, just return
1353 * :enum:`NGHTTP2_ERR_WOULDBLOCK`; the library will call this callback
1354 * with the same parameters later (It is recommended to send complete
1355 * DATA frame at once in this function to deal with error; if partial
1356 * frame data has already sent, it is impossible to send another data
1357 * in that state, and all we can do is tear down connection). When
1358 * data is fully processed, but application wants to make
1359 * `nghttp2_session_mem_send()` or `nghttp2_session_send()` return
1360 * immediately without processing next frames, return
1361 * :enum:`NGHTTP2_ERR_PAUSE`. If application decided to reset this
1362 * stream, return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`, then
1363 * the library will send RST_STREAM with INTERNAL_ERROR as error code.
1364 * The application can also return
1365 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`, which will result in
1366 * connection closure. Returning any other value is treated as
1367 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned.
1369 typedef int (*nghttp2_send_data_callback)(nghttp2_session *session,
1370 nghttp2_frame *frame,
1371 const uint8_t *framehd, size_t length,
1372 nghttp2_data_source *source,
1378 * Callback function invoked when |session| wants to receive data from
1379 * the remote peer. The implementation of this function must read at
1380 * most |length| bytes of data and store it in |buf|. The |flags| is
1381 * currently not used and always 0. It must return the number of
1382 * bytes written in |buf| if it succeeds. If it cannot read any
1383 * single byte without blocking, it must return
1384 * :enum:`NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF before it reads any
1385 * single byte, it must return :enum:`NGHTTP2_ERR_EOF`. For other
1386 * errors, it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1387 * Returning 0 is treated as :enum:`NGHTTP2_ERR_WOULDBLOCK`. The
1388 * |user_data| pointer is the third argument passed in to the call to
1389 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1391 * This callback is required if the application uses
1392 * `nghttp2_session_recv()` to receive data from the remote endpoint.
1393 * If the application uses solely `nghttp2_session_mem_recv()`
1394 * instead, this callback function is unnecessary.
1396 * To set this callback to :type:`nghttp2_session_callbacks`, use
1397 * `nghttp2_session_callbacks_set_recv_callback()`.
1399 typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf,
1400 size_t length, int flags,
1406 * Callback function invoked by `nghttp2_session_recv()` and
1407 * `nghttp2_session_mem_recv()` when a frame is received. The
1408 * |user_data| pointer is the third argument passed in to the call to
1409 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1411 * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen``
1412 * member of their data structure are always ``NULL`` and 0
1413 * respectively. The header name/value pairs are emitted via
1414 * :type:`nghttp2_on_header_callback`.
1416 * For HEADERS, PUSH_PROMISE and DATA frames, this callback may be
1417 * called after stream is closed (see
1418 * :type:`nghttp2_on_stream_close_callback`). The application should
1419 * check that stream is still alive using its own stream management or
1420 * :func:`nghttp2_session_get_stream_user_data()`.
1422 * Only HEADERS and DATA frame can signal the end of incoming data.
1423 * If ``frame->hd.flags & NGHTTP2_FLAG_END_STREAM`` is nonzero, the
1424 * |frame| is the last frame from the remote peer in this stream.
1426 * This callback won't be called for CONTINUATION frames.
1427 * HEADERS/PUSH_PROMISE + CONTINUATIONs are treated as single frame.
1429 * The implementation of this function must return 0 if it succeeds.
1430 * If nonzero value is returned, it is treated as fatal error and
1431 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1432 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1434 * To set this callback to :type:`nghttp2_session_callbacks`, use
1435 * `nghttp2_session_callbacks_set_on_frame_recv_callback()`.
1437 typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session,
1438 const nghttp2_frame *frame,
1444 * Callback function invoked by `nghttp2_session_recv()` and
1445 * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is
1446 * received. The error is indicated by the |lib_error_code|, which is
1447 * one of the values defined in :type:`nghttp2_error`. When this
1448 * callback function is invoked, the library automatically submits
1449 * either RST_STREAM or GOAWAY frame. The |user_data| pointer is the
1450 * third argument passed in to the call to
1451 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1453 * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen``
1454 * member of their data structure are always ``NULL`` and 0
1457 * The implementation of this function must return 0 if it succeeds.
1458 * If nonzero is returned, it is treated as fatal error and
1459 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1460 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1462 * To set this callback to :type:`nghttp2_session_callbacks`, use
1463 * `nghttp2_session_callbacks_set_on_invalid_frame_recv_callback()`.
1465 typedef int (*nghttp2_on_invalid_frame_recv_callback)(
1466 nghttp2_session *session, const nghttp2_frame *frame, int lib_error_code,
1472 * Callback function invoked when a chunk of data in DATA frame is
1473 * received. The |stream_id| is the stream ID this DATA frame belongs
1474 * to. The |flags| is the flags of DATA frame which this data chunk
1475 * is contained. ``(flags & NGHTTP2_FLAG_END_STREAM) != 0`` does not
1476 * necessarily mean this chunk of data is the last one in the stream.
1477 * You should use :type:`nghttp2_on_frame_recv_callback` to know all
1478 * data frames are received. The |user_data| pointer is the third
1479 * argument passed in to the call to `nghttp2_session_client_new()` or
1480 * `nghttp2_session_server_new()`.
1482 * If the application uses `nghttp2_session_mem_recv()`, it can return
1483 * :enum:`NGHTTP2_ERR_PAUSE` to make `nghttp2_session_mem_recv()`
1484 * return without processing further input bytes. The memory by
1485 * pointed by the |data| is retained until
1486 * `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called.
1487 * The application must retain the input bytes which was used to
1488 * produce the |data| parameter, because it may refer to the memory
1489 * region included in the input bytes.
1491 * The implementation of this function must return 0 if it succeeds.
1492 * If nonzero is returned, it is treated as fatal error, and
1493 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1494 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1496 * To set this callback to :type:`nghttp2_session_callbacks`, use
1497 * `nghttp2_session_callbacks_set_on_data_chunk_recv_callback()`.
1499 typedef int (*nghttp2_on_data_chunk_recv_callback)(nghttp2_session *session,
1502 const uint8_t *data,
1503 size_t len, void *user_data);
1508 * Callback function invoked just before the non-DATA frame |frame| is
1509 * sent. The |user_data| pointer is the third argument passed in to
1510 * the call to `nghttp2_session_client_new()` or
1511 * `nghttp2_session_server_new()`.
1513 * The implementation of this function must return 0 if it succeeds.
1514 * It can also return :enum:`NGHTTP2_ERR_CANCEL` to cancel the
1515 * transmission of the given frame.
1517 * If there is a fatal error while executing this callback, the
1518 * implementation should return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`,
1519 * which makes `nghttp2_session_send()` and
1520 * `nghttp2_session_mem_send()` functions immediately return
1521 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1523 * If the other value is returned, it is treated as if
1524 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned. But the
1525 * implementation should not rely on this since the library may define
1526 * new return value to extend its capability.
1528 * To set this callback to :type:`nghttp2_session_callbacks`, use
1529 * `nghttp2_session_callbacks_set_before_frame_send_callback()`.
1531 typedef int (*nghttp2_before_frame_send_callback)(nghttp2_session *session,
1532 const nghttp2_frame *frame,
1538 * Callback function invoked after the frame |frame| is sent. The
1539 * |user_data| pointer is the third argument passed in to the call to
1540 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1542 * The implementation of this function must return 0 if it succeeds.
1543 * If nonzero is returned, it is treated as fatal error and
1544 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
1545 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1547 * To set this callback to :type:`nghttp2_session_callbacks`, use
1548 * `nghttp2_session_callbacks_set_on_frame_send_callback()`.
1550 typedef int (*nghttp2_on_frame_send_callback)(nghttp2_session *session,
1551 const nghttp2_frame *frame,
1557 * Callback function invoked after the non-DATA frame |frame| is not
1558 * sent because of the error. The error is indicated by the
1559 * |lib_error_code|, which is one of the values defined in
1560 * :type:`nghttp2_error`. The |user_data| pointer is the third
1561 * argument passed in to the call to `nghttp2_session_client_new()` or
1562 * `nghttp2_session_server_new()`.
1564 * The implementation of this function must return 0 if it succeeds.
1565 * If nonzero is returned, it is treated as fatal error and
1566 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
1567 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1569 * `nghttp2_session_get_stream_user_data()` can be used to get
1572 * To set this callback to :type:`nghttp2_session_callbacks`, use
1573 * `nghttp2_session_callbacks_set_on_frame_not_send_callback()`.
1575 typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session,
1576 const nghttp2_frame *frame,
1583 * Callback function invoked when the stream |stream_id| is closed.
1584 * The reason of closure is indicated by the |error_code|. The
1585 * |error_code| is usually one of :enum:`nghttp2_error_code`, but that
1586 * is not guaranteed. The stream_user_data, which was specified in
1587 * `nghttp2_submit_request()` or `nghttp2_submit_headers()`, is still
1588 * available in this function. The |user_data| pointer is the third
1589 * argument passed in to the call to `nghttp2_session_client_new()` or
1590 * `nghttp2_session_server_new()`.
1592 * This function is also called for a stream in reserved state.
1594 * The implementation of this function must return 0 if it succeeds.
1595 * If nonzero is returned, it is treated as fatal error and
1596 * `nghttp2_session_recv()`, `nghttp2_session_mem_recv()`,
1597 * `nghttp2_session_send()`, and `nghttp2_session_mem_send()`
1598 * functions immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1600 * To set this callback to :type:`nghttp2_session_callbacks`, use
1601 * `nghttp2_session_callbacks_set_on_stream_close_callback()`.
1603 typedef int (*nghttp2_on_stream_close_callback)(nghttp2_session *session,
1605 uint32_t error_code,
1611 * Callback function invoked when the reception of header block in
1612 * HEADERS or PUSH_PROMISE is started. Each header name/value pair
1613 * will be emitted by :type:`nghttp2_on_header_callback`.
1615 * The ``frame->hd.flags`` may not have
1616 * :enum:`NGHTTP2_FLAG_END_HEADERS` flag set, which indicates that one
1617 * or more CONTINUATION frames are involved. But the application does
1618 * not need to care about that because the header name/value pairs are
1619 * emitted transparently regardless of CONTINUATION frames.
1621 * The server applications probably create an object to store
1622 * information about new stream if ``frame->hd.type ==
1623 * NGHTTP2_HEADERS`` and ``frame->headers.cat ==
1624 * NGHTTP2_HCAT_REQUEST``. If |session| is configured as server side,
1625 * ``frame->headers.cat`` is either ``NGHTTP2_HCAT_REQUEST``
1626 * containing request headers or ``NGHTTP2_HCAT_HEADERS`` containing
1627 * trailer fields and never get PUSH_PROMISE in this callback.
1629 * For the client applications, ``frame->hd.type`` is either
1630 * ``NGHTTP2_HEADERS`` or ``NGHTTP2_PUSH_PROMISE``. In case of
1631 * ``NGHTTP2_HEADERS``, ``frame->headers.cat ==
1632 * NGHTTP2_HCAT_RESPONSE`` means that it is the first response
1633 * headers, but it may be non-final response which is indicated by 1xx
1634 * status code. In this case, there may be zero or more HEADERS frame
1635 * with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` which has
1636 * non-final response code and finally client gets exactly one HEADERS
1637 * frame with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS``
1638 * containing final response headers (non-1xx status code). The
1639 * trailer fields also has ``frame->headers.cat ==
1640 * NGHTTP2_HCAT_HEADERS`` which does not contain any status code.
1642 * Returning :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close
1643 * the stream (promised stream if frame is PUSH_PROMISE) by issuing
1644 * RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. In this case,
1645 * :type:`nghttp2_on_header_callback` and
1646 * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a
1647 * different error code is desirable, use
1648 * `nghttp2_submit_rst_stream()` with a desired error code and then
1649 * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Again, use
1650 * ``frame->push_promise.promised_stream_id`` as stream_id parameter
1651 * in `nghttp2_submit_rst_stream()` if frame is PUSH_PROMISE.
1653 * The implementation of this function must return 0 if it succeeds.
1654 * It can return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` to
1655 * reset the stream (promised stream if frame is PUSH_PROMISE). For
1656 * critical errors, it must return
1657 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the other value is
1658 * returned, it is treated as if :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
1659 * is returned. If :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned,
1660 * `nghttp2_session_mem_recv()` function will immediately return
1661 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1663 * To set this callback to :type:`nghttp2_session_callbacks`, use
1664 * `nghttp2_session_callbacks_set_on_begin_headers_callback()`.
1666 typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session,
1667 const nghttp2_frame *frame,
1673 * Callback function invoked when a header name/value pair is received
1674 * for the |frame|. The |name| of length |namelen| is header name.
1675 * The |value| of length |valuelen| is header value. The |flags| is
1676 * bitwise OR of one or more of :type:`nghttp2_nv_flag`.
1678 * If :enum:`NGHTTP2_NV_FLAG_NO_INDEX` is set in |flags|, the receiver
1679 * must not index this name/value pair when forwarding it to the next
1680 * hop. More specifically, "Literal Header Field never Indexed"
1681 * representation must be used in HPACK encoding.
1683 * When this callback is invoked, ``frame->hd.type`` is either
1684 * :enum:`NGHTTP2_HEADERS` or :enum:`NGHTTP2_PUSH_PROMISE`. After all
1685 * header name/value pairs are processed with this callback, and no
1686 * error has been detected, :type:`nghttp2_on_frame_recv_callback`
1687 * will be invoked. If there is an error in decompression,
1688 * :type:`nghttp2_on_frame_recv_callback` for the |frame| will not be
1691 * Both |name| and |value| are guaranteed to be NULL-terminated. The
1692 * |namelen| and |valuelen| do not include terminal NULL. If
1693 * `nghttp2_option_set_no_http_messaging()` is used with nonzero
1694 * value, NULL character may be included in |name| or |value| before
1697 * Please note that unless `nghttp2_option_set_no_http_messaging()` is
1698 * used, nghttp2 library does perform validation against the |name|
1699 * and the |value| using `nghttp2_check_header_name()` and
1700 * `nghttp2_check_header_value()`. In addition to this, nghttp2
1701 * performs validation based on HTTP Messaging rule, which is briefly
1702 * explained in :ref:`http-messaging` section.
1704 * If the application uses `nghttp2_session_mem_recv()`, it can return
1705 * :enum:`NGHTTP2_ERR_PAUSE` to make `nghttp2_session_mem_recv()`
1706 * return without processing further input bytes. The memory pointed
1707 * by |frame|, |name| and |value| parameters are retained until
1708 * `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called.
1709 * The application must retain the input bytes which was used to
1710 * produce these parameters, because it may refer to the memory region
1711 * included in the input bytes.
1713 * Returning :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close
1714 * the stream (promised stream if frame is PUSH_PROMISE) by issuing
1715 * RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. In this case,
1716 * :type:`nghttp2_on_header_callback` and
1717 * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a
1718 * different error code is desirable, use
1719 * `nghttp2_submit_rst_stream()` with a desired error code and then
1720 * return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Again, use
1721 * ``frame->push_promise.promised_stream_id`` as stream_id parameter
1722 * in `nghttp2_submit_rst_stream()` if frame is PUSH_PROMISE.
1724 * The implementation of this function must return 0 if it succeeds.
1725 * It may return :enum:`NGHTTP2_ERR_PAUSE` or
1726 * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. For other critical
1727 * failures, it must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If
1728 * the other nonzero value is returned, it is treated as
1729 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If
1730 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` is returned,
1731 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1732 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1734 * To set this callback to :type:`nghttp2_session_callbacks`, use
1735 * `nghttp2_session_callbacks_set_on_header_callback()`.
1739 * Application should properly limit the total buffer size to store
1740 * incoming header fields. Without it, peer may send large number
1741 * of header fields or large header fields to cause out of memory in
1742 * local endpoint. Due to how HPACK works, peer can do this
1743 * effectively without using much memory on their own.
1745 typedef int (*nghttp2_on_header_callback)(nghttp2_session *session,
1746 const nghttp2_frame *frame,
1747 const uint8_t *name, size_t namelen,
1748 const uint8_t *value, size_t valuelen,
1749 uint8_t flags, void *user_data);
1754 * Callback function invoked when a header name/value pair is received
1755 * for the |frame|. The |name| is header name. The |value| is header
1756 * value. The |flags| is bitwise OR of one or more of
1757 * :type:`nghttp2_nv_flag`.
1759 * This callback behaves like :type:`nghttp2_on_header_callback`,
1760 * except that |name| and |value| are stored in reference counted
1761 * buffer. If application wishes to keep these references without
1762 * copying them, use `nghttp2_rcbuf_incref()` to increment their
1763 * reference count. It is the application's responsibility to call
1764 * `nghttp2_rcbuf_decref()` if they called `nghttp2_rcbuf_incref()` so
1765 * as not to leak memory. If the |session| is created by
1766 * `nghttp2_session_server_new3()` or `nghttp2_session_client_new3()`,
1767 * the function to free memory is the one belongs to the mem
1768 * parameter. As long as this free function alives, |name| and
1769 * |value| can live after |session| was destroyed.
1771 typedef int (*nghttp2_on_header_callback2)(nghttp2_session *session,
1772 const nghttp2_frame *frame,
1773 nghttp2_rcbuf *name,
1774 nghttp2_rcbuf *value, uint8_t flags,
1780 * Callback function invoked when a invalid header name/value pair is
1781 * received for the |frame|.
1783 * The parameter and behaviour are similar to
1784 * :type:`nghttp2_on_header_callback`. The difference is that this
1785 * callback is only invoked when a invalid header name/value pair is
1786 * received which is treated as stream error if this callback is not
1787 * set. Only invalid regular header field are passed to this
1788 * callback. In other words, invalid pseudo header field is not
1789 * passed to this callback. Also header fields which includes upper
1790 * cased latter are also treated as error without passing them to this
1793 * This callback is only considered if HTTP messaging validation is
1794 * turned on (which is on by default, see
1795 * `nghttp2_option_set_no_http_messaging()`).
1797 * With this callback, application inspects the incoming invalid
1798 * field, and it also can reset stream from this callback by returning
1799 * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. By default, the
1800 * error code is :enum:`NGHTTP2_PROTOCOL_ERROR`. To change the error
1801 * code, call `nghttp2_submit_rst_stream()` with the error code of
1802 * choice in addition to returning
1803 * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.
1805 * If 0 is returned, the header field is ignored, and the stream is
1808 typedef int (*nghttp2_on_invalid_header_callback)(
1809 nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name,
1810 size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags,
1816 * Callback function invoked when a invalid header name/value pair is
1817 * received for the |frame|.
1819 * The parameter and behaviour are similar to
1820 * :type:`nghttp2_on_header_callback2`. The difference is that this
1821 * callback is only invoked when a invalid header name/value pair is
1822 * received which is silently ignored if this callback is not set.
1823 * Only invalid regular header field are passed to this callback. In
1824 * other words, invalid pseudo header field is not passed to this
1825 * callback. Also header fields which includes upper cased latter are
1826 * also treated as error without passing them to this callback.
1828 * This callback is only considered if HTTP messaging validation is
1829 * turned on (which is on by default, see
1830 * `nghttp2_option_set_no_http_messaging()`).
1832 * With this callback, application inspects the incoming invalid
1833 * field, and it also can reset stream from this callback by returning
1834 * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. By default, the
1835 * error code is :enum:`NGHTTP2_INTERNAL_ERROR`. To change the error
1836 * code, call `nghttp2_submit_rst_stream()` with the error code of
1837 * choice in addition to returning
1838 * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.
1840 typedef int (*nghttp2_on_invalid_header_callback2)(
1841 nghttp2_session *session, const nghttp2_frame *frame, nghttp2_rcbuf *name,
1842 nghttp2_rcbuf *value, uint8_t flags, void *user_data);
1847 * Callback function invoked when the library asks application how
1848 * many padding bytes are required for the transmission of the
1849 * |frame|. The application must choose the total length of payload
1850 * including padded bytes in range [frame->hd.length, max_payloadlen],
1851 * inclusive. Choosing number not in this range will be treated as
1852 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. Returning
1853 * ``frame->hd.length`` means no padding is added. Returning
1854 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will make
1855 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
1856 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1858 * To set this callback to :type:`nghttp2_session_callbacks`, use
1859 * `nghttp2_session_callbacks_set_select_padding_callback()`.
1861 typedef ssize_t (*nghttp2_select_padding_callback)(nghttp2_session *session,
1862 const nghttp2_frame *frame,
1863 size_t max_payloadlen,
1869 * Callback function invoked when library wants to get max length of
1870 * data to send data to the remote peer. The implementation of this
1871 * function should return a value in the following range. [1,
1872 * min(|session_remote_window_size|, |stream_remote_window_size|,
1873 * |remote_max_frame_size|)]. If a value greater than this range is
1874 * returned than the max allow value will be used. Returning a value
1875 * smaller than this range is treated as
1876 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. The |frame_type| is provided
1877 * for future extensibility and identifies the type of frame (see
1878 * :type:`nghttp2_frame_type`) for which to get the length for.
1879 * Currently supported frame types are: :enum:`NGHTTP2_DATA`.
1881 * This callback can be used to control the length in bytes for which
1882 * :type:`nghttp2_data_source_read_callback` is allowed to send to the
1883 * remote endpoint. This callback is optional. Returning
1884 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the entire session
1887 * To set this callback to :type:`nghttp2_session_callbacks`, use
1888 * `nghttp2_session_callbacks_set_data_source_read_length_callback()`.
1890 typedef ssize_t (*nghttp2_data_source_read_length_callback)(
1891 nghttp2_session *session, uint8_t frame_type, int32_t stream_id,
1892 int32_t session_remote_window_size, int32_t stream_remote_window_size,
1893 uint32_t remote_max_frame_size, void *user_data);
1898 * Callback function invoked when a frame header is received. The
1899 * |hd| points to received frame header.
1901 * Unlike :type:`nghttp2_on_frame_recv_callback`, this callback will
1902 * also be called when frame header of CONTINUATION frame is received.
1904 * If both :type:`nghttp2_on_begin_frame_callback` and
1905 * :type:`nghttp2_on_begin_headers_callback` are set and HEADERS or
1906 * PUSH_PROMISE is received, :type:`nghttp2_on_begin_frame_callback`
1907 * will be called first.
1909 * The implementation of this function must return 0 if it succeeds.
1910 * If nonzero value is returned, it is treated as fatal error and
1911 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1912 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1914 * To set this callback to :type:`nghttp2_session_callbacks`, use
1915 * `nghttp2_session_callbacks_set_on_begin_frame_callback()`.
1917 typedef int (*nghttp2_on_begin_frame_callback)(nghttp2_session *session,
1918 const nghttp2_frame_hd *hd,
1924 * Callback function invoked when chunk of extension frame payload is
1925 * received. The |hd| points to frame header. The received
1926 * chunk is |data| of length |len|.
1928 * The implementation of this function must return 0 if it succeeds.
1930 * To abort processing this extension frame, return
1931 * :enum:`NGHTTP2_ERR_CANCEL`.
1933 * If fatal error occurred, application should return
1934 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,
1935 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1936 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the
1937 * other values are returned, currently they are treated as
1938 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1940 typedef int (*nghttp2_on_extension_chunk_recv_callback)(
1941 nghttp2_session *session, const nghttp2_frame_hd *hd, const uint8_t *data,
1942 size_t len, void *user_data);
1947 * Callback function invoked when library asks the application to
1948 * unpack extension payload from its wire format. The extension
1949 * payload has been passed to the application using
1950 * :type:`nghttp2_on_extension_chunk_recv_callback`. The frame header
1951 * is already unpacked by the library and provided as |hd|.
1953 * To receive extension frames, the application must tell desired
1954 * extension frame type to the library using
1955 * `nghttp2_option_set_user_recv_extension_type()`.
1957 * The implementation of this function may store the pointer to the
1958 * created object as a result of unpacking in |*payload|, and returns
1959 * 0. The pointer stored in |*payload| is opaque to the library, and
1960 * the library does not own its pointer. |*payload| is initialized as
1961 * ``NULL``. The |*payload| is available as ``frame->ext.payload`` in
1962 * :type:`nghttp2_on_frame_recv_callback`. Therefore if application
1963 * can free that memory inside :type:`nghttp2_on_frame_recv_callback`
1964 * callback. Of course, application has a liberty not ot use
1965 * |*payload|, and do its own mechanism to process extension frames.
1967 * To abort processing this extension frame, return
1968 * :enum:`NGHTTP2_ERR_CANCEL`.
1970 * If fatal error occurred, application should return
1971 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,
1972 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions
1973 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the
1974 * other values are returned, currently they are treated as
1975 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
1977 typedef int (*nghttp2_unpack_extension_callback)(nghttp2_session *session,
1979 const nghttp2_frame_hd *hd,
1985 * Callback function invoked when library asks the application to pack
1986 * extension payload in its wire format. The frame header will be
1987 * packed by library. Application must pack payload only.
1988 * ``frame->ext.payload`` is the object passed to
1989 * `nghttp2_submit_extension()` as payload parameter. Application
1990 * must pack extension payload to the |buf| of its capacity |len|
1991 * bytes. The |len| is at least 16KiB.
1993 * The implementation of this function should return the number of
1994 * bytes written into |buf| when it succeeds.
1996 * To abort processing this extension frame, return
1997 * :enum:`NGHTTP2_ERR_CANCEL`, and
1998 * :type:`nghttp2_on_frame_not_send_callback` will be invoked.
2000 * If fatal error occurred, application should return
2001 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,
2002 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
2003 * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the
2004 * other values are returned, currently they are treated as
2005 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. If the return value is
2006 * strictly larger than |len|, it is treated as
2007 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`.
2009 typedef ssize_t (*nghttp2_pack_extension_callback)(nghttp2_session *session,
2010 uint8_t *buf, size_t len,
2011 const nghttp2_frame *frame,
2017 * Callback function invoked when library provides the error message
2018 * intended for human consumption. This callback is solely for
2019 * debugging purpose. The |msg| is typically NULL-terminated string
2020 * of length |len|. |len| does not include the sentinel NULL
2023 * This function is deprecated. The new application should use
2024 * :type:`nghttp2_error_callback2`.
2026 * The format of error message may change between nghttp2 library
2027 * versions. The application should not depend on the particular
2030 * Normally, application should return 0 from this callback. If fatal
2031 * error occurred while doing something in this callback, application
2032 * should return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,
2033 * library will return immediately with return value
2034 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if nonzero value
2035 * is returned from this callback, they are treated as
2036 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`, but application should not
2037 * rely on this details.
2039 typedef int (*nghttp2_error_callback)(nghttp2_session *session, const char *msg,
2040 size_t len, void *user_data);
2045 * Callback function invoked when library provides the error code, and
2046 * message. This callback is solely for debugging purpose.
2047 * |lib_error_code| is one of error code defined in
2048 * :enum:`nghttp2_error`. The |msg| is typically NULL-terminated
2049 * string of length |len|, and intended for human consumption. |len|
2050 * does not include the sentinel NULL character.
2052 * The format of error message may change between nghttp2 library
2053 * versions. The application should not depend on the particular
2056 * Normally, application should return 0 from this callback. If fatal
2057 * error occurred while doing something in this callback, application
2058 * should return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,
2059 * library will return immediately with return value
2060 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if nonzero value
2061 * is returned from this callback, they are treated as
2062 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`, but application should not
2063 * rely on this details.
2065 typedef int (*nghttp2_error_callback2)(nghttp2_session *session,
2066 int lib_error_code, const char *msg,
2067 size_t len, void *user_data);
2069 struct nghttp2_session_callbacks;
2074 * Callback functions for :type:`nghttp2_session`. The details of
2075 * this structure are intentionally hidden from the public API.
2077 typedef struct nghttp2_session_callbacks nghttp2_session_callbacks;
2082 * Initializes |*callbacks_ptr| with NULL values.
2084 * The initialized object can be used when initializing multiple
2085 * :type:`nghttp2_session` objects.
2087 * When the application finished using this object, it can use
2088 * `nghttp2_session_callbacks_del()` to free its memory.
2090 * This function returns 0 if it succeeds, or one of the following
2091 * negative error codes:
2093 * :enum:`NGHTTP2_ERR_NOMEM`
2097 nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr);
2102 * Frees any resources allocated for |callbacks|. If |callbacks| is
2103 * ``NULL``, this function does nothing.
2106 nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks);
2111 * Sets callback function invoked when a session wants to send data to
2112 * the remote peer. This callback is not necessary if the application
2113 * uses solely `nghttp2_session_mem_send()` to serialize data to
2116 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback(
2117 nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback);
2122 * Sets callback function invoked when the a session wants to receive
2123 * data from the remote peer. This callback is not necessary if the
2124 * application uses solely `nghttp2_session_mem_recv()` to process
2127 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback(
2128 nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback);
2133 * Sets callback function invoked by `nghttp2_session_recv()` and
2134 * `nghttp2_session_mem_recv()` when a frame is received.
2136 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback(
2137 nghttp2_session_callbacks *cbs,
2138 nghttp2_on_frame_recv_callback on_frame_recv_callback);
2143 * Sets callback function invoked by `nghttp2_session_recv()` and
2144 * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is
2148 nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(
2149 nghttp2_session_callbacks *cbs,
2150 nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback);
2155 * Sets callback function invoked when a chunk of data in DATA frame
2158 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_data_chunk_recv_callback(
2159 nghttp2_session_callbacks *cbs,
2160 nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback);
2165 * Sets callback function invoked before a non-DATA frame is sent.
2167 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_before_frame_send_callback(
2168 nghttp2_session_callbacks *cbs,
2169 nghttp2_before_frame_send_callback before_frame_send_callback);
2174 * Sets callback function invoked after a frame is sent.
2176 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_send_callback(
2177 nghttp2_session_callbacks *cbs,
2178 nghttp2_on_frame_send_callback on_frame_send_callback);
2183 * Sets callback function invoked when a non-DATA frame is not sent
2184 * because of an error.
2186 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_not_send_callback(
2187 nghttp2_session_callbacks *cbs,
2188 nghttp2_on_frame_not_send_callback on_frame_not_send_callback);
2193 * Sets callback function invoked when the stream is closed.
2195 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_stream_close_callback(
2196 nghttp2_session_callbacks *cbs,
2197 nghttp2_on_stream_close_callback on_stream_close_callback);
2202 * Sets callback function invoked when the reception of header block
2203 * in HEADERS or PUSH_PROMISE is started.
2205 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_headers_callback(
2206 nghttp2_session_callbacks *cbs,
2207 nghttp2_on_begin_headers_callback on_begin_headers_callback);
2212 * Sets callback function invoked when a header name/value pair is
2214 * `nghttp2_session_callbacks_set_on_header_callback()` and
2215 * `nghttp2_session_callbacks_set_on_header_callback2()` are used to
2216 * set callbacks, the latter has the precedence.
2218 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback(
2219 nghttp2_session_callbacks *cbs,
2220 nghttp2_on_header_callback on_header_callback);
2225 * Sets callback function invoked when a header name/value pair is
2228 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback2(
2229 nghttp2_session_callbacks *cbs,
2230 nghttp2_on_header_callback2 on_header_callback2);
2235 * Sets callback function invoked when a invalid header name/value
2236 * pair is received. If both
2237 * `nghttp2_session_callbacks_set_on_invalid_header_callback()` and
2238 * `nghttp2_session_callbacks_set_on_invalid_header_callback2()` are
2239 * used to set callbacks, the latter takes the precedence.
2241 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback(
2242 nghttp2_session_callbacks *cbs,
2243 nghttp2_on_invalid_header_callback on_invalid_header_callback);
2248 * Sets callback function invoked when a invalid header name/value
2251 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback2(
2252 nghttp2_session_callbacks *cbs,
2253 nghttp2_on_invalid_header_callback2 on_invalid_header_callback2);
2258 * Sets callback function invoked when the library asks application
2259 * how many padding bytes are required for the transmission of the
2262 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback(
2263 nghttp2_session_callbacks *cbs,
2264 nghttp2_select_padding_callback select_padding_callback);
2269 * Sets callback function determine the length allowed in
2270 * :type:`nghttp2_data_source_read_callback`.
2273 nghttp2_session_callbacks_set_data_source_read_length_callback(
2274 nghttp2_session_callbacks *cbs,
2275 nghttp2_data_source_read_length_callback data_source_read_length_callback);
2280 * Sets callback function invoked when a frame header is received.
2282 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_frame_callback(
2283 nghttp2_session_callbacks *cbs,
2284 nghttp2_on_begin_frame_callback on_begin_frame_callback);
2289 * Sets callback function invoked when
2290 * :enum:`NGHTTP2_DATA_FLAG_NO_COPY` is used in
2291 * :type:`nghttp2_data_source_read_callback` to avoid data copy.
2293 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_data_callback(
2294 nghttp2_session_callbacks *cbs,
2295 nghttp2_send_data_callback send_data_callback);
2300 * Sets callback function invoked when the library asks the
2301 * application to pack extension frame payload in wire format.
2303 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback(
2304 nghttp2_session_callbacks *cbs,
2305 nghttp2_pack_extension_callback pack_extension_callback);
2310 * Sets callback function invoked when the library asks the
2311 * application to unpack extension frame payload from wire format.
2313 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_unpack_extension_callback(
2314 nghttp2_session_callbacks *cbs,
2315 nghttp2_unpack_extension_callback unpack_extension_callback);
2320 * Sets callback function invoked when chunk of extension frame
2321 * payload is received.
2324 nghttp2_session_callbacks_set_on_extension_chunk_recv_callback(
2325 nghttp2_session_callbacks *cbs,
2326 nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback);
2331 * Sets callback function invoked when library tells error message to
2334 * This function is deprecated. The new application should use
2335 * `nghttp2_session_callbacks_set_error_callback2()`.
2337 * If both :type:`nghttp2_error_callback` and
2338 * :type:`nghttp2_error_callback2` are set, the latter takes
2341 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback(
2342 nghttp2_session_callbacks *cbs, nghttp2_error_callback error_callback);
2347 * Sets callback function invoked when library tells error code, and
2348 * message to the application.
2350 * If both :type:`nghttp2_error_callback` and
2351 * :type:`nghttp2_error_callback2` are set, the latter takes
2354 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback2(
2355 nghttp2_session_callbacks *cbs, nghttp2_error_callback2 error_callback2);
2360 * Custom memory allocator to replace malloc(). The |mem_user_data|
2361 * is the mem_user_data member of :type:`nghttp2_mem` structure.
2363 typedef void *(*nghttp2_malloc)(size_t size, void *mem_user_data);
2368 * Custom memory allocator to replace free(). The |mem_user_data| is
2369 * the mem_user_data member of :type:`nghttp2_mem` structure.
2371 typedef void (*nghttp2_free)(void *ptr, void *mem_user_data);
2376 * Custom memory allocator to replace calloc(). The |mem_user_data|
2377 * is the mem_user_data member of :type:`nghttp2_mem` structure.
2379 typedef void *(*nghttp2_calloc)(size_t nmemb, size_t size, void *mem_user_data);
2384 * Custom memory allocator to replace realloc(). The |mem_user_data|
2385 * is the mem_user_data member of :type:`nghttp2_mem` structure.
2387 typedef void *(*nghttp2_realloc)(void *ptr, size_t size, void *mem_user_data);
2392 * Custom memory allocator functions and user defined pointer. The
2393 * |mem_user_data| member is passed to each allocator function. This
2394 * can be used, for example, to achieve per-session memory pool.
2396 * In the following example code, ``my_malloc``, ``my_free``,
2397 * ``my_calloc`` and ``my_realloc`` are the replacement of the
2398 * standard allocators ``malloc``, ``free``, ``calloc`` and
2399 * ``realloc`` respectively::
2401 * void *my_malloc_cb(size_t size, void *mem_user_data) {
2402 * return my_malloc(size);
2405 * void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); }
2407 * void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) {
2408 * return my_calloc(nmemb, size);
2411 * void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) {
2412 * return my_realloc(ptr, size);
2415 * void session_new() {
2416 * nghttp2_session *session;
2417 * nghttp2_session_callbacks *callbacks;
2418 * nghttp2_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb,
2423 * nghttp2_session_client_new3(&session, callbacks, NULL, NULL, &mem);
2430 * An arbitrary user supplied data. This is passed to each
2431 * allocator function.
2433 void *mem_user_data;
2435 * Custom allocator function to replace malloc().
2437 nghttp2_malloc malloc;
2439 * Custom allocator function to replace free().
2443 * Custom allocator function to replace calloc().
2445 nghttp2_calloc calloc;
2447 * Custom allocator function to replace realloc().
2449 nghttp2_realloc realloc;
2452 struct nghttp2_option;
2457 * Configuration options for :type:`nghttp2_session`. The details of
2458 * this structure are intentionally hidden from the public API.
2460 typedef struct nghttp2_option nghttp2_option;
2465 * Initializes |*option_ptr| with default values.
2467 * When the application finished using this object, it can use
2468 * `nghttp2_option_del()` to free its memory.
2470 * This function returns 0 if it succeeds, or one of the following
2471 * negative error codes:
2473 * :enum:`NGHTTP2_ERR_NOMEM`
2476 NGHTTP2_EXTERN int nghttp2_option_new(nghttp2_option **option_ptr);
2481 * Frees any resources allocated for |option|. If |option| is
2482 * ``NULL``, this function does nothing.
2484 NGHTTP2_EXTERN void nghttp2_option_del(nghttp2_option *option);
2489 * This option prevents the library from sending WINDOW_UPDATE for a
2490 * connection automatically. If this option is set to nonzero, the
2491 * library won't send WINDOW_UPDATE for DATA until application calls
2492 * `nghttp2_session_consume()` to indicate the consumed amount of
2493 * data. Don't use `nghttp2_submit_window_update()` for this purpose.
2494 * By default, this option is set to zero.
2497 nghttp2_option_set_no_auto_window_update(nghttp2_option *option, int val);
2502 * This option sets the SETTINGS_MAX_CONCURRENT_STREAMS value of
2503 * remote endpoint as if it is received in SETTINGS frame. Without
2504 * specifying this option, the maximum number of outgoing concurrent
2505 * streams is initially limited to 100 to avoid issues when the local
2506 * endpoint submits lots of requests before receiving initial SETTINGS
2507 * frame from the remote endpoint, since sending them at once to the
2508 * remote endpoint could lead to rejection of some of the requests.
2509 * This value will be overwritten when the local endpoint receives
2510 * initial SETTINGS frame from the remote endpoint, either to the
2511 * value advertised in SETTINGS_MAX_CONCURRENT_STREAMS or to the
2512 * default value (unlimited) if none was advertised.
2515 nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option,
2521 * By default, nghttp2 library, if configured as server, requires
2522 * first 24 bytes of client magic byte string (MAGIC). In most cases,
2523 * this will simplify the implementation of server. But sometimes
2524 * server may want to detect the application protocol based on first
2525 * few bytes on clear text communication.
2527 * If this option is used with nonzero |val|, nghttp2 library does not
2528 * handle MAGIC. It still checks following SETTINGS frame. This
2529 * means that applications should deal with MAGIC by themselves.
2531 * If this option is not used or used with zero value, if MAGIC does
2532 * not match :macro:`NGHTTP2_CLIENT_MAGIC`, `nghttp2_session_recv()`
2533 * and `nghttp2_session_mem_recv()` will return error
2534 * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`, which is fatal error.
2537 nghttp2_option_set_no_recv_client_magic(nghttp2_option *option, int val);
2542 * By default, nghttp2 library enforces subset of HTTP Messaging rules
2543 * described in `HTTP/2 specification, section 8
2544 * <https://tools.ietf.org/html/rfc7540#section-8>`_. See
2545 * :ref:`http-messaging` section for details. For those applications
2546 * who use nghttp2 library as non-HTTP use, give nonzero to |val| to
2547 * disable this enforcement. Please note that disabling this feature
2548 * does not change the fundamental client and server model of HTTP.
2549 * That is, even if the validation is disabled, only client can send
2552 NGHTTP2_EXTERN void nghttp2_option_set_no_http_messaging(nghttp2_option *option,
2558 * RFC 7540 does not enforce any limit on the number of incoming
2559 * reserved streams (in RFC 7540 terms, streams in reserved (remote)
2560 * state). This only affects client side, since only server can push
2561 * streams. Malicious server can push arbitrary number of streams,
2562 * and make client's memory exhausted. This option can set the
2563 * maximum number of such incoming streams to avoid possible memory
2564 * exhaustion. If this option is set, and pushed streams are
2565 * automatically closed on reception, without calling user provided
2566 * callback, if they exceed the given limit. The default value is
2567 * 200. If session is configured as server side, this option has no
2568 * effect. Server can control the number of streams to push.
2571 nghttp2_option_set_max_reserved_remote_streams(nghttp2_option *option,
2577 * Sets extension frame type the application is willing to handle with
2578 * user defined callbacks (see
2579 * :type:`nghttp2_on_extension_chunk_recv_callback` and
2580 * :type:`nghttp2_unpack_extension_callback`). The |type| is
2581 * extension frame type, and must be strictly greater than 0x9.
2582 * Otherwise, this function does nothing. The application can call
2583 * this function multiple times to set more than one frame type to
2584 * receive. The application does not have to call this function if it
2585 * just sends extension frames.
2588 nghttp2_option_set_user_recv_extension_type(nghttp2_option *option,
2594 * Sets extension frame type the application is willing to receive
2595 * using builtin handler. The |type| is the extension frame type to
2596 * receive, and must be strictly greater than 0x9. Otherwise, this
2597 * function does nothing. The application can call this function
2598 * multiple times to set more than one frame type to receive. The
2599 * application does not have to call this function if it just sends
2602 * If same frame type is passed to both
2603 * `nghttp2_option_set_builtin_recv_extension_type()` and
2604 * `nghttp2_option_set_user_recv_extension_type()`, the latter takes
2608 nghttp2_option_set_builtin_recv_extension_type(nghttp2_option *option,
2614 * This option prevents the library from sending PING frame with ACK
2615 * flag set automatically when PING frame without ACK flag set is
2616 * received. If this option is set to nonzero, the library won't send
2617 * PING frame with ACK flag set in the response for incoming PING
2618 * frame. The application can send PING frame with ACK flag set using
2619 * `nghttp2_submit_ping()` with :enum:`NGHTTP2_FLAG_ACK` as flags
2622 NGHTTP2_EXTERN void nghttp2_option_set_no_auto_ping_ack(nghttp2_option *option,
2628 * This option sets the maximum length of header block (a set of
2629 * header fields per one HEADERS frame) to send. The length of a
2630 * given set of header fields is calculated using
2631 * `nghttp2_hd_deflate_bound()`. The default value is 64KiB. If
2632 * application attempts to send header fields larger than this limit,
2633 * the transmission of the frame fails with error code
2634 * :enum:`NGHTTP2_ERR_FRAME_SIZE_ERROR`.
2637 nghttp2_option_set_max_send_header_block_length(nghttp2_option *option,
2643 * This option sets the maximum dynamic table size for deflating
2644 * header fields. The default value is 4KiB. In HTTP/2, receiver of
2645 * deflated header block can specify maximum dynamic table size. The
2646 * actual maximum size is the minimum of the size receiver specified
2647 * and this option value.
2650 nghttp2_option_set_max_deflate_dynamic_table_size(nghttp2_option *option,
2656 * This option prevents the library from retaining closed streams to
2657 * maintain the priority tree. If this option is set to nonzero,
2658 * applications can discard closed stream completely to save memory.
2660 NGHTTP2_EXTERN void nghttp2_option_set_no_closed_streams(nghttp2_option *option,
2666 * This function sets the maximum number of outgoing SETTINGS ACK and
2667 * PING ACK frames retained in :type:`nghttp2_session` object. If
2668 * more than those frames are retained, the peer is considered to be
2669 * misbehaving and session will be closed. The default value is 1000.
2671 NGHTTP2_EXTERN void nghttp2_option_set_max_outbound_ack(nghttp2_option *option,
2677 * This function sets the maximum number of SETTINGS entries per
2678 * SETTINGS frame that will be accepted. If more than those entries
2679 * are received, the peer is considered to be misbehaving and session
2680 * will be closed. The default value is 32.
2682 NGHTTP2_EXTERN void nghttp2_option_set_max_settings(nghttp2_option *option,
2688 * Initializes |*session_ptr| for client use. The all members of
2689 * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|
2690 * does not store |callbacks|. The |user_data| is an arbitrary user
2691 * supplied data, which will be passed to the callback functions.
2693 * The :type:`nghttp2_send_callback` must be specified. If the
2694 * application code uses `nghttp2_session_recv()`, the
2695 * :type:`nghttp2_recv_callback` must be specified. The other members
2696 * of |callbacks| can be ``NULL``.
2698 * If this function fails, |*session_ptr| is left untouched.
2700 * This function returns 0 if it succeeds, or one of the following
2701 * negative error codes:
2703 * :enum:`NGHTTP2_ERR_NOMEM`
2707 nghttp2_session_client_new(nghttp2_session **session_ptr,
2708 const nghttp2_session_callbacks *callbacks,
2714 * Initializes |*session_ptr| for server use. The all members of
2715 * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|
2716 * does not store |callbacks|. The |user_data| is an arbitrary user
2717 * supplied data, which will be passed to the callback functions.
2719 * The :type:`nghttp2_send_callback` must be specified. If the
2720 * application code uses `nghttp2_session_recv()`, the
2721 * :type:`nghttp2_recv_callback` must be specified. The other members
2722 * of |callbacks| can be ``NULL``.
2724 * If this function fails, |*session_ptr| is left untouched.
2726 * This function returns 0 if it succeeds, or one of the following
2727 * negative error codes:
2729 * :enum:`NGHTTP2_ERR_NOMEM`
2733 nghttp2_session_server_new(nghttp2_session **session_ptr,
2734 const nghttp2_session_callbacks *callbacks,
2740 * Like `nghttp2_session_client_new()`, but with additional options
2741 * specified in the |option|.
2743 * The |option| can be ``NULL`` and the call is equivalent to
2744 * `nghttp2_session_client_new()`.
2746 * This function does not take ownership |option|. The application is
2747 * responsible for freeing |option| if it finishes using the object.
2749 * The library code does not refer to |option| after this function
2752 * This function returns 0 if it succeeds, or one of the following
2753 * negative error codes:
2755 * :enum:`NGHTTP2_ERR_NOMEM`
2759 nghttp2_session_client_new2(nghttp2_session **session_ptr,
2760 const nghttp2_session_callbacks *callbacks,
2761 void *user_data, const nghttp2_option *option);
2766 * Like `nghttp2_session_server_new()`, but with additional options
2767 * specified in the |option|.
2769 * The |option| can be ``NULL`` and the call is equivalent to
2770 * `nghttp2_session_server_new()`.
2772 * This function does not take ownership |option|. The application is
2773 * responsible for freeing |option| if it finishes using the object.
2775 * The library code does not refer to |option| after this function
2778 * This function returns 0 if it succeeds, or one of the following
2779 * negative error codes:
2781 * :enum:`NGHTTP2_ERR_NOMEM`
2785 nghttp2_session_server_new2(nghttp2_session **session_ptr,
2786 const nghttp2_session_callbacks *callbacks,
2787 void *user_data, const nghttp2_option *option);
2792 * Like `nghttp2_session_client_new2()`, but with additional custom
2793 * memory allocator specified in the |mem|.
2795 * The |mem| can be ``NULL`` and the call is equivalent to
2796 * `nghttp2_session_client_new2()`.
2798 * This function does not take ownership |mem|. The application is
2799 * responsible for freeing |mem|.
2801 * The library code does not refer to |mem| pointer after this
2802 * function returns, so the application can safely free it.
2804 * This function returns 0 if it succeeds, or one of the following
2805 * negative error codes:
2807 * :enum:`NGHTTP2_ERR_NOMEM`
2810 NGHTTP2_EXTERN int nghttp2_session_client_new3(
2811 nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,
2812 void *user_data, const nghttp2_option *option, nghttp2_mem *mem);
2817 * Like `nghttp2_session_server_new2()`, but with additional custom
2818 * memory allocator specified in the |mem|.
2820 * The |mem| can be ``NULL`` and the call is equivalent to
2821 * `nghttp2_session_server_new2()`.
2823 * This function does not take ownership |mem|. The application is
2824 * responsible for freeing |mem|.
2826 * The library code does not refer to |mem| pointer after this
2827 * function returns, so the application can safely free it.
2829 * This function returns 0 if it succeeds, or one of the following
2830 * negative error codes:
2832 * :enum:`NGHTTP2_ERR_NOMEM`
2835 NGHTTP2_EXTERN int nghttp2_session_server_new3(
2836 nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,
2837 void *user_data, const nghttp2_option *option, nghttp2_mem *mem);
2842 * Frees any resources allocated for |session|. If |session| is
2843 * ``NULL``, this function does nothing.
2845 NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session);
2850 * Sends pending frames to the remote peer.
2852 * This function retrieves the highest prioritized frame from the
2853 * outbound queue and sends it to the remote peer. It does this as
2854 * many as possible until the user callback
2855 * :type:`nghttp2_send_callback` returns
2856 * :enum:`NGHTTP2_ERR_WOULDBLOCK` or the outbound queue becomes empty.
2857 * This function calls several callback functions which are passed
2858 * when initializing the |session|. Here is the simple time chart
2859 * which tells when each callback is invoked:
2861 * 1. Get the next frame to send from outbound queue.
2863 * 2. Prepare transmission of the frame.
2865 * 3. If the control frame cannot be sent because some preconditions
2866 * are not met (e.g., request HEADERS cannot be sent after GOAWAY),
2867 * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort
2868 * the following steps.
2870 * 4. If the frame is HEADERS, PUSH_PROMISE or DATA,
2871 * :type:`nghttp2_select_padding_callback` is invoked.
2873 * 5. If the frame is request HEADERS, the stream is opened here.
2875 * 6. :type:`nghttp2_before_frame_send_callback` is invoked.
2877 * 7. If :enum:`NGHTTP2_ERR_CANCEL` is returned from
2878 * :type:`nghttp2_before_frame_send_callback`, the current frame
2879 * transmission is canceled, and
2880 * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort
2881 * the following steps.
2883 * 8. :type:`nghttp2_send_callback` is invoked one or more times to
2886 * 9. :type:`nghttp2_on_frame_send_callback` is invoked.
2888 * 10. If the transmission of the frame triggers closure of the
2889 * stream, the stream is closed and
2890 * :type:`nghttp2_on_stream_close_callback` is invoked.
2892 * This function returns 0 if it succeeds, or one of the following
2893 * negative error codes:
2895 * :enum:`NGHTTP2_ERR_NOMEM`
2897 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
2898 * The callback function failed.
2900 NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session);
2905 * Returns the serialized data to send.
2907 * This function behaves like `nghttp2_session_send()` except that it
2908 * does not use :type:`nghttp2_send_callback` to transmit data.
2909 * Instead, it assigns the pointer to the serialized data to the
2910 * |*data_ptr| and returns its length. The other callbacks are called
2911 * in the same way as they are in `nghttp2_session_send()`.
2913 * If no data is available to send, this function returns 0.
2915 * This function may not return all serialized data in one invocation.
2916 * To get all data, call this function repeatedly until it returns 0
2917 * or one of negative error codes.
2919 * The assigned |*data_ptr| is valid until the next call of
2920 * `nghttp2_session_mem_send()` or `nghttp2_session_send()`.
2922 * The caller must send all data before sending the next chunk of
2925 * This function returns the length of the data pointed by the
2926 * |*data_ptr| if it succeeds, or one of the following negative error
2929 * :enum:`NGHTTP2_ERR_NOMEM`
2934 * This function may produce very small byte string. If that is the
2935 * case, and application disables Nagle algorithm (``TCP_NODELAY``),
2936 * then writing this small chunk leads to very small packet, and it
2937 * is very inefficient. An application should be responsible to
2938 * buffer up small chunks of data as necessary to avoid this
2941 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session,
2942 const uint8_t **data_ptr);
2947 * Receives frames from the remote peer.
2949 * This function receives as many frames as possible until the user
2950 * callback :type:`nghttp2_recv_callback` returns
2951 * :enum:`NGHTTP2_ERR_WOULDBLOCK`. This function calls several
2952 * callback functions which are passed when initializing the
2953 * |session|. Here is the simple time chart which tells when each
2954 * callback is invoked:
2956 * 1. :type:`nghttp2_recv_callback` is invoked one or more times to
2957 * receive frame header.
2959 * 2. When frame header is received,
2960 * :type:`nghttp2_on_begin_frame_callback` is invoked.
2962 * 3. If the frame is DATA frame:
2964 * 1. :type:`nghttp2_recv_callback` is invoked to receive DATA
2965 * payload. For each chunk of data,
2966 * :type:`nghttp2_on_data_chunk_recv_callback` is invoked.
2968 * 2. If one DATA frame is completely received,
2969 * :type:`nghttp2_on_frame_recv_callback` is invoked. If the
2970 * reception of the frame triggers the closure of the stream,
2971 * :type:`nghttp2_on_stream_close_callback` is invoked.
2973 * 4. If the frame is the control frame:
2975 * 1. :type:`nghttp2_recv_callback` is invoked one or more times to
2976 * receive whole frame.
2978 * 2. If the received frame is valid, then following actions are
2979 * taken. If the frame is either HEADERS or PUSH_PROMISE,
2980 * :type:`nghttp2_on_begin_headers_callback` is invoked. Then
2981 * :type:`nghttp2_on_header_callback` is invoked for each header
2982 * name/value pair. For invalid header field,
2983 * :type:`nghttp2_on_invalid_header_callback` is called. After
2984 * all name/value pairs are emitted successfully,
2985 * :type:`nghttp2_on_frame_recv_callback` is invoked. For other
2986 * frames, :type:`nghttp2_on_frame_recv_callback` is invoked.
2987 * If the reception of the frame triggers the closure of the
2988 * stream, :type:`nghttp2_on_stream_close_callback` is invoked.
2990 * 3. If the received frame is unpacked but is interpreted as
2991 * invalid, :type:`nghttp2_on_invalid_frame_recv_callback` is
2994 * This function returns 0 if it succeeds, or one of the following
2995 * negative error codes:
2997 * :enum:`NGHTTP2_ERR_EOF`
2998 * The remote peer did shutdown on the connection.
2999 * :enum:`NGHTTP2_ERR_NOMEM`
3001 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
3002 * The callback function failed.
3003 * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`
3004 * Invalid client magic was detected. This error only returns
3005 * when |session| was configured as server and
3006 * `nghttp2_option_set_no_recv_client_magic()` is not used with
3008 * :enum:`NGHTTP2_ERR_FLOODED`
3009 * Flooding was detected in this HTTP/2 session, and it must be
3010 * closed. This is most likely caused by misbehaviour of peer.
3012 NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session);
3017 * Processes data |in| as an input from the remote endpoint. The
3018 * |inlen| indicates the number of bytes in the |in|.
3020 * This function behaves like `nghttp2_session_recv()` except that it
3021 * does not use :type:`nghttp2_recv_callback` to receive data; the
3022 * |in| is the only data for the invocation of this function. If all
3023 * bytes are processed, this function returns. The other callbacks
3024 * are called in the same way as they are in `nghttp2_session_recv()`.
3026 * In the current implementation, this function always tries to
3027 * processes all input data unless either an error occurs or
3028 * :enum:`NGHTTP2_ERR_PAUSE` is returned from
3029 * :type:`nghttp2_on_header_callback` or
3030 * :type:`nghttp2_on_data_chunk_recv_callback`. If
3031 * :enum:`NGHTTP2_ERR_PAUSE` is used, the return value includes the
3032 * number of bytes which was used to produce the data or frame for the
3035 * This function returns the number of processed bytes, or one of the
3036 * following negative error codes:
3038 * :enum:`NGHTTP2_ERR_NOMEM`
3040 * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`
3041 * The callback function failed.
3042 * :enum:`NGHTTP2_ERR_BAD_CLIENT_MAGIC`
3043 * Invalid client magic was detected. This error only returns
3044 * when |session| was configured as server and
3045 * `nghttp2_option_set_no_recv_client_magic()` is not used with
3047 * :enum:`NGHTTP2_ERR_FLOODED`
3048 * Flooding was detected in this HTTP/2 session, and it must be
3049 * closed. This is most likely caused by misbehaviour of peer.
3051 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
3058 * Puts back previously deferred DATA frame in the stream |stream_id|
3059 * to the outbound queue.
3061 * This function returns 0 if it succeeds, or one of the following
3062 * negative error codes:
3064 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3065 * The stream does not exist; or no deferred data exist.
3066 * :enum:`NGHTTP2_ERR_NOMEM`
3069 NGHTTP2_EXTERN int nghttp2_session_resume_data(nghttp2_session *session,
3075 * Returns nonzero value if |session| wants to receive data from the
3078 * If both `nghttp2_session_want_read()` and
3079 * `nghttp2_session_want_write()` return 0, the application should
3080 * drop the connection.
3082 NGHTTP2_EXTERN int nghttp2_session_want_read(nghttp2_session *session);
3087 * Returns nonzero value if |session| wants to send data to the remote
3090 * If both `nghttp2_session_want_read()` and
3091 * `nghttp2_session_want_write()` return 0, the application should
3092 * drop the connection.
3094 NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session);
3099 * Returns stream_user_data for the stream |stream_id|. The
3100 * stream_user_data is provided by `nghttp2_submit_request()`,
3101 * `nghttp2_submit_headers()` or
3102 * `nghttp2_session_set_stream_user_data()`. Unless it is set using
3103 * `nghttp2_session_set_stream_user_data()`, if the stream is
3104 * initiated by the remote endpoint, stream_user_data is always
3105 * ``NULL``. If the stream does not exist, this function returns
3108 NGHTTP2_EXTERN void *
3109 nghttp2_session_get_stream_user_data(nghttp2_session *session,
3115 * Sets the |stream_user_data| to the stream denoted by the
3116 * |stream_id|. If a stream user data is already set to the stream,
3117 * it is replaced with the |stream_user_data|. It is valid to specify
3118 * ``NULL`` in the |stream_user_data|, which nullifies the associated
3121 * It is valid to set the |stream_user_data| to the stream reserved by
3122 * PUSH_PROMISE frame.
3124 * This function returns 0 if it succeeds, or one of following
3125 * negative error codes:
3127 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3128 * The stream does not exist
3131 nghttp2_session_set_stream_user_data(nghttp2_session *session,
3132 int32_t stream_id, void *stream_user_data);
3137 * Sets |user_data| to |session|, overwriting the existing user data
3138 * specified in `nghttp2_session_client_new()`, or
3139 * `nghttp2_session_server_new()`.
3141 NGHTTP2_EXTERN void nghttp2_session_set_user_data(nghttp2_session *session,
3147 * Returns the number of frames in the outbound queue. This does not
3148 * include the deferred DATA frames.
3150 NGHTTP2_EXTERN size_t
3151 nghttp2_session_get_outbound_queue_size(nghttp2_session *session);
3156 * Returns the number of DATA payload in bytes received without
3157 * WINDOW_UPDATE transmission for the stream |stream_id|. The local
3158 * (receive) window size can be adjusted by
3159 * `nghttp2_submit_window_update()`. This function takes into account
3160 * that and returns effective data length. In particular, if the
3161 * local window size is reduced by submitting negative
3162 * window_size_increment with `nghttp2_submit_window_update()`, this
3163 * function returns the number of bytes less than actually received.
3165 * This function returns -1 if it fails.
3167 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_recv_data_length(
3168 nghttp2_session *session, int32_t stream_id);
3173 * Returns the local (receive) window size for the stream |stream_id|.
3174 * The local window size can be adjusted by
3175 * `nghttp2_submit_window_update()`. This function takes into account
3176 * that and returns effective window size.
3178 * This function does not take into account the amount of received
3179 * data from the remote endpoint. Use
3180 * `nghttp2_session_get_stream_local_window_size()` to know the amount
3181 * of data the remote endpoint can send without receiving stream level
3182 * WINDOW_UPDATE frame. Note that each stream is still subject to the
3183 * connection level flow control.
3185 * This function returns -1 if it fails.
3187 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_local_window_size(
3188 nghttp2_session *session, int32_t stream_id);
3193 * Returns the amount of flow-controlled payload (e.g., DATA) that the
3194 * remote endpoint can send without receiving stream level
3195 * WINDOW_UPDATE frame. It is also subject to the connection level
3196 * flow control. So the actual amount of data to send is
3197 * min(`nghttp2_session_get_stream_local_window_size()`,
3198 * `nghttp2_session_get_local_window_size()`).
3200 * This function returns -1 if it fails.
3202 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_local_window_size(
3203 nghttp2_session *session, int32_t stream_id);
3208 * Returns the number of DATA payload in bytes received without
3209 * WINDOW_UPDATE transmission for a connection. The local (receive)
3210 * window size can be adjusted by `nghttp2_submit_window_update()`.
3211 * This function takes into account that and returns effective data
3212 * length. In particular, if the local window size is reduced by
3213 * submitting negative window_size_increment with
3214 * `nghttp2_submit_window_update()`, this function returns the number
3215 * of bytes less than actually received.
3217 * This function returns -1 if it fails.
3219 NGHTTP2_EXTERN int32_t
3220 nghttp2_session_get_effective_recv_data_length(nghttp2_session *session);
3225 * Returns the local (receive) window size for a connection. The
3226 * local window size can be adjusted by
3227 * `nghttp2_submit_window_update()`. This function takes into account
3228 * that and returns effective window size.
3230 * This function does not take into account the amount of received
3231 * data from the remote endpoint. Use
3232 * `nghttp2_session_get_local_window_size()` to know the amount of
3233 * data the remote endpoint can send without receiving
3234 * connection-level WINDOW_UPDATE frame. Note that each stream is
3235 * still subject to the stream level flow control.
3237 * This function returns -1 if it fails.
3239 NGHTTP2_EXTERN int32_t
3240 nghttp2_session_get_effective_local_window_size(nghttp2_session *session);
3245 * Returns the amount of flow-controlled payload (e.g., DATA) that the
3246 * remote endpoint can send without receiving connection level
3247 * WINDOW_UPDATE frame. Note that each stream is still subject to the
3248 * stream level flow control (see
3249 * `nghttp2_session_get_stream_local_window_size()`).
3251 * This function returns -1 if it fails.
3253 NGHTTP2_EXTERN int32_t
3254 nghttp2_session_get_local_window_size(nghttp2_session *session);
3259 * Returns the remote window size for a given stream |stream_id|.
3261 * This is the amount of flow-controlled payload (e.g., DATA) that the
3262 * local endpoint can send without stream level WINDOW_UPDATE. There
3263 * is also connection level flow control, so the effective size of
3264 * payload that the local endpoint can actually send is
3265 * min(`nghttp2_session_get_stream_remote_window_size()`,
3266 * `nghttp2_session_get_remote_window_size()`).
3268 * This function returns -1 if it fails.
3270 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_remote_window_size(
3271 nghttp2_session *session, int32_t stream_id);
3276 * Returns the remote window size for a connection.
3278 * This function always succeeds.
3280 NGHTTP2_EXTERN int32_t
3281 nghttp2_session_get_remote_window_size(nghttp2_session *session);
3286 * Returns 1 if local peer half closed the given stream |stream_id|.
3287 * Returns 0 if it did not. Returns -1 if no such stream exists.
3290 nghttp2_session_get_stream_local_close(nghttp2_session *session,
3296 * Returns 1 if remote peer half closed the given stream |stream_id|.
3297 * Returns 0 if it did not. Returns -1 if no such stream exists.
3300 nghttp2_session_get_stream_remote_close(nghttp2_session *session,
3306 * Returns the current dynamic table size of HPACK inflater, including
3307 * the overhead 32 bytes per entry described in RFC 7541.
3309 NGHTTP2_EXTERN size_t
3310 nghttp2_session_get_hd_inflate_dynamic_table_size(nghttp2_session *session);
3315 * Returns the current dynamic table size of HPACK deflater including
3316 * the overhead 32 bytes per entry described in RFC 7541.
3318 NGHTTP2_EXTERN size_t
3319 nghttp2_session_get_hd_deflate_dynamic_table_size(nghttp2_session *session);
3324 * Signals the session so that the connection should be terminated.
3326 * The last stream ID is the minimum value between the stream ID of a
3327 * stream for which :type:`nghttp2_on_frame_recv_callback` was called
3328 * most recently and the last stream ID we have sent to the peer
3331 * The |error_code| is the error code of this GOAWAY frame. The
3332 * pre-defined error code is one of :enum:`nghttp2_error_code`.
3334 * After the transmission, both `nghttp2_session_want_read()` and
3335 * `nghttp2_session_want_write()` return 0.
3337 * This function should be called when the connection should be
3338 * terminated after sending GOAWAY. If the remaining streams should
3339 * be processed after GOAWAY, use `nghttp2_submit_goaway()` instead.
3341 * This function returns 0 if it succeeds, or one of the following
3342 * negative error codes:
3344 * :enum:`NGHTTP2_ERR_NOMEM`
3347 NGHTTP2_EXTERN int nghttp2_session_terminate_session(nghttp2_session *session,
3348 uint32_t error_code);
3353 * Signals the session so that the connection should be terminated.
3355 * This function behaves like `nghttp2_session_terminate_session()`,
3356 * but the last stream ID can be specified by the application for fine
3357 * grained control of stream. The HTTP/2 specification does not allow
3358 * last_stream_id to be increased. So the actual value sent as
3359 * last_stream_id is the minimum value between the given
3360 * |last_stream_id| and the last_stream_id we have previously sent to
3363 * The |last_stream_id| is peer's stream ID or 0. So if |session| is
3364 * initialized as client, |last_stream_id| must be even or 0. If
3365 * |session| is initialized as server, |last_stream_id| must be odd or
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 |last_stream_id| is invalid.
3376 NGHTTP2_EXTERN int nghttp2_session_terminate_session2(nghttp2_session *session,
3377 int32_t last_stream_id,
3378 uint32_t error_code);
3383 * Signals to the client that the server started graceful shutdown
3386 * This function is only usable for server. If this function is
3387 * called with client side session, this function returns
3388 * :enum:`NGHTTP2_ERR_INVALID_STATE`.
3390 * To gracefully shutdown HTTP/2 session, server should call this
3391 * function to send GOAWAY with last_stream_id (1u << 31) - 1. And
3392 * after some delay (e.g., 1 RTT), send another GOAWAY with the stream
3393 * ID that the server has some processing using
3394 * `nghttp2_submit_goaway()`. See also
3395 * `nghttp2_session_get_last_proc_stream_id()`.
3397 * Unlike `nghttp2_submit_goaway()`, this function just sends GOAWAY
3398 * and does nothing more. This is a mere indication to the client
3399 * that session shutdown is imminent. The application should call
3400 * `nghttp2_submit_goaway()` with appropriate last_stream_id after
3403 * If one or more GOAWAY frame have been already sent by either
3404 * `nghttp2_submit_goaway()` or `nghttp2_session_terminate_session()`,
3405 * this function has no effect.
3407 * This function returns 0 if it succeeds, or one of the following
3408 * negative error codes:
3410 * :enum:`NGHTTP2_ERR_NOMEM`
3412 * :enum:`NGHTTP2_ERR_INVALID_STATE`
3413 * The |session| is initialized as client.
3415 NGHTTP2_EXTERN int nghttp2_submit_shutdown_notice(nghttp2_session *session);
3420 * Returns the value of SETTINGS |id| notified by a remote endpoint.
3421 * The |id| must be one of values defined in
3422 * :enum:`nghttp2_settings_id`.
3424 NGHTTP2_EXTERN uint32_t nghttp2_session_get_remote_settings(
3425 nghttp2_session *session, nghttp2_settings_id id);
3430 * Returns the value of SETTINGS |id| of local endpoint acknowledged
3431 * by the remote endpoint. The |id| must be one of the values defined
3432 * in :enum:`nghttp2_settings_id`.
3434 NGHTTP2_EXTERN uint32_t nghttp2_session_get_local_settings(
3435 nghttp2_session *session, nghttp2_settings_id id);
3440 * Tells the |session| that next stream ID is |next_stream_id|. The
3441 * |next_stream_id| must be equal or greater than the value returned
3442 * by `nghttp2_session_get_next_stream_id()`.
3444 * This function returns 0 if it succeeds, or one of the following
3445 * negative error codes:
3447 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3448 * The |next_stream_id| is strictly less than the value
3449 * `nghttp2_session_get_next_stream_id()` returns; or
3450 * |next_stream_id| is invalid (e.g., even integer for client, or
3451 * odd integer for server).
3453 NGHTTP2_EXTERN int nghttp2_session_set_next_stream_id(nghttp2_session *session,
3454 int32_t next_stream_id);
3459 * Returns the next outgoing stream ID. Notice that return type is
3460 * uint32_t. If we run out of stream ID for this session, this
3461 * function returns 1 << 31.
3463 NGHTTP2_EXTERN uint32_t
3464 nghttp2_session_get_next_stream_id(nghttp2_session *session);
3469 * Tells the |session| that |size| bytes for a stream denoted by
3470 * |stream_id| were consumed by application and are ready to
3471 * WINDOW_UPDATE. The consumed bytes are counted towards both
3472 * connection and stream level WINDOW_UPDATE (see
3473 * `nghttp2_session_consume_connection()` and
3474 * `nghttp2_session_consume_stream()` to update consumption
3475 * independently). This function is intended to be used without
3476 * automatic window update (see
3477 * `nghttp2_option_set_no_auto_window_update()`).
3479 * This function returns 0 if it succeeds, or one of the following
3480 * negative error codes:
3482 * :enum:`NGHTTP2_ERR_NOMEM`
3484 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3485 * The |stream_id| is 0.
3486 * :enum:`NGHTTP2_ERR_INVALID_STATE`
3487 * Automatic WINDOW_UPDATE is not disabled.
3489 NGHTTP2_EXTERN int nghttp2_session_consume(nghttp2_session *session,
3490 int32_t stream_id, size_t size);
3495 * Like `nghttp2_session_consume()`, but this only tells library that
3496 * |size| bytes were consumed only for connection level. Note that
3497 * HTTP/2 maintains connection and stream level flow control windows
3500 * This function returns 0 if it succeeds, or one of the following
3501 * negative error codes:
3503 * :enum:`NGHTTP2_ERR_NOMEM`
3505 * :enum:`NGHTTP2_ERR_INVALID_STATE`
3506 * Automatic WINDOW_UPDATE is not disabled.
3508 NGHTTP2_EXTERN int nghttp2_session_consume_connection(nghttp2_session *session,
3514 * Like `nghttp2_session_consume()`, but this only tells library that
3515 * |size| bytes were consumed only for stream denoted by |stream_id|.
3516 * Note that HTTP/2 maintains connection and stream level flow control
3517 * windows independently.
3519 * This function returns 0 if it succeeds, or one of the following
3520 * negative error codes:
3522 * :enum:`NGHTTP2_ERR_NOMEM`
3524 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3525 * The |stream_id| is 0.
3526 * :enum:`NGHTTP2_ERR_INVALID_STATE`
3527 * Automatic WINDOW_UPDATE is not disabled.
3529 NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session,
3536 * Changes priority of existing stream denoted by |stream_id|. The
3537 * new priority specification is |pri_spec|.
3539 * The priority is changed silently and instantly, and no PRIORITY
3540 * frame will be sent to notify the peer of this change. This
3541 * function may be useful for server to change the priority of pushed
3544 * If |session| is initialized as server, and ``pri_spec->stream_id``
3545 * points to the idle stream, the idle stream is created if it does
3546 * not exist. The created idle stream will depend on root stream
3547 * (stream 0) with weight 16.
3549 * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not
3550 * found, we use default priority instead of given |pri_spec|. That
3551 * is make stream depend on root stream with weight 16.
3553 * This function returns 0 if it succeeds, or one of the following
3554 * negative error codes:
3556 * :enum:`NGHTTP2_ERR_NOMEM`
3558 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3559 * Attempted to depend on itself; or no stream exist for the given
3560 * |stream_id|; or |stream_id| is 0
3563 nghttp2_session_change_stream_priority(nghttp2_session *session,
3565 const nghttp2_priority_spec *pri_spec);
3570 * Creates idle stream with the given |stream_id|, and priority
3573 * The stream creation is done without sending PRIORITY frame, which
3574 * means that peer does not know about the existence of this idle
3575 * stream in the local endpoint.
3577 * RFC 7540 does not disallow the use of creation of idle stream with
3578 * odd or even stream ID regardless of client or server. So this
3579 * function can create odd or even stream ID regardless of client or
3580 * server. But probably it is a bit safer to use the stream ID the
3581 * local endpoint can initiate (in other words, use odd stream ID for
3582 * client, and even stream ID for server), to avoid potential
3583 * collision from peer's instruction. Also we can use
3584 * `nghttp2_session_set_next_stream_id()` to avoid to open created
3585 * idle streams accidentally if we follow this recommendation.
3587 * If |session| is initialized as server, and ``pri_spec->stream_id``
3588 * points to the idle stream, the idle stream is created if it does
3589 * not exist. The created idle stream will depend on root stream
3590 * (stream 0) with weight 16.
3592 * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not
3593 * found, we use default priority instead of given |pri_spec|. That
3594 * is make stream depend on root stream with weight 16.
3596 * This function returns 0 if it succeeds, or one of the following
3597 * negative error codes:
3599 * :enum:`NGHTTP2_ERR_NOMEM`
3601 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3602 * Attempted to depend on itself; or stream denoted by |stream_id|
3603 * already exists; or |stream_id| cannot be used to create idle
3604 * stream (in other words, local endpoint has already opened
3605 * stream ID greater than or equal to the given stream ID; or
3609 nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id,
3610 const nghttp2_priority_spec *pri_spec);
3615 * Performs post-process of HTTP Upgrade request. This function can
3616 * be called from both client and server, but the behavior is very
3617 * different in each other.
3621 * This function is deprecated in favor of
3622 * `nghttp2_session_upgrade2()`, because this function lacks the
3623 * parameter to tell the library the request method used in the
3624 * original HTTP request. This information is required for client
3625 * to validate actual response body length against content-length
3626 * header field (see `nghttp2_option_set_no_http_messaging()`). If
3627 * HEAD is used in request, the length of response body must be 0
3628 * regardless of value included in content-length header field.
3630 * If called from client side, the |settings_payload| must be the
3631 * value sent in ``HTTP2-Settings`` header field and must be decoded
3632 * by base64url decoder. The |settings_payloadlen| is the length of
3633 * |settings_payload|. The |settings_payload| is unpacked and its
3634 * setting values will be submitted using `nghttp2_submit_settings()`.
3635 * This means that the client application code does not need to submit
3636 * SETTINGS by itself. The stream with stream ID=1 is opened and the
3637 * |stream_user_data| is used for its stream_user_data. The opened
3638 * stream becomes half-closed (local) state.
3640 * If called from server side, the |settings_payload| must be the
3641 * value received in ``HTTP2-Settings`` header field and must be
3642 * decoded by base64url decoder. The |settings_payloadlen| is the
3643 * length of |settings_payload|. It is treated as if the SETTINGS
3644 * frame with that payload is received. Thus, callback functions for
3645 * the reception of SETTINGS frame will be invoked. The stream with
3646 * stream ID=1 is opened. The |stream_user_data| is ignored. The
3647 * opened stream becomes half-closed (remote).
3649 * This function returns 0 if it succeeds, or one of the following
3650 * negative error codes:
3652 * :enum:`NGHTTP2_ERR_NOMEM`
3654 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3655 * The |settings_payload| is badly formed.
3656 * :enum:`NGHTTP2_ERR_PROTO`
3657 * The stream ID 1 is already used or closed; or is not available.
3659 NGHTTP2_EXTERN int nghttp2_session_upgrade(nghttp2_session *session,
3660 const uint8_t *settings_payload,
3661 size_t settings_payloadlen,
3662 void *stream_user_data);
3667 * Performs post-process of HTTP Upgrade request. This function can
3668 * be called from both client and server, but the behavior is very
3669 * different in each other.
3671 * If called from client side, the |settings_payload| must be the
3672 * value sent in ``HTTP2-Settings`` header field and must be decoded
3673 * by base64url decoder. The |settings_payloadlen| is the length of
3674 * |settings_payload|. The |settings_payload| is unpacked and its
3675 * setting values will be submitted using `nghttp2_submit_settings()`.
3676 * This means that the client application code does not need to submit
3677 * SETTINGS by itself. The stream with stream ID=1 is opened and the
3678 * |stream_user_data| is used for its stream_user_data. The opened
3679 * stream becomes half-closed (local) state.
3681 * If called from server side, the |settings_payload| must be the
3682 * value received in ``HTTP2-Settings`` header field and must be
3683 * decoded by base64url decoder. The |settings_payloadlen| is the
3684 * length of |settings_payload|. It is treated as if the SETTINGS
3685 * frame with that payload is received. Thus, callback functions for
3686 * the reception of SETTINGS frame will be invoked. The stream with
3687 * stream ID=1 is opened. The |stream_user_data| is ignored. The
3688 * opened stream becomes half-closed (remote).
3690 * If the request method is HEAD, pass nonzero value to
3691 * |head_request|. Otherwise, pass 0.
3693 * This function returns 0 if it succeeds, or one of the following
3694 * negative error codes:
3696 * :enum:`NGHTTP2_ERR_NOMEM`
3698 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3699 * The |settings_payload| is badly formed.
3700 * :enum:`NGHTTP2_ERR_PROTO`
3701 * The stream ID 1 is already used or closed; or is not available.
3703 NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session,
3704 const uint8_t *settings_payload,
3705 size_t settings_payloadlen,
3707 void *stream_user_data);
3712 * Serializes the SETTINGS values |iv| in the |buf|. The size of the
3713 * |buf| is specified by |buflen|. The number of entries in the |iv|
3714 * array is given by |niv|. The required space in |buf| for the |niv|
3715 * entries is ``6*niv`` bytes and if the given buffer is too small, an
3716 * error is returned. This function is used mainly for creating a
3717 * SETTINGS payload to be sent with the ``HTTP2-Settings`` header
3718 * field in an HTTP Upgrade request. The data written in |buf| is NOT
3719 * base64url encoded and the application is responsible for encoding.
3721 * This function returns the number of bytes written in |buf|, or one
3722 * of the following negative error codes:
3724 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3725 * The |iv| contains duplicate settings ID or invalid value.
3727 * :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`
3728 * The provided |buflen| size is too small to hold the output.
3730 NGHTTP2_EXTERN ssize_t nghttp2_pack_settings_payload(
3731 uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv);
3736 * Returns string describing the |lib_error_code|. The
3737 * |lib_error_code| must be one of the :enum:`nghttp2_error`.
3739 NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code);
3744 * Returns string representation of HTTP/2 error code |error_code|
3745 * (e.g., ``PROTOCOL_ERROR`` is returned if ``error_code ==
3746 * NGHTTP2_PROTOCOL_ERROR``). If string representation is unknown for
3747 * given |error_code|, this function returns string ``unknown``.
3749 NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code);
3754 * Initializes |pri_spec| with the |stream_id| of the stream to depend
3755 * on with |weight| and its exclusive flag. If |exclusive| is
3756 * nonzero, exclusive flag is set.
3758 * The |weight| must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
3759 * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive.
3761 NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec,
3763 int32_t weight, int exclusive);
3768 * Initializes |pri_spec| with the default values. The default values
3769 * are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and
3773 nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec);
3778 * Returns nonzero if the |pri_spec| is filled with default values.
3781 nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec);
3786 * Submits HEADERS frame and optionally one or more DATA frames.
3788 * The |pri_spec| is priority specification of this request. ``NULL``
3789 * means the default priority (see
3790 * `nghttp2_priority_spec_default_init()`). To specify the priority,
3791 * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``,
3792 * this function will copy its data members.
3794 * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
3795 * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is
3796 * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
3797 * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
3798 * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
3800 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
3801 * |nvlen| elements. The application is responsible to include
3802 * required pseudo-header fields (header field whose name starts with
3803 * ":") in |nva| and must place pseudo-headers before regular header
3806 * This function creates copies of all name/value pairs in |nva|. It
3807 * also lower-cases all names in |nva|. The order of elements in
3808 * |nva| is preserved. For header fields with
3809 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and
3810 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name
3811 * and value are not copied respectively. With
3812 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to
3813 * pass header field name in lowercase. The application should
3814 * maintain the references to them until
3815 * :type:`nghttp2_on_frame_send_callback` or
3816 * :type:`nghttp2_on_frame_not_send_callback` is called.
3818 * HTTP/2 specification has requirement about header fields in the
3819 * request HEADERS. See the specification for more details.
3821 * If |data_prd| is not ``NULL``, it provides data which will be sent
3822 * in subsequent DATA frames. In this case, a method that allows
3823 * request message bodies
3824 * (https://tools.ietf.org/html/rfc7231#section-4) must be specified
3825 * with ``:method`` key in |nva| (e.g. ``POST``). This function does
3826 * not take ownership of the |data_prd|. The function copies the
3827 * members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have
3828 * END_STREAM set. The |stream_user_data| is data associated to the
3829 * stream opened by this request and can be an arbitrary pointer,
3830 * which can be retrieved later by
3831 * `nghttp2_session_get_stream_user_data()`.
3833 * This function returns assigned stream ID if it succeeds, or one of
3834 * the following negative error codes:
3836 * :enum:`NGHTTP2_ERR_NOMEM`
3838 * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
3839 * No stream ID is available because maximum stream ID was
3841 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3842 * Trying to depend on itself (new stream ID equals
3843 * ``pri_spec->stream_id``).
3844 * :enum:`NGHTTP2_ERR_PROTO`
3845 * The |session| is server session.
3849 * This function returns assigned stream ID if it succeeds. But
3850 * that stream is not created yet. The application must not submit
3851 * frame to that stream ID before
3852 * :type:`nghttp2_before_frame_send_callback` is called for this
3853 * frame. This means `nghttp2_session_get_stream_user_data()` does
3854 * not work before the callback. But
3855 * `nghttp2_session_set_stream_user_data()` handles this situation
3856 * specially, and it can set data to a stream during this period.
3859 NGHTTP2_EXTERN int32_t nghttp2_submit_request(
3860 nghttp2_session *session, const nghttp2_priority_spec *pri_spec,
3861 const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd,
3862 void *stream_user_data);
3867 * Submits response HEADERS frame and optionally one or more DATA
3868 * frames against the stream |stream_id|.
3870 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
3871 * |nvlen| elements. The application is responsible to include
3872 * required pseudo-header fields (header field whose name starts with
3873 * ":") in |nva| and must place pseudo-headers before regular header
3876 * This function creates copies of all name/value pairs in |nva|. It
3877 * also lower-cases all names in |nva|. The order of elements in
3878 * |nva| is preserved. For header fields with
3879 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and
3880 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name
3881 * and value are not copied respectively. With
3882 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to
3883 * pass header field name in lowercase. The application should
3884 * maintain the references to them until
3885 * :type:`nghttp2_on_frame_send_callback` or
3886 * :type:`nghttp2_on_frame_not_send_callback` is called.
3888 * HTTP/2 specification has requirement about header fields in the
3889 * response HEADERS. See the specification for more details.
3891 * If |data_prd| is not ``NULL``, it provides data which will be sent
3892 * in subsequent DATA frames. This function does not take ownership
3893 * of the |data_prd|. The function copies the members of the
3894 * |data_prd|. If |data_prd| is ``NULL``, HEADERS will have
3895 * END_STREAM flag set.
3897 * This method can be used as normal HTTP response and push response.
3898 * When pushing a resource using this function, the |session| must be
3899 * configured using `nghttp2_session_server_new()` or its variants and
3900 * the target stream denoted by the |stream_id| must be reserved using
3901 * `nghttp2_submit_push_promise()`.
3903 * To send non-final response headers (e.g., HTTP status 101), don't
3904 * use this function because this function half-closes the outbound
3905 * stream. Instead, use `nghttp2_submit_headers()` for this purpose.
3907 * This function returns 0 if it succeeds, or one of the following
3908 * negative error codes:
3910 * :enum:`NGHTTP2_ERR_NOMEM`
3912 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3913 * The |stream_id| is 0.
3914 * :enum:`NGHTTP2_ERR_DATA_EXIST`
3915 * DATA or HEADERS has been already submitted and not fully
3916 * processed yet. Normally, this does not happen, but when
3917 * application wrongly calls `nghttp2_submit_response()` twice,
3919 * :enum:`NGHTTP2_ERR_PROTO`
3920 * The |session| is client session.
3924 * Calling this function twice for the same stream ID may lead to
3925 * program crash. It is generally considered to a programming error
3926 * to commit response twice.
3929 nghttp2_submit_response(nghttp2_session *session, int32_t stream_id,
3930 const nghttp2_nv *nva, size_t nvlen,
3931 const nghttp2_data_provider *data_prd);
3936 * Submits trailer fields HEADERS against the stream |stream_id|.
3938 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
3939 * |nvlen| elements. The application must not include pseudo-header
3940 * fields (headers whose names starts with ":") in |nva|.
3942 * This function creates copies of all name/value pairs in |nva|. It
3943 * also lower-cases all names in |nva|. The order of elements in
3944 * |nva| is preserved. For header fields with
3945 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and
3946 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name
3947 * and value are not copied respectively. With
3948 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to
3949 * pass header field name in lowercase. The application should
3950 * maintain the references to them until
3951 * :type:`nghttp2_on_frame_send_callback` or
3952 * :type:`nghttp2_on_frame_not_send_callback` is called.
3954 * For server, trailer fields must follow response HEADERS or response
3955 * DATA without END_STREAM flat set. The library does not enforce
3956 * this requirement, and applications should do this for themselves.
3957 * If `nghttp2_submit_trailer()` is called before any response HEADERS
3958 * submission (usually by `nghttp2_submit_response()`), the content of
3959 * |nva| will be sent as response headers, which will result in error.
3961 * This function has the same effect with `nghttp2_submit_headers()`,
3962 * with flags = :enum:`NGHTTP2_FLAG_END_STREAM` and both pri_spec and
3963 * stream_user_data to NULL.
3965 * To submit trailer fields after `nghttp2_submit_response()` is
3966 * called, the application has to specify
3967 * :type:`nghttp2_data_provider` to `nghttp2_submit_response()`.
3968 * Inside of :type:`nghttp2_data_source_read_callback`, when setting
3969 * :enum:`NGHTTP2_DATA_FLAG_EOF`, also set
3970 * :enum:`NGHTTP2_DATA_FLAG_NO_END_STREAM`. After that, the
3971 * application can send trailer fields using
3972 * `nghttp2_submit_trailer()`. `nghttp2_submit_trailer()` can be used
3973 * inside :type:`nghttp2_data_source_read_callback`.
3975 * This function returns 0 if it succeeds and |stream_id| is -1.
3976 * Otherwise, this function returns 0 if it succeeds, or one of the
3977 * following negative error codes:
3979 * :enum:`NGHTTP2_ERR_NOMEM`
3981 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
3982 * The |stream_id| is 0.
3984 NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session,
3986 const nghttp2_nv *nva, size_t nvlen);
3991 * Submits HEADERS frame. The |flags| is bitwise OR of the
3994 * * :enum:`NGHTTP2_FLAG_END_STREAM`
3996 * If |flags| includes :enum:`NGHTTP2_FLAG_END_STREAM`, this frame has
3997 * END_STREAM flag set.
3999 * The library handles the CONTINUATION frame internally and it
4000 * correctly sets END_HEADERS to the last sequence of the PUSH_PROMISE
4001 * or CONTINUATION frame.
4003 * If the |stream_id| is -1, this frame is assumed as request (i.e.,
4004 * request HEADERS frame which opens new stream). In this case, the
4005 * assigned stream ID will be returned. Otherwise, specify stream ID
4008 * The |pri_spec| is priority specification of this request. ``NULL``
4009 * means the default priority (see
4010 * `nghttp2_priority_spec_default_init()`). To specify the priority,
4011 * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``,
4012 * this function will copy its data members.
4014 * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
4015 * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is
4016 * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
4017 * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
4018 * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
4020 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4021 * |nvlen| elements. The application is responsible to include
4022 * required pseudo-header fields (header field whose name starts with
4023 * ":") in |nva| and must place pseudo-headers before regular header
4026 * This function creates copies of all name/value pairs in |nva|. It
4027 * also lower-cases all names in |nva|. The order of elements in
4028 * |nva| is preserved. For header fields with
4029 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4030 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name
4031 * and value are not copied respectively. With
4032 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to
4033 * pass header field name in lowercase. The application should
4034 * maintain the references to them until
4035 * :type:`nghttp2_on_frame_send_callback` or
4036 * :type:`nghttp2_on_frame_not_send_callback` is called.
4038 * The |stream_user_data| is a pointer to an arbitrary data which is
4039 * associated to the stream this frame will open. Therefore it is
4040 * only used if this frame opens streams, in other words, it changes
4041 * stream state from idle or reserved to open.
4043 * This function is low-level in a sense that the application code can
4044 * specify flags directly. For usual HTTP request,
4045 * `nghttp2_submit_request()` is useful. Likewise, for HTTP response,
4046 * prefer `nghttp2_submit_response()`.
4048 * This function returns newly assigned stream ID if it succeeds and
4049 * |stream_id| is -1. Otherwise, this function returns 0 if it
4050 * succeeds, or one of the following negative error codes:
4052 * :enum:`NGHTTP2_ERR_NOMEM`
4054 * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
4055 * No stream ID is available because maximum stream ID was
4057 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4058 * The |stream_id| is 0; or trying to depend on itself (stream ID
4059 * equals ``pri_spec->stream_id``).
4060 * :enum:`NGHTTP2_ERR_DATA_EXIST`
4061 * DATA or HEADERS has been already submitted and not fully
4062 * processed yet. This happens if stream denoted by |stream_id|
4063 * is in reserved state.
4064 * :enum:`NGHTTP2_ERR_PROTO`
4065 * The |stream_id| is -1, and |session| is server session.
4069 * This function returns assigned stream ID if it succeeds and
4070 * |stream_id| is -1. But that stream is not opened yet. The
4071 * application must not submit frame to that stream ID before
4072 * :type:`nghttp2_before_frame_send_callback` is called for this
4076 NGHTTP2_EXTERN int32_t nghttp2_submit_headers(
4077 nghttp2_session *session, uint8_t flags, int32_t stream_id,
4078 const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen,
4079 void *stream_user_data);
4084 * Submits one or more DATA frames to the stream |stream_id|. The
4085 * data to be sent are provided by |data_prd|. If |flags| contains
4086 * :enum:`NGHTTP2_FLAG_END_STREAM`, the last DATA frame has END_STREAM
4089 * This function does not take ownership of the |data_prd|. The
4090 * function copies the members of the |data_prd|.
4092 * This function returns 0 if it succeeds, or one of the following
4093 * negative error codes:
4095 * :enum:`NGHTTP2_ERR_NOMEM`
4097 * :enum:`NGHTTP2_ERR_DATA_EXIST`
4098 * DATA or HEADERS has been already submitted and not fully
4100 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4101 * The |stream_id| is 0.
4102 * :enum:`NGHTTP2_ERR_STREAM_CLOSED`
4103 * The stream was already closed; or the |stream_id| is invalid.
4107 * Currently, only one DATA or HEADERS is allowed for a stream at a
4108 * time. Submitting these frames more than once before first DATA
4109 * or HEADERS is finished results in :enum:`NGHTTP2_ERR_DATA_EXIST`
4110 * error code. The earliest callback which tells that previous
4111 * frame is done is :type:`nghttp2_on_frame_send_callback`. In side
4112 * that callback, new data can be submitted using
4113 * `nghttp2_submit_data()`. Of course, all data except for last one
4114 * must not have :enum:`NGHTTP2_FLAG_END_STREAM` flag set in
4115 * |flags|. This sounds a bit complicated, and we recommend to use
4116 * `nghttp2_submit_request()` and `nghttp2_submit_response()` to
4117 * avoid this cascading issue. The experience shows that for HTTP
4118 * use, these two functions are enough to implement both client and
4121 NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
4123 const nghttp2_data_provider *data_prd);
4128 * Submits PRIORITY frame to change the priority of stream |stream_id|
4129 * to the priority specification |pri_spec|.
4131 * The |flags| is currently ignored and should be
4132 * :enum:`NGHTTP2_FLAG_NONE`.
4134 * The |pri_spec| is priority specification of this request. ``NULL``
4135 * is not allowed for this function. To specify the priority, use
4136 * `nghttp2_priority_spec_init()`. This function will copy its data
4139 * The ``pri_spec->weight`` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
4140 * :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` is
4141 * strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
4142 * :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
4143 * :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
4145 * This function returns 0 if it succeeds, or one of the following
4146 * negative error codes:
4148 * :enum:`NGHTTP2_ERR_NOMEM`
4150 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4151 * The |stream_id| is 0; or the |pri_spec| is NULL; or trying to
4155 nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,
4157 const nghttp2_priority_spec *pri_spec);
4162 * Submits RST_STREAM frame to cancel/reject the stream |stream_id|
4163 * with the error code |error_code|.
4165 * The pre-defined error code is one of :enum:`nghttp2_error_code`.
4167 * The |flags| is currently ignored and should be
4168 * :enum:`NGHTTP2_FLAG_NONE`.
4170 * This function returns 0 if it succeeds, or one of the following
4171 * negative error codes:
4173 * :enum:`NGHTTP2_ERR_NOMEM`
4175 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4176 * The |stream_id| is 0.
4178 NGHTTP2_EXTERN int nghttp2_submit_rst_stream(nghttp2_session *session,
4179 uint8_t flags, int32_t stream_id,
4180 uint32_t error_code);
4185 * Stores local settings and submits SETTINGS frame. The |iv| is the
4186 * pointer to the array of :type:`nghttp2_settings_entry`. The |niv|
4187 * indicates the number of :type:`nghttp2_settings_entry`.
4189 * The |flags| is currently ignored and should be
4190 * :enum:`NGHTTP2_FLAG_NONE`.
4192 * This function does not take ownership of the |iv|. This function
4193 * copies all the elements in the |iv|.
4195 * While updating individual stream's local window size, if the window
4196 * size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE,
4197 * RST_STREAM is issued against such a stream.
4199 * SETTINGS with :enum:`NGHTTP2_FLAG_ACK` is automatically submitted
4200 * by the library and application could not send it at its will.
4202 * This function returns 0 if it succeeds, or one of the following
4203 * negative error codes:
4205 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4206 * The |iv| contains invalid value (e.g., initial window size
4207 * strictly greater than (1 << 31) - 1.
4208 * :enum:`NGHTTP2_ERR_NOMEM`
4211 NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session,
4213 const nghttp2_settings_entry *iv,
4219 * Submits PUSH_PROMISE frame.
4221 * The |flags| is currently ignored. The library handles the
4222 * CONTINUATION frame internally and it correctly sets END_HEADERS to
4223 * the last sequence of the PUSH_PROMISE or CONTINUATION frame.
4225 * The |stream_id| must be client initiated stream ID.
4227 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4228 * |nvlen| elements. The application is responsible to include
4229 * required pseudo-header fields (header field whose name starts with
4230 * ":") in |nva| and must place pseudo-headers before regular header
4233 * This function creates copies of all name/value pairs in |nva|. It
4234 * also lower-cases all names in |nva|. The order of elements in
4235 * |nva| is preserved. For header fields with
4236 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4237 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, header field name
4238 * and value are not copied respectively. With
4239 * :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`, application is responsible to
4240 * pass header field name in lowercase. The application should
4241 * maintain the references to them until
4242 * :type:`nghttp2_on_frame_send_callback` or
4243 * :type:`nghttp2_on_frame_not_send_callback` is called.
4245 * The |promised_stream_user_data| is a pointer to an arbitrary data
4246 * which is associated to the promised stream this frame will open and
4247 * make it in reserved state. It is available using
4248 * `nghttp2_session_get_stream_user_data()`. The application can
4249 * access it in :type:`nghttp2_before_frame_send_callback` and
4250 * :type:`nghttp2_on_frame_send_callback` of this frame.
4252 * The client side is not allowed to use this function.
4254 * To submit response headers and data, use
4255 * `nghttp2_submit_response()`.
4257 * This function returns assigned promised stream ID if it succeeds,
4258 * or one of the following negative error codes:
4260 * :enum:`NGHTTP2_ERR_NOMEM`
4262 * :enum:`NGHTTP2_ERR_PROTO`
4263 * This function was invoked when |session| is initialized as
4265 * :enum:`NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
4266 * No stream ID is available because maximum stream ID was
4268 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4269 * The |stream_id| is 0; The |stream_id| does not designate stream
4270 * that peer initiated.
4271 * :enum:`NGHTTP2_ERR_STREAM_CLOSED`
4272 * The stream was already closed; or the |stream_id| is invalid.
4276 * This function returns assigned promised stream ID if it succeeds.
4277 * As of 1.16.0, stream object for pushed resource is created when
4278 * this function succeeds. In that case, the application can submit
4279 * push response for the promised frame.
4281 * In 1.15.0 or prior versions, pushed stream is not opened yet when
4282 * this function succeeds. The application must not submit frame to
4283 * that stream ID before :type:`nghttp2_before_frame_send_callback`
4284 * is called for this frame.
4287 NGHTTP2_EXTERN int32_t nghttp2_submit_push_promise(
4288 nghttp2_session *session, uint8_t flags, int32_t stream_id,
4289 const nghttp2_nv *nva, size_t nvlen, void *promised_stream_user_data);
4294 * Submits PING frame. You don't have to send PING back when you
4295 * received PING frame. The library automatically submits PING frame
4298 * The |flags| is bitwise OR of 0 or more of the following value.
4300 * * :enum:`NGHTTP2_FLAG_ACK`
4302 * Unless `nghttp2_option_set_no_auto_ping_ack()` is used, the |flags|
4303 * should be :enum:`NGHTTP2_FLAG_NONE`.
4305 * If the |opaque_data| is non ``NULL``, then it should point to the 8
4306 * bytes array of memory to specify opaque data to send with PING
4307 * frame. If the |opaque_data| is ``NULL``, zero-cleared 8 bytes will
4308 * be sent as opaque data.
4310 * This function returns 0 if it succeeds, or one of the following
4311 * negative error codes:
4313 * :enum:`NGHTTP2_ERR_NOMEM`
4316 NGHTTP2_EXTERN int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags,
4317 const uint8_t *opaque_data);
4322 * Submits GOAWAY frame with the last stream ID |last_stream_id| and
4323 * the error code |error_code|.
4325 * The pre-defined error code is one of :enum:`nghttp2_error_code`.
4327 * The |flags| is currently ignored and should be
4328 * :enum:`NGHTTP2_FLAG_NONE`.
4330 * The |last_stream_id| is peer's stream ID or 0. So if |session| is
4331 * initialized as client, |last_stream_id| must be even or 0. If
4332 * |session| is initialized as server, |last_stream_id| must be odd or
4335 * The HTTP/2 specification says last_stream_id must not be increased
4336 * from the value previously sent. So the actual value sent as
4337 * last_stream_id is the minimum value between the given
4338 * |last_stream_id| and the last_stream_id previously sent to the
4341 * If the |opaque_data| is not ``NULL`` and |opaque_data_len| is not
4342 * zero, those data will be sent as additional debug data. The
4343 * library makes a copy of the memory region pointed by |opaque_data|
4344 * with the length |opaque_data_len|, so the caller does not need to
4345 * keep this memory after the return of this function. If the
4346 * |opaque_data_len| is 0, the |opaque_data| could be ``NULL``.
4348 * After successful transmission of GOAWAY, following things happen.
4349 * All incoming streams having strictly more than |last_stream_id| are
4350 * closed. All incoming HEADERS which starts new stream are simply
4351 * ignored. After all active streams are handled, both
4352 * `nghttp2_session_want_read()` and `nghttp2_session_want_write()`
4353 * return 0 and the application can close session.
4355 * This function returns 0 if it succeeds, or one of the following
4356 * negative error codes:
4358 * :enum:`NGHTTP2_ERR_NOMEM`
4360 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4361 * The |opaque_data_len| is too large; the |last_stream_id| is
4364 NGHTTP2_EXTERN int nghttp2_submit_goaway(nghttp2_session *session,
4365 uint8_t flags, int32_t last_stream_id,
4366 uint32_t error_code,
4367 const uint8_t *opaque_data,
4368 size_t opaque_data_len);
4373 * Returns the last stream ID of a stream for which
4374 * :type:`nghttp2_on_frame_recv_callback` was invoked most recently.
4375 * The returned value can be used as last_stream_id parameter for
4376 * `nghttp2_submit_goaway()` and
4377 * `nghttp2_session_terminate_session2()`.
4379 * This function always succeeds.
4381 NGHTTP2_EXTERN int32_t
4382 nghttp2_session_get_last_proc_stream_id(nghttp2_session *session);
4387 * Returns nonzero if new request can be sent from local endpoint.
4389 * This function return 0 if request is not allowed for this session.
4390 * There are several reasons why request is not allowed. Some of the
4391 * reasons are: session is server; stream ID has been spent; GOAWAY
4392 * has been sent or received.
4394 * The application can call `nghttp2_submit_request()` without
4395 * consulting this function. In that case, `nghttp2_submit_request()`
4396 * may return error. Or, request is failed to sent, and
4397 * :type:`nghttp2_on_stream_close_callback` is called.
4400 nghttp2_session_check_request_allowed(nghttp2_session *session);
4405 * Returns nonzero if |session| is initialized as server side session.
4408 nghttp2_session_check_server_session(nghttp2_session *session);
4413 * Submits WINDOW_UPDATE frame.
4415 * The |flags| is currently ignored and should be
4416 * :enum:`NGHTTP2_FLAG_NONE`.
4418 * The |stream_id| is the stream ID to send this WINDOW_UPDATE. To
4419 * send connection level WINDOW_UPDATE, specify 0 to |stream_id|.
4421 * If the |window_size_increment| is positive, the WINDOW_UPDATE with
4422 * that value as window_size_increment is queued. If the
4423 * |window_size_increment| is larger than the received bytes from the
4424 * remote endpoint, the local window size is increased by that
4425 * difference. If the sole purpose is to increase the local window
4426 * size, consider to use `nghttp2_session_set_local_window_size()`.
4428 * If the |window_size_increment| is negative, the local window size
4429 * is decreased by -|window_size_increment|. If automatic
4430 * WINDOW_UPDATE is enabled
4431 * (`nghttp2_option_set_no_auto_window_update()`), and the library
4432 * decided that the WINDOW_UPDATE should be submitted, then
4433 * WINDOW_UPDATE is queued with the current received bytes count. If
4434 * the sole purpose is to decrease the local window size, consider to
4435 * use `nghttp2_session_set_local_window_size()`.
4437 * If the |window_size_increment| is 0, the function does nothing and
4440 * This function returns 0 if it succeeds, or one of the following
4441 * negative error codes:
4443 * :enum:`NGHTTP2_ERR_FLOW_CONTROL`
4444 * The local window size overflow or gets negative.
4445 * :enum:`NGHTTP2_ERR_NOMEM`
4448 NGHTTP2_EXTERN int nghttp2_submit_window_update(nghttp2_session *session,
4451 int32_t window_size_increment);
4456 * Set local window size (local endpoints's window size) to the given
4457 * |window_size| for the given stream denoted by |stream_id|. To
4458 * change connection level window size, specify 0 to |stream_id|. To
4459 * increase window size, this function may submit WINDOW_UPDATE frame
4460 * to transmission queue.
4462 * The |flags| is currently ignored and should be
4463 * :enum:`NGHTTP2_FLAG_NONE`.
4465 * This sounds similar to `nghttp2_submit_window_update()`, but there
4466 * are 2 differences. The first difference is that this function
4467 * takes the absolute value of window size to set, rather than the
4468 * delta. To change the window size, this may be easier to use since
4469 * the application just declares the intended window size, rather than
4470 * calculating delta. The second difference is that
4471 * `nghttp2_submit_window_update()` affects the received bytes count
4472 * which has not acked yet. By the specification of
4473 * `nghttp2_submit_window_update()`, to strictly increase the local
4474 * window size, we have to submit delta including all received bytes
4475 * count, which might not be desirable in some cases. On the other
4476 * hand, this function does not affect the received bytes count. It
4477 * just sets the local window size to the given value.
4479 * This function returns 0 if it succeeds, or one of the following
4480 * negative error codes:
4482 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4483 * The |stream_id| is negative.
4484 * :enum:`NGHTTP2_ERR_NOMEM`
4488 nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags,
4489 int32_t stream_id, int32_t window_size);
4494 * Submits extension frame.
4496 * Application can pass arbitrary frame flags and stream ID in |flags|
4497 * and |stream_id| respectively. The |payload| is opaque pointer, and
4498 * it can be accessible though ``frame->ext.payload`` in
4499 * :type:`nghttp2_pack_extension_callback`. The library will not own
4500 * passed |payload| pointer.
4502 * The application must set :type:`nghttp2_pack_extension_callback`
4503 * using `nghttp2_session_callbacks_set_pack_extension_callback()`.
4505 * The application should retain the memory pointed by |payload| until
4506 * the transmission of extension frame is done (which is indicated by
4507 * :type:`nghttp2_on_frame_send_callback`), or transmission fails
4508 * (which is indicated by :type:`nghttp2_on_frame_not_send_callback`).
4509 * If application does not touch this memory region after packing it
4510 * into a wire format, application can free it inside
4511 * :type:`nghttp2_pack_extension_callback`.
4513 * The standard HTTP/2 frame cannot be sent with this function, so
4514 * |type| must be strictly grater than 0x9. Otherwise, this function
4515 * will fail with error code :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`.
4517 * This function returns 0 if it succeeds, or one of the following
4518 * negative error codes:
4520 * :enum:`NGHTTP2_ERR_INVALID_STATE`
4521 * If :type:`nghttp2_pack_extension_callback` is not set.
4522 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4523 * If |type| specifies standard HTTP/2 frame type. The frame
4524 * types in the rage [0x0, 0x9], both inclusive, are standard
4525 * HTTP/2 frame type, and cannot be sent using this function.
4526 * :enum:`NGHTTP2_ERR_NOMEM`
4529 NGHTTP2_EXTERN int nghttp2_submit_extension(nghttp2_session *session,
4530 uint8_t type, uint8_t flags,
4531 int32_t stream_id, void *payload);
4536 * The payload of ALTSVC frame. ALTSVC frame is a non-critical
4537 * extension to HTTP/2. If this frame is received, and
4538 * `nghttp2_option_set_user_recv_extension_type()` is not set, and
4539 * `nghttp2_option_set_builtin_recv_extension_type()` is set for
4540 * :enum:`NGHTTP2_ALTSVC`, ``nghttp2_extension.payload`` will point to
4543 * It has the following members:
4547 * The pointer to origin which this alternative service is
4548 * associated with. This is not necessarily NULL-terminated.
4552 * The length of the |origin|.
4556 * The pointer to Alt-Svc field value contained in ALTSVC frame.
4557 * This is not necessarily NULL-terminated.
4559 uint8_t *field_value;
4561 * The length of the |field_value|.
4563 size_t field_value_len;
4564 } nghttp2_ext_altsvc;
4569 * Submits ALTSVC frame.
4571 * ALTSVC frame is a non-critical extension to HTTP/2, and defined in
4572 * `RFC 7383 <https://tools.ietf.org/html/rfc7838#section-4>`_.
4574 * The |flags| is currently ignored and should be
4575 * :enum:`NGHTTP2_FLAG_NONE`.
4577 * The |origin| points to the origin this alternative service is
4578 * associated with. The |origin_len| is the length of the origin. If
4579 * |stream_id| is 0, the origin must be specified. If |stream_id| is
4580 * not zero, the origin must be empty (in other words, |origin_len|
4583 * The ALTSVC frame is only usable from server side. If this function
4584 * is invoked with client side session, this function returns
4585 * :enum:`NGHTTP2_ERR_INVALID_STATE`.
4587 * This function returns 0 if it succeeds, or one of the following
4588 * negative error codes:
4590 * :enum:`NGHTTP2_ERR_NOMEM`
4592 * :enum:`NGHTTP2_ERR_INVALID_STATE`
4593 * The function is called from client side session
4594 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4595 * The sum of |origin_len| and |field_value_len| is larger than
4596 * 16382; or |origin_len| is 0 while |stream_id| is 0; or
4597 * |origin_len| is not 0 while |stream_id| is not 0.
4599 NGHTTP2_EXTERN int nghttp2_submit_altsvc(nghttp2_session *session,
4600 uint8_t flags, int32_t stream_id,
4601 const uint8_t *origin,
4603 const uint8_t *field_value,
4604 size_t field_value_len);
4609 * The single entry of an origin.
4613 * The pointer to origin. No validation is made against this field
4614 * by the library. This is not necessarily NULL-terminated.
4618 * The length of the |origin|.
4621 } nghttp2_origin_entry;
4626 * The payload of ORIGIN frame. ORIGIN frame is a non-critical
4627 * extension to HTTP/2 and defined by `RFC 8336
4628 * <https://tools.ietf.org/html/rfc8336>`_.
4630 * If this frame is received, and
4631 * `nghttp2_option_set_user_recv_extension_type()` is not set, and
4632 * `nghttp2_option_set_builtin_recv_extension_type()` is set for
4633 * :enum:`NGHTTP2_ORIGIN`, ``nghttp2_extension.payload`` will point to
4636 * It has the following members:
4640 * The number of origins contained in |ov|.
4644 * The pointer to the array of origins contained in ORIGIN frame.
4646 nghttp2_origin_entry *ov;
4647 } nghttp2_ext_origin;
4652 * Submits ORIGIN frame.
4654 * ORIGIN frame is a non-critical extension to HTTP/2 and defined by
4655 * `RFC 8336 <https://tools.ietf.org/html/rfc8336>`_.
4657 * The |flags| is currently ignored and should be
4658 * :enum:`NGHTTP2_FLAG_NONE`.
4660 * The |ov| points to the array of origins. The |nov| specifies the
4661 * number of origins included in |ov|. This function creates copies
4662 * of all elements in |ov|.
4664 * The ORIGIN frame is only usable by a server. If this function is
4665 * invoked with client side session, this function returns
4666 * :enum:`NGHTTP2_ERR_INVALID_STATE`.
4668 * :enum:`NGHTTP2_ERR_NOMEM`
4670 * :enum:`NGHTTP2_ERR_INVALID_STATE`
4671 * The function is called from client side session.
4672 * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
4673 * There are too many origins, or an origin is too large to fit
4674 * into a default frame payload.
4676 NGHTTP2_EXTERN int nghttp2_submit_origin(nghttp2_session *session,
4678 const nghttp2_origin_entry *ov,
4684 * Compares ``lhs->name`` of length ``lhs->namelen`` bytes and
4685 * ``rhs->name`` of length ``rhs->namelen`` bytes. Returns negative
4686 * integer if ``lhs->name`` is found to be less than ``rhs->name``; or
4687 * returns positive integer if ``lhs->name`` is found to be greater
4688 * than ``rhs->name``; or returns 0 otherwise.
4690 NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs,
4691 const nghttp2_nv *rhs);
4696 * A helper function for dealing with NPN in client side or ALPN in
4697 * server side. The |in| contains peer's protocol list in preferable
4698 * order. The format of |in| is length-prefixed and not
4699 * null-terminated. For example, ``h2`` and
4700 * ``http/1.1`` stored in |in| like this::
4705 * in[4..11] = "http/1.1"
4708 * The selection algorithm is as follows:
4710 * 1. If peer's list contains HTTP/2 protocol the library supports,
4711 * it is selected and returns 1. The following step is not taken.
4713 * 2. If peer's list contains ``http/1.1``, this function selects
4714 * ``http/1.1`` and returns 0. The following step is not taken.
4716 * 3. This function selects nothing and returns -1 (So called
4717 * non-overlap case). In this case, |out| and |outlen| are left
4720 * Selecting ``h2`` means that ``h2`` is written into |*out| and its
4721 * length (which is 2) is assigned to |*outlen|.
4723 * For ALPN, refer to https://tools.ietf.org/html/rfc7301
4725 * See http://technotes.googlecode.com/git/nextprotoneg.html for more
4726 * details about NPN.
4728 * For NPN, to use this method you should do something like::
4730 * static int select_next_proto_cb(SSL* ssl,
4731 * unsigned char **out,
4732 * unsigned char *outlen,
4733 * const unsigned char *in,
4734 * unsigned int inlen,
4738 * rv = nghttp2_select_next_protocol(out, outlen, in, inlen);
4740 * return SSL_TLSEXT_ERR_NOACK;
4743 * ((MyType*)arg)->http2_selected = 1;
4745 * return SSL_TLSEXT_ERR_OK;
4748 * SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, my_obj);
4751 NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out,
4752 unsigned char *outlen,
4753 const unsigned char *in,
4754 unsigned int inlen);
4759 * Returns a pointer to a nghttp2_info struct with version information
4760 * about the run-time library in use. The |least_version| argument
4761 * can be set to a 24 bit numerical value for the least accepted
4762 * version number and if the condition is not met, this function will
4763 * return a ``NULL``. Pass in 0 to skip the version checking.
4765 NGHTTP2_EXTERN nghttp2_info *nghttp2_version(int least_version);
4770 * Returns nonzero if the :type:`nghttp2_error` library error code
4771 * |lib_error| is fatal.
4773 NGHTTP2_EXTERN int nghttp2_is_fatal(int lib_error_code);
4778 * Returns nonzero if HTTP header field name |name| of length |len| is
4779 * valid according to http://tools.ietf.org/html/rfc7230#section-3.2
4781 * Because this is a header field name in HTTP2, the upper cased alphabet
4782 * is treated as error.
4784 NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len);
4789 * Returns nonzero if HTTP header field value |value| of length |len|
4790 * is valid according to
4791 * http://tools.ietf.org/html/rfc7230#section-3.2
4793 NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len);
4798 * Returns nonzero if the |value| which is supposed to the value of
4799 * :authority or host header field is valid according to
4800 * https://tools.ietf.org/html/rfc3986#section-3.2
4802 * |value| is valid if it merely consists of the allowed characters.
4803 * In particular, it does not check whether |value| follows the syntax
4806 NGHTTP2_EXTERN int nghttp2_check_authority(const uint8_t *value, size_t len);
4810 struct nghttp2_hd_deflater;
4815 * HPACK deflater object.
4817 typedef struct nghttp2_hd_deflater nghttp2_hd_deflater;
4822 * Initializes |*deflater_ptr| for deflating name/values pairs.
4824 * The |max_deflate_dynamic_table_size| is the upper bound of header
4825 * table size the deflater will use.
4827 * If this function fails, |*deflater_ptr| is left untouched.
4829 * This function returns 0 if it succeeds, or one of the following
4830 * negative error codes:
4832 * :enum:`NGHTTP2_ERR_NOMEM`
4836 nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,
4837 size_t max_deflate_dynamic_table_size);
4842 * Like `nghttp2_hd_deflate_new()`, but with additional custom memory
4843 * allocator specified in the |mem|.
4845 * The |mem| can be ``NULL`` and the call is equivalent to
4846 * `nghttp2_hd_deflate_new()`.
4848 * This function does not take ownership |mem|. The application is
4849 * responsible for freeing |mem|.
4851 * The library code does not refer to |mem| pointer after this
4852 * function returns, so the application can safely free it.
4855 nghttp2_hd_deflate_new2(nghttp2_hd_deflater **deflater_ptr,
4856 size_t max_deflate_dynamic_table_size,
4862 * Deallocates any resources allocated for |deflater|.
4864 NGHTTP2_EXTERN void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater);
4869 * Changes header table size of the |deflater| to
4870 * |settings_max_dynamic_table_size| bytes. This may trigger eviction
4871 * in the dynamic table.
4873 * The |settings_max_dynamic_table_size| should be the value received
4874 * in SETTINGS_HEADER_TABLE_SIZE.
4876 * The deflater never uses more memory than
4877 * ``max_deflate_dynamic_table_size`` bytes specified in
4878 * `nghttp2_hd_deflate_new()`. Therefore, if
4879 * |settings_max_dynamic_table_size| >
4880 * ``max_deflate_dynamic_table_size``, resulting maximum table size
4881 * becomes ``max_deflate_dynamic_table_size``.
4883 * This function returns 0 if it succeeds, or one of the following
4884 * negative error codes:
4886 * :enum:`NGHTTP2_ERR_NOMEM`
4890 nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater,
4891 size_t settings_max_dynamic_table_size);
4896 * Deflates the |nva|, which has the |nvlen| name/value pairs, into
4897 * the |buf| of length |buflen|.
4899 * If |buf| is not large enough to store the deflated header block,
4900 * this function fails with :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`. The
4901 * caller should use `nghttp2_hd_deflate_bound()` to know the upper
4902 * bound of buffer size required to deflate given header name/value
4905 * Once this function fails, subsequent call of this function always
4906 * returns :enum:`NGHTTP2_ERR_HEADER_COMP`.
4908 * After this function returns, it is safe to delete the |nva|.
4910 * This function returns the number of bytes written to |buf| if it
4911 * succeeds, or one of the following negative error codes:
4913 * :enum:`NGHTTP2_ERR_NOMEM`
4915 * :enum:`NGHTTP2_ERR_HEADER_COMP`
4916 * Deflation process has failed.
4917 * :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`
4918 * The provided |buflen| size is too small to hold the output.
4920 NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,
4921 uint8_t *buf, size_t buflen,
4922 const nghttp2_nv *nva,
4928 * Deflates the |nva|, which has the |nvlen| name/value pairs, into
4929 * the |veclen| size of buf vector |vec|. The each size of buffer
4930 * must be set in len field of :type:`nghttp2_vec`. If and only if
4931 * one chunk is filled up completely, next chunk will be used. If
4932 * |vec| is not large enough to store the deflated header block, this
4933 * function fails with :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller
4934 * should use `nghttp2_hd_deflate_bound()` to know the upper bound of
4935 * buffer size required to deflate given header name/value pairs.
4937 * Once this function fails, subsequent call of this function always
4938 * returns :enum:`NGHTTP2_ERR_HEADER_COMP`.
4940 * After this function returns, it is safe to delete the |nva|.
4942 * This function returns the number of bytes written to |vec| if it
4943 * succeeds, or one of the following negative error codes:
4945 * :enum:`NGHTTP2_ERR_NOMEM`
4947 * :enum:`NGHTTP2_ERR_HEADER_COMP`
4948 * Deflation process has failed.
4949 * :enum:`NGHTTP2_ERR_INSUFF_BUFSIZE`
4950 * The provided |buflen| size is too small to hold the output.
4952 NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater,
4953 const nghttp2_vec *vec,
4955 const nghttp2_nv *nva,
4961 * Returns an upper bound on the compressed size after deflation of
4962 * |nva| of length |nvlen|.
4964 NGHTTP2_EXTERN size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
4965 const nghttp2_nv *nva,
4971 * Returns the number of entries that header table of |deflater|
4972 * contains. This is the sum of the number of static table and
4973 * dynamic table, so the return value is at least 61.
4976 size_t nghttp2_hd_deflate_get_num_table_entries(nghttp2_hd_deflater *deflater);
4981 * Returns the table entry denoted by |idx| from header table of
4982 * |deflater|. The |idx| is 1-based, and idx=1 returns first entry of
4983 * static table. idx=62 returns first entry of dynamic table if it
4984 * exists. Specifying idx=0 is error, and this function returns NULL.
4985 * If |idx| is strictly greater than the number of entries the tables
4986 * contain, this function returns NULL.
4990 nghttp2_hd_deflate_get_table_entry(nghttp2_hd_deflater *deflater, size_t idx);
4995 * Returns the used dynamic table size, including the overhead 32
4996 * bytes per entry described in RFC 7541.
4999 size_t nghttp2_hd_deflate_get_dynamic_table_size(nghttp2_hd_deflater *deflater);
5004 * Returns the maximum dynamic table size.
5008 nghttp2_hd_deflate_get_max_dynamic_table_size(nghttp2_hd_deflater *deflater);
5010 struct nghttp2_hd_inflater;
5015 * HPACK inflater object.
5017 typedef struct nghttp2_hd_inflater nghttp2_hd_inflater;
5022 * Initializes |*inflater_ptr| for inflating name/values pairs.
5024 * If this function fails, |*inflater_ptr| is left untouched.
5026 * This function returns 0 if it succeeds, or one of the following
5027 * negative error codes:
5029 * :enum:`NGHTTP2_ERR_NOMEM`
5032 NGHTTP2_EXTERN int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr);
5037 * Like `nghttp2_hd_inflate_new()`, but with additional custom memory
5038 * allocator specified in the |mem|.
5040 * The |mem| can be ``NULL`` and the call is equivalent to
5041 * `nghttp2_hd_inflate_new()`.
5043 * This function does not take ownership |mem|. The application is
5044 * responsible for freeing |mem|.
5046 * The library code does not refer to |mem| pointer after this
5047 * function returns, so the application can safely free it.
5049 NGHTTP2_EXTERN int nghttp2_hd_inflate_new2(nghttp2_hd_inflater **inflater_ptr,
5055 * Deallocates any resources allocated for |inflater|.
5057 NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater);
5062 * Changes header table size in the |inflater|. This may trigger
5063 * eviction in the dynamic table.
5065 * The |settings_max_dynamic_table_size| should be the value
5066 * transmitted in SETTINGS_HEADER_TABLE_SIZE.
5068 * This function must not be called while header block is being
5069 * inflated. In other words, this function must be called after
5070 * initialization of |inflater|, but before calling
5071 * `nghttp2_hd_inflate_hd2()`, or after
5072 * `nghttp2_hd_inflate_end_headers()`. Otherwise,
5073 * `NGHTTP2_ERR_INVALID_STATE` was returned.
5075 * This function returns 0 if it succeeds, or one of the following
5076 * negative error codes:
5078 * :enum:`NGHTTP2_ERR_NOMEM`
5080 * :enum:`NGHTTP2_ERR_INVALID_STATE`
5081 * The function is called while header block is being inflated.
5082 * Probably, application missed to call
5083 * `nghttp2_hd_inflate_end_headers()`.
5086 nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater,
5087 size_t settings_max_dynamic_table_size);
5092 * The flags for header inflation.
5098 NGHTTP2_HD_INFLATE_NONE = 0,
5100 * Indicates all headers were inflated.
5102 NGHTTP2_HD_INFLATE_FINAL = 0x01,
5104 * Indicates a header was emitted.
5106 NGHTTP2_HD_INFLATE_EMIT = 0x02
5107 } nghttp2_hd_inflate_flag;
5114 * Deprecated. Use `nghttp2_hd_inflate_hd2()` instead.
5116 * Inflates name/value block stored in |in| with length |inlen|. This
5117 * function performs decompression. For each successful emission of
5118 * header name/value pair, :enum:`NGHTTP2_HD_INFLATE_EMIT` is set in
5119 * |*inflate_flags| and name/value pair is assigned to the |nv_out|
5120 * and the function returns. The caller must not free the members of
5123 * The |nv_out| may include pointers to the memory region in the |in|.
5124 * The caller must retain the |in| while the |nv_out| is used.
5126 * The application should call this function repeatedly until the
5127 * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
5128 * return value is non-negative. This means the all input values are
5129 * processed successfully. Then the application must call
5130 * `nghttp2_hd_inflate_end_headers()` to prepare for the next header
5133 * The caller can feed complete compressed header block. It also can
5134 * feed it in several chunks. The caller must set |in_final| to
5135 * nonzero if the given input is the last block of the compressed
5138 * This function returns the number of bytes processed if it succeeds,
5139 * or one of the following negative error codes:
5141 * :enum:`NGHTTP2_ERR_NOMEM`
5143 * :enum:`NGHTTP2_ERR_HEADER_COMP`
5144 * Inflation process has failed.
5145 * :enum:`NGHTTP2_ERR_BUFFER_ERROR`
5146 * The header field name or value is too large.
5150 * int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
5151 * uint8_t *in, size_t inlen, int final)
5157 * int inflate_flags = 0;
5159 * rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags,
5160 * in, inlen, final);
5163 * fprintf(stderr, "inflate failed with error code %zd", rv);
5170 * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
5171 * fwrite(nv.name, nv.namelen, 1, stderr);
5172 * fprintf(stderr, ": ");
5173 * fwrite(nv.value, nv.valuelen, 1, stderr);
5174 * fprintf(stderr, "\n");
5176 * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
5177 * nghttp2_hd_inflate_end_headers(hd_inflater);
5180 * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
5190 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
5192 int *inflate_flags, uint8_t *in,
5193 size_t inlen, int in_final);
5198 * Inflates name/value block stored in |in| with length |inlen|. This
5199 * function performs decompression. For each successful emission of
5200 * header name/value pair, :enum:`NGHTTP2_HD_INFLATE_EMIT` is set in
5201 * |*inflate_flags| and name/value pair is assigned to the |nv_out|
5202 * and the function returns. The caller must not free the members of
5205 * The |nv_out| may include pointers to the memory region in the |in|.
5206 * The caller must retain the |in| while the |nv_out| is used.
5208 * The application should call this function repeatedly until the
5209 * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
5210 * return value is non-negative. If that happens, all given input
5211 * data (|inlen| bytes) are processed successfully. Then the
5212 * application must call `nghttp2_hd_inflate_end_headers()` to prepare
5213 * for the next header block input.
5215 * In other words, if |in_final| is nonzero, and this function returns
5216 * |inlen|, you can assert that :enum:`NGHTTP2_HD_INFLATE_FINAL` is
5217 * set in |*inflate_flags|.
5219 * The caller can feed complete compressed header block. It also can
5220 * feed it in several chunks. The caller must set |in_final| to
5221 * nonzero if the given input is the last block of the compressed
5224 * This function returns the number of bytes processed if it succeeds,
5225 * or one of the following negative error codes:
5227 * :enum:`NGHTTP2_ERR_NOMEM`
5229 * :enum:`NGHTTP2_ERR_HEADER_COMP`
5230 * Inflation process has failed.
5231 * :enum:`NGHTTP2_ERR_BUFFER_ERROR`
5232 * The header field name or value is too large.
5236 * int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
5237 * uint8_t *in, size_t inlen, int final)
5243 * int inflate_flags = 0;
5245 * rv = nghttp2_hd_inflate_hd2(hd_inflater, &nv, &inflate_flags,
5246 * in, inlen, final);
5249 * fprintf(stderr, "inflate failed with error code %zd", rv);
5256 * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
5257 * fwrite(nv.name, nv.namelen, 1, stderr);
5258 * fprintf(stderr, ": ");
5259 * fwrite(nv.value, nv.valuelen, 1, stderr);
5260 * fprintf(stderr, "\n");
5262 * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
5263 * nghttp2_hd_inflate_end_headers(hd_inflater);
5266 * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
5276 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater,
5279 const uint8_t *in, size_t inlen,
5285 * Signals the end of decompression for one header block.
5287 * This function returns 0 if it succeeds. Currently this function
5291 nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater);
5296 * Returns the number of entries that header table of |inflater|
5297 * contains. This is the sum of the number of static table and
5298 * dynamic table, so the return value is at least 61.
5301 size_t nghttp2_hd_inflate_get_num_table_entries(nghttp2_hd_inflater *inflater);
5306 * Returns the table entry denoted by |idx| from header table of
5307 * |inflater|. The |idx| is 1-based, and idx=1 returns first entry of
5308 * static table. idx=62 returns first entry of dynamic table if it
5309 * exists. Specifying idx=0 is error, and this function returns NULL.
5310 * If |idx| is strictly greater than the number of entries the tables
5311 * contain, this function returns NULL.
5315 nghttp2_hd_inflate_get_table_entry(nghttp2_hd_inflater *inflater, size_t idx);
5320 * Returns the used dynamic table size, including the overhead 32
5321 * bytes per entry described in RFC 7541.
5324 size_t nghttp2_hd_inflate_get_dynamic_table_size(nghttp2_hd_inflater *inflater);
5329 * Returns the maximum dynamic table size.
5333 nghttp2_hd_inflate_get_max_dynamic_table_size(nghttp2_hd_inflater *inflater);
5335 struct nghttp2_stream;
5340 * The structure to represent HTTP/2 stream. The details of this
5341 * structure are intentionally hidden from the public API.
5343 typedef struct nghttp2_stream nghttp2_stream;
5348 * Returns pointer to :type:`nghttp2_stream` object denoted by
5349 * |stream_id|. If stream was not found, returns NULL.
5351 * Returns imaginary root stream (see
5352 * `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|.
5354 * Unless |stream_id| == 0, the returned pointer is valid until next
5355 * call of `nghttp2_session_send()`, `nghttp2_session_mem_send()`,
5356 * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv()`.
5358 NGHTTP2_EXTERN nghttp2_stream *
5359 nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id);
5364 * State of stream as described in RFC 7540.
5370 NGHTTP2_STREAM_STATE_IDLE = 1,
5374 NGHTTP2_STREAM_STATE_OPEN,
5376 * reserved (local) state.
5378 NGHTTP2_STREAM_STATE_RESERVED_LOCAL,
5380 * reserved (remote) state.
5382 NGHTTP2_STREAM_STATE_RESERVED_REMOTE,
5384 * half closed (local) state.
5386 NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL,
5388 * half closed (remote) state.
5390 NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE,
5394 NGHTTP2_STREAM_STATE_CLOSED
5395 } nghttp2_stream_proto_state;
5400 * Returns state of |stream|. The root stream retrieved by
5401 * `nghttp2_session_get_root_stream()` will have stream state
5402 * :enum:`NGHTTP2_STREAM_STATE_IDLE`.
5404 NGHTTP2_EXTERN nghttp2_stream_proto_state
5405 nghttp2_stream_get_state(nghttp2_stream *stream);
5410 * Returns root of dependency tree, which is imaginary stream with
5411 * stream ID 0. The returned pointer is valid until |session| is
5412 * freed by `nghttp2_session_del()`.
5414 NGHTTP2_EXTERN nghttp2_stream *
5415 nghttp2_session_get_root_stream(nghttp2_session *session);
5420 * Returns the parent stream of |stream| in dependency tree. Returns
5421 * NULL if there is no such stream.
5423 NGHTTP2_EXTERN nghttp2_stream *
5424 nghttp2_stream_get_parent(nghttp2_stream *stream);
5426 NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream);
5431 * Returns the next sibling stream of |stream| in dependency tree.
5432 * Returns NULL if there is no such stream.
5434 NGHTTP2_EXTERN nghttp2_stream *
5435 nghttp2_stream_get_next_sibling(nghttp2_stream *stream);
5440 * Returns the previous sibling stream of |stream| in dependency tree.
5441 * Returns NULL if there is no such stream.
5443 NGHTTP2_EXTERN nghttp2_stream *
5444 nghttp2_stream_get_previous_sibling(nghttp2_stream *stream);
5449 * Returns the first child stream of |stream| in dependency tree.
5450 * Returns NULL if there is no such stream.
5452 NGHTTP2_EXTERN nghttp2_stream *
5453 nghttp2_stream_get_first_child(nghttp2_stream *stream);
5458 * Returns dependency weight to the parent stream of |stream|.
5460 NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream);
5465 * Returns the sum of the weight for |stream|'s children.
5467 NGHTTP2_EXTERN int32_t
5468 nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream);
5473 * Callback function invoked when the library outputs debug logging.
5474 * The function is called with arguments suitable for ``vfprintf(3)``
5476 * The debug output is only enabled if the library is built with
5477 * ``DEBUGBUILD`` macro defined.
5479 typedef void (*nghttp2_debug_vprintf_callback)(const char *format,
5485 * Sets a debug output callback called by the library when built with
5486 * ``DEBUGBUILD`` macro defined. If this option is not used, debug
5487 * log is written into standard error output.
5489 * For builds without ``DEBUGBUILD`` macro defined, this function is
5492 * Note that building with ``DEBUGBUILD`` may cause significant
5493 * performance penalty to libnghttp2 because of extra processing. It
5494 * should be used for debugging purpose only.
5498 * Building with ``DEBUGBUILD`` may cause significant performance
5499 * penalty to libnghttp2 because of extra processing. It should be
5500 * used for debugging purpose only. We write this two times because
5501 * this is important.
5503 NGHTTP2_EXTERN void nghttp2_set_debug_vprintf_callback(
5504 nghttp2_debug_vprintf_callback debug_vprintf_callback);
5510 #endif /* NGHTTP2_H */