Path: blob/master/Utilities/cmnghttp2/lib/includes/nghttp2/nghttp2.h
3158 views
/*1* nghttp2 - HTTP/2 C Library2*3* Copyright (c) 2013, 2014 Tatsuhiro Tsujikawa4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice shall be14* included in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24#ifndef NGHTTP2_H25#define NGHTTP2_H2627/* Define WIN32 when build target is Win32 API (borrowed from28libcurl) */29#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)30# define WIN3231#endif3233/* Compatibility for non-Clang compilers */34#ifndef __has_declspec_attribute35# define __has_declspec_attribute(x) 036#endif3738#ifdef __cplusplus39extern "C" {40#endif4142#include <stdlib.h>43#if defined(_MSC_VER) && (_MSC_VER < 1800)44/* MSVC < 2013 does not have inttypes.h because it is not C9945compliant. See compiler macros and version number in46https://sourceforge.net/p/predef/wiki/Compilers/ */47# include <stdint.h>48#else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */49# include <inttypes.h>50#endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */51#include <sys/types.h>52#include <stdarg.h>5354#include <nghttp2/nghttp2ver.h>5556#ifdef NGHTTP2_STATICLIB57# define NGHTTP2_EXTERN58#elif defined(WIN32) || (__has_declspec_attribute(dllexport) && \59__has_declspec_attribute(dllimport))60# ifdef BUILDING_NGHTTP261# define NGHTTP2_EXTERN __declspec(dllexport)62# else /* !BUILDING_NGHTTP2 */63# define NGHTTP2_EXTERN __declspec(dllimport)64# endif /* !BUILDING_NGHTTP2 */65#else /* !defined(WIN32) */66# ifdef BUILDING_NGHTTP267# define NGHTTP2_EXTERN __attribute__((visibility("default")))68# else /* !BUILDING_NGHTTP2 */69# define NGHTTP2_EXTERN70# endif /* !BUILDING_NGHTTP2 */71#endif /* !defined(WIN32) */7273/**74* @macro75*76* The protocol version identification string of this library77* supports. This identifier is used if HTTP/2 is used over TLS.78*/79#define NGHTTP2_PROTO_VERSION_ID "h2"80/**81* @macro82*83* The length of :macro:`NGHTTP2_PROTO_VERSION_ID`.84*/85#define NGHTTP2_PROTO_VERSION_ID_LEN 28687/**88* @macro89*90* The serialized form of ALPN protocol identifier this library91* supports. Notice that first byte is the length of following92* protocol identifier. This is the same wire format of `TLS ALPN93* extension <https://tools.ietf.org/html/rfc7301>`_. This is useful94* to process incoming ALPN tokens in wire format.95*/96#define NGHTTP2_PROTO_ALPN "\x2h2"9798/**99* @macro100*101* The length of :macro:`NGHTTP2_PROTO_ALPN`.102*/103#define NGHTTP2_PROTO_ALPN_LEN (sizeof(NGHTTP2_PROTO_ALPN) - 1)104105/**106* @macro107*108* The protocol version identification string of this library109* supports. This identifier is used if HTTP/2 is used over cleartext110* TCP.111*/112#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c"113114/**115* @macro116*117* The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`.118*/119#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 3120121struct nghttp2_session;122/**123* @struct124*125* The primary structure to hold the resources needed for a HTTP/2126* session. The details of this structure are intentionally hidden127* from the public API.128*/129typedef struct nghttp2_session nghttp2_session;130131/**132* @macro133*134* The age of :type:`nghttp2_info`135*/136#define NGHTTP2_VERSION_AGE 1137138/**139* @struct140*141* This struct is what `nghttp2_version()` returns. It holds142* information about the particular nghttp2 version.143*/144typedef struct {145/**146* Age of this struct. This instance of nghttp2 sets it to147* :macro:`NGHTTP2_VERSION_AGE` but a future version may bump it and148* add more struct fields at the bottom149*/150int age;151/**152* the :macro:`NGHTTP2_VERSION_NUM` number (since age ==1)153*/154int version_num;155/**156* points to the :macro:`NGHTTP2_VERSION` string (since age ==1)157*/158const char *version_str;159/**160* points to the :macro:`NGHTTP2_PROTO_VERSION_ID` string this161* instance implements (since age ==1)162*/163const char *proto_str;164/* -------- the above fields all exist when age == 1 */165} nghttp2_info;166167/**168* @macro169*170* The default weight of stream dependency.171*/172#define NGHTTP2_DEFAULT_WEIGHT 16173174/**175* @macro176*177* The maximum weight of stream dependency.178*/179#define NGHTTP2_MAX_WEIGHT 256180181/**182* @macro183*184* The minimum weight of stream dependency.185*/186#define NGHTTP2_MIN_WEIGHT 1187188/**189* @macro190*191* The maximum window size192*/193#define NGHTTP2_MAX_WINDOW_SIZE ((int32_t)((1U << 31) - 1))194195/**196* @macro197*198* The initial window size for stream level flow control.199*/200#define NGHTTP2_INITIAL_WINDOW_SIZE ((1 << 16) - 1)201/**202* @macro203*204* The initial window size for connection level flow control.205*/206#define NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE ((1 << 16) - 1)207208/**209* @macro210*211* The default header table size.212*/213#define NGHTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12)214215/**216* @macro217*218* The client magic string, which is the first 24 bytes byte string of219* client connection preface.220*/221#define NGHTTP2_CLIENT_MAGIC "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"222223/**224* @macro225*226* The length of :macro:`NGHTTP2_CLIENT_MAGIC`.227*/228#define NGHTTP2_CLIENT_MAGIC_LEN 24229230/**231* @macro232*233* The default max number of settings per SETTINGS frame234*/235#define NGHTTP2_DEFAULT_MAX_SETTINGS 32236237/**238* @enum239*240* Error codes used in this library. The code range is [-999, -500],241* inclusive. The following values are defined:242*/243typedef enum {244/**245* Invalid argument passed.246*/247NGHTTP2_ERR_INVALID_ARGUMENT = -501,248/**249* Out of buffer space.250*/251NGHTTP2_ERR_BUFFER_ERROR = -502,252/**253* The specified protocol version is not supported.254*/255NGHTTP2_ERR_UNSUPPORTED_VERSION = -503,256/**257* Used as a return value from :type:`nghttp2_send_callback`,258* :type:`nghttp2_recv_callback` and259* :type:`nghttp2_send_data_callback` to indicate that the operation260* would block.261*/262NGHTTP2_ERR_WOULDBLOCK = -504,263/**264* General protocol error265*/266NGHTTP2_ERR_PROTO = -505,267/**268* The frame is invalid.269*/270NGHTTP2_ERR_INVALID_FRAME = -506,271/**272* The peer performed a shutdown on the connection.273*/274NGHTTP2_ERR_EOF = -507,275/**276* Used as a return value from277* :func:`nghttp2_data_source_read_callback` to indicate that data278* transfer is postponed. See279* :func:`nghttp2_data_source_read_callback` for details.280*/281NGHTTP2_ERR_DEFERRED = -508,282/**283* Stream ID has reached the maximum value. Therefore no stream ID284* is available.285*/286NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509,287/**288* The stream is already closed; or the stream ID is invalid.289*/290NGHTTP2_ERR_STREAM_CLOSED = -510,291/**292* RST_STREAM has been added to the outbound queue. The stream is293* in closing state.294*/295NGHTTP2_ERR_STREAM_CLOSING = -511,296/**297* The transmission is not allowed for this stream (e.g., a frame298* with END_STREAM flag set has already sent).299*/300NGHTTP2_ERR_STREAM_SHUT_WR = -512,301/**302* The stream ID is invalid.303*/304NGHTTP2_ERR_INVALID_STREAM_ID = -513,305/**306* The state of the stream is not valid (e.g., DATA cannot be sent307* to the stream if response HEADERS has not been sent).308*/309NGHTTP2_ERR_INVALID_STREAM_STATE = -514,310/**311* Another DATA frame has already been deferred.312*/313NGHTTP2_ERR_DEFERRED_DATA_EXIST = -515,314/**315* Starting new stream is not allowed (e.g., GOAWAY has been sent316* and/or received).317*/318NGHTTP2_ERR_START_STREAM_NOT_ALLOWED = -516,319/**320* GOAWAY has already been sent.321*/322NGHTTP2_ERR_GOAWAY_ALREADY_SENT = -517,323/**324* The received frame contains the invalid header block (e.g., There325* are duplicate header names; or the header names are not encoded326* in US-ASCII character set and not lower cased; or the header name327* is zero-length string; or the header value contains multiple328* in-sequence NUL bytes).329*/330NGHTTP2_ERR_INVALID_HEADER_BLOCK = -518,331/**332* Indicates that the context is not suitable to perform the333* requested operation.334*/335NGHTTP2_ERR_INVALID_STATE = -519,336/**337* The user callback function failed due to the temporal error.338*/339NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE = -521,340/**341* The length of the frame is invalid, either too large or too small.342*/343NGHTTP2_ERR_FRAME_SIZE_ERROR = -522,344/**345* Header block inflate/deflate error.346*/347NGHTTP2_ERR_HEADER_COMP = -523,348/**349* Flow control error350*/351NGHTTP2_ERR_FLOW_CONTROL = -524,352/**353* Insufficient buffer size given to function.354*/355NGHTTP2_ERR_INSUFF_BUFSIZE = -525,356/**357* Callback was paused by the application358*/359NGHTTP2_ERR_PAUSE = -526,360/**361* There are too many in-flight SETTING frame and no more362* transmission of SETTINGS is allowed.363*/364NGHTTP2_ERR_TOO_MANY_INFLIGHT_SETTINGS = -527,365/**366* The server push is disabled.367*/368NGHTTP2_ERR_PUSH_DISABLED = -528,369/**370* DATA or HEADERS frame for a given stream has been already371* submitted and has not been fully processed yet. Application372* should wait for the transmission of the previously submitted373* frame before submitting another.374*/375NGHTTP2_ERR_DATA_EXIST = -529,376/**377* The current session is closing due to a connection error or378* `nghttp2_session_terminate_session()` is called.379*/380NGHTTP2_ERR_SESSION_CLOSING = -530,381/**382* Invalid HTTP header field was received and stream is going to be383* closed.384*/385NGHTTP2_ERR_HTTP_HEADER = -531,386/**387* Violation in HTTP messaging rule.388*/389NGHTTP2_ERR_HTTP_MESSAGING = -532,390/**391* Stream was refused.392*/393NGHTTP2_ERR_REFUSED_STREAM = -533,394/**395* Unexpected internal error, but recovered.396*/397NGHTTP2_ERR_INTERNAL = -534,398/**399* Indicates that a processing was canceled.400*/401NGHTTP2_ERR_CANCEL = -535,402/**403* When a local endpoint expects to receive SETTINGS frame, it404* receives an other type of frame.405*/406NGHTTP2_ERR_SETTINGS_EXPECTED = -536,407/**408* When a local endpoint receives too many settings entries409* in a single SETTINGS frame.410*/411NGHTTP2_ERR_TOO_MANY_SETTINGS = -537,412/**413* The errors < :enum:`nghttp2_error.NGHTTP2_ERR_FATAL` mean that414* the library is under unexpected condition and processing was415* terminated (e.g., out of memory). If application receives this416* error code, it must stop using that :type:`nghttp2_session`417* object and only allowed operation for that object is deallocate418* it using `nghttp2_session_del()`.419*/420NGHTTP2_ERR_FATAL = -900,421/**422* Out of memory. This is a fatal error.423*/424NGHTTP2_ERR_NOMEM = -901,425/**426* The user callback function failed. This is a fatal error.427*/428NGHTTP2_ERR_CALLBACK_FAILURE = -902,429/**430* Invalid client magic (see :macro:`NGHTTP2_CLIENT_MAGIC`) was431* received and further processing is not possible.432*/433NGHTTP2_ERR_BAD_CLIENT_MAGIC = -903,434/**435* Possible flooding by peer was detected in this HTTP/2 session.436* Flooding is measured by how many PING and SETTINGS frames with437* ACK flag set are queued for transmission. These frames are438* response for the peer initiated frames, and peer can cause memory439* exhaustion on server side to send these frames forever and does440* not read network.441*/442NGHTTP2_ERR_FLOODED = -904443} nghttp2_error;444445/**446* @struct447*448* The object representing single contiguous buffer.449*/450typedef struct {451/**452* The pointer to the buffer.453*/454uint8_t *base;455/**456* The length of the buffer.457*/458size_t len;459} nghttp2_vec;460461struct nghttp2_rcbuf;462463/**464* @struct465*466* The object representing reference counted buffer. The details of467* this structure are intentionally hidden from the public API.468*/469typedef struct nghttp2_rcbuf nghttp2_rcbuf;470471/**472* @function473*474* Increments the reference count of |rcbuf| by 1.475*/476NGHTTP2_EXTERN void nghttp2_rcbuf_incref(nghttp2_rcbuf *rcbuf);477478/**479* @function480*481* Decrements the reference count of |rcbuf| by 1. If the reference482* count becomes zero, the object pointed by |rcbuf| will be freed.483* In this case, application must not use |rcbuf| again.484*/485NGHTTP2_EXTERN void nghttp2_rcbuf_decref(nghttp2_rcbuf *rcbuf);486487/**488* @function489*490* Returns the underlying buffer managed by |rcbuf|.491*/492NGHTTP2_EXTERN nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf);493494/**495* @function496*497* Returns nonzero if the underlying buffer is statically allocated,498* and 0 otherwise. This can be useful for language bindings that wish499* to avoid creating duplicate strings for these buffers.500*/501NGHTTP2_EXTERN int nghttp2_rcbuf_is_static(const nghttp2_rcbuf *rcbuf);502503/**504* @enum505*506* The flags for header field name/value pair.507*/508typedef enum {509/**510* No flag set.511*/512NGHTTP2_NV_FLAG_NONE = 0,513/**514* Indicates that this name/value pair must not be indexed ("Literal515* Header Field never Indexed" representation must be used in HPACK516* encoding). Other implementation calls this bit as "sensitive".517*/518NGHTTP2_NV_FLAG_NO_INDEX = 0x01,519/**520* This flag is set solely by application. If this flag is set, the521* library does not make a copy of header field name. This could522* improve performance.523*/524NGHTTP2_NV_FLAG_NO_COPY_NAME = 0x02,525/**526* This flag is set solely by application. If this flag is set, the527* library does not make a copy of header field value. This could528* improve performance.529*/530NGHTTP2_NV_FLAG_NO_COPY_VALUE = 0x04531} nghttp2_nv_flag;532533/**534* @struct535*536* The name/value pair, which mainly used to represent header fields.537*/538typedef struct {539/**540* The |name| byte string. If this struct is presented from library541* (e.g., :type:`nghttp2_on_frame_recv_callback`), |name| is542* guaranteed to be NULL-terminated. For some callbacks543* (:type:`nghttp2_before_frame_send_callback`,544* :type:`nghttp2_on_frame_send_callback`, and545* :type:`nghttp2_on_frame_not_send_callback`), it may not be546* NULL-terminated if header field is passed from application with547* the flag :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`).548* When application is constructing this struct, |name| is not549* required to be NULL-terminated.550*/551uint8_t *name;552/**553* The |value| byte string. If this struct is presented from554* library (e.g., :type:`nghttp2_on_frame_recv_callback`), |value|555* is guaranteed to be NULL-terminated. For some callbacks556* (:type:`nghttp2_before_frame_send_callback`,557* :type:`nghttp2_on_frame_send_callback`, and558* :type:`nghttp2_on_frame_not_send_callback`), it may not be559* NULL-terminated if header field is passed from application with560* the flag :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE`).561* When application is constructing this struct, |value| is not562* required to be NULL-terminated.563*/564uint8_t *value;565/**566* The length of the |name|, excluding terminating NULL.567*/568size_t namelen;569/**570* The length of the |value|, excluding terminating NULL.571*/572size_t valuelen;573/**574* Bitwise OR of one or more of :type:`nghttp2_nv_flag`.575*/576uint8_t flags;577} nghttp2_nv;578579/**580* @enum581*582* The frame types in HTTP/2 specification.583*/584typedef enum {585/**586* The DATA frame.587*/588NGHTTP2_DATA = 0,589/**590* The HEADERS frame.591*/592NGHTTP2_HEADERS = 0x01,593/**594* The PRIORITY frame.595*/596NGHTTP2_PRIORITY = 0x02,597/**598* The RST_STREAM frame.599*/600NGHTTP2_RST_STREAM = 0x03,601/**602* The SETTINGS frame.603*/604NGHTTP2_SETTINGS = 0x04,605/**606* The PUSH_PROMISE frame.607*/608NGHTTP2_PUSH_PROMISE = 0x05,609/**610* The PING frame.611*/612NGHTTP2_PING = 0x06,613/**614* The GOAWAY frame.615*/616NGHTTP2_GOAWAY = 0x07,617/**618* The WINDOW_UPDATE frame.619*/620NGHTTP2_WINDOW_UPDATE = 0x08,621/**622* The CONTINUATION frame. This frame type won't be passed to any623* callbacks because the library processes this frame type and its624* preceding HEADERS/PUSH_PROMISE as a single frame.625*/626NGHTTP2_CONTINUATION = 0x09,627/**628* The ALTSVC frame, which is defined in `RFC 7383629* <https://tools.ietf.org/html/rfc7838#section-4>`_.630*/631NGHTTP2_ALTSVC = 0x0a,632/**633* The ORIGIN frame, which is defined by `RFC 8336634* <https://tools.ietf.org/html/rfc8336>`_.635*/636NGHTTP2_ORIGIN = 0x0c,637/**638* The PRIORITY_UPDATE frame, which is defined by :rfc:`9218`.639*/640NGHTTP2_PRIORITY_UPDATE = 0x10641} nghttp2_frame_type;642643/**644* @enum645*646* The flags for HTTP/2 frames. This enum defines all flags for all647* frames.648*/649typedef enum {650/**651* No flag set.652*/653NGHTTP2_FLAG_NONE = 0,654/**655* The END_STREAM flag.656*/657NGHTTP2_FLAG_END_STREAM = 0x01,658/**659* The END_HEADERS flag.660*/661NGHTTP2_FLAG_END_HEADERS = 0x04,662/**663* The ACK flag.664*/665NGHTTP2_FLAG_ACK = 0x01,666/**667* The PADDED flag.668*/669NGHTTP2_FLAG_PADDED = 0x08,670/**671* The PRIORITY flag.672*/673NGHTTP2_FLAG_PRIORITY = 0x20674} nghttp2_flag;675676/**677* @enum678* The SETTINGS ID.679*/680typedef enum {681/**682* SETTINGS_HEADER_TABLE_SIZE683*/684NGHTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x01,685/**686* SETTINGS_ENABLE_PUSH687*/688NGHTTP2_SETTINGS_ENABLE_PUSH = 0x02,689/**690* SETTINGS_MAX_CONCURRENT_STREAMS691*/692NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x03,693/**694* SETTINGS_INITIAL_WINDOW_SIZE695*/696NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x04,697/**698* SETTINGS_MAX_FRAME_SIZE699*/700NGHTTP2_SETTINGS_MAX_FRAME_SIZE = 0x05,701/**702* SETTINGS_MAX_HEADER_LIST_SIZE703*/704NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x06,705/**706* SETTINGS_ENABLE_CONNECT_PROTOCOL707* (`RFC 8441 <https://tools.ietf.org/html/rfc8441>`_)708*/709NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL = 0x08,710/**711* SETTINGS_NO_RFC7540_PRIORITIES (:rfc:`9218`)712*/713NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES = 0x09714} nghttp2_settings_id;715/* Note: If we add SETTINGS, update the capacity of716NGHTTP2_INBOUND_NUM_IV as well */717718/**719* @macro720*721* .. warning::722*723* Deprecated. The initial max concurrent streams is 0xffffffffu.724*725* Default maximum number of incoming concurrent streams. Use726* `nghttp2_submit_settings()` with727* :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS`728* to change the maximum number of incoming concurrent streams.729*730* .. note::731*732* The maximum number of outgoing concurrent streams is 100 by733* default.734*/735#define NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1)736737/**738* @enum739* The status codes for the RST_STREAM and GOAWAY frames.740*/741typedef enum {742/**743* No errors.744*/745NGHTTP2_NO_ERROR = 0x00,746/**747* PROTOCOL_ERROR748*/749NGHTTP2_PROTOCOL_ERROR = 0x01,750/**751* INTERNAL_ERROR752*/753NGHTTP2_INTERNAL_ERROR = 0x02,754/**755* FLOW_CONTROL_ERROR756*/757NGHTTP2_FLOW_CONTROL_ERROR = 0x03,758/**759* SETTINGS_TIMEOUT760*/761NGHTTP2_SETTINGS_TIMEOUT = 0x04,762/**763* STREAM_CLOSED764*/765NGHTTP2_STREAM_CLOSED = 0x05,766/**767* FRAME_SIZE_ERROR768*/769NGHTTP2_FRAME_SIZE_ERROR = 0x06,770/**771* REFUSED_STREAM772*/773NGHTTP2_REFUSED_STREAM = 0x07,774/**775* CANCEL776*/777NGHTTP2_CANCEL = 0x08,778/**779* COMPRESSION_ERROR780*/781NGHTTP2_COMPRESSION_ERROR = 0x09,782/**783* CONNECT_ERROR784*/785NGHTTP2_CONNECT_ERROR = 0x0a,786/**787* ENHANCE_YOUR_CALM788*/789NGHTTP2_ENHANCE_YOUR_CALM = 0x0b,790/**791* INADEQUATE_SECURITY792*/793NGHTTP2_INADEQUATE_SECURITY = 0x0c,794/**795* HTTP_1_1_REQUIRED796*/797NGHTTP2_HTTP_1_1_REQUIRED = 0x0d798} nghttp2_error_code;799800/**801* @struct802* The frame header.803*/804typedef struct {805/**806* The length field of this frame, excluding frame header.807*/808size_t length;809/**810* The stream identifier (aka, stream ID)811*/812int32_t stream_id;813/**814* The type of this frame. See `nghttp2_frame_type`.815*/816uint8_t type;817/**818* The flags.819*/820uint8_t flags;821/**822* Reserved bit in frame header. Currently, this is always set to 0823* and application should not expect something useful in here.824*/825uint8_t reserved;826} nghttp2_frame_hd;827828/**829* @union830*831* This union represents the some kind of data source passed to832* :type:`nghttp2_data_source_read_callback`.833*/834typedef union {835/**836* The integer field, suitable for a file descriptor.837*/838int fd;839/**840* The pointer to an arbitrary object.841*/842void *ptr;843} nghttp2_data_source;844845/**846* @enum847*848* The flags used to set in |data_flags| output parameter in849* :type:`nghttp2_data_source_read_callback`.850*/851typedef enum {852/**853* No flag set.854*/855NGHTTP2_DATA_FLAG_NONE = 0,856/**857* Indicates EOF was sensed.858*/859NGHTTP2_DATA_FLAG_EOF = 0x01,860/**861* Indicates that END_STREAM flag must not be set even if862* NGHTTP2_DATA_FLAG_EOF is set. Usually this flag is used to send863* trailer fields with `nghttp2_submit_request()` or864* `nghttp2_submit_response()`.865*/866NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02,867/**868* Indicates that application will send complete DATA frame in869* :type:`nghttp2_send_data_callback`.870*/871NGHTTP2_DATA_FLAG_NO_COPY = 0x04872} nghttp2_data_flag;873874/**875* @functypedef876*877* Callback function invoked when the library wants to read data from878* the |source|. The read data is sent in the stream |stream_id|.879* The implementation of this function must read at most |length|880* bytes of data from |source| (or possibly other places) and store881* them in |buf| and return number of data stored in |buf|. If EOF is882* reached, set :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag883* in |*data_flags|.884*885* Sometime it is desirable to avoid copying data into |buf| and let886* application to send data directly. To achieve this, set887* :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` to888* |*data_flags| (and possibly other flags, just like when we do889* copy), and return the number of bytes to send without copying data890* into |buf|. The library, seeing891* :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY`, will invoke892* :type:`nghttp2_send_data_callback`. The application must send893* complete DATA frame in that callback.894*895* If this callback is set by `nghttp2_submit_request()`,896* `nghttp2_submit_response()` or `nghttp2_submit_headers()` and897* `nghttp2_submit_data()` with flag parameter898* :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` set, and899* :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag is set to900* |*data_flags|, DATA frame will have END_STREAM flag set. Usually,901* this is expected behaviour and all are fine. One exception is send902* trailer fields. You cannot send trailer fields after sending frame903* with END_STREAM set. To avoid this problem, one can set904* :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM` along905* with :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` to signal the906* library not to set END_STREAM in DATA frame. Then application can907* use `nghttp2_submit_trailer()` to send trailer fields.908* `nghttp2_submit_trailer()` can be called inside this callback.909*910* If the application wants to postpone DATA frames (e.g.,911* asynchronous I/O, or reading data blocks for long time), it is912* achieved by returning :enum:`nghttp2_error.NGHTTP2_ERR_DEFERRED`913* without reading any data in this invocation. The library removes914* DATA frame from the outgoing queue temporarily. To move back915* deferred DATA frame to outgoing queue, call916* `nghttp2_session_resume_data()`.917*918* By default, |length| is limited to 16KiB at maximum. If peer919* allows larger frames, application can enlarge transmission buffer920* size. See :type:`nghttp2_data_source_read_length_callback` for921* more details.922*923* If the application just wants to return from924* `nghttp2_session_send()` or `nghttp2_session_mem_send()` without925* sending anything, return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`.926*927* In case of error, there are 2 choices. Returning928* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will929* close the stream by issuing RST_STREAM with930* :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. If a different931* error code is desirable, use `nghttp2_submit_rst_stream()` with a932* desired error code and then return933* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.934* Returning :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will935* signal the entire session failure.936*/937typedef ssize_t (*nghttp2_data_source_read_callback)(938nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length,939uint32_t *data_flags, nghttp2_data_source *source, void *user_data);940941/**942* @struct943*944* This struct represents the data source and the way to read a chunk945* of data from it.946*/947typedef struct {948/**949* The data source.950*/951nghttp2_data_source source;952/**953* The callback function to read a chunk of data from the |source|.954*/955nghttp2_data_source_read_callback read_callback;956} nghttp2_data_provider;957958/**959* @struct960*961* The DATA frame. The received data is delivered via962* :type:`nghttp2_on_data_chunk_recv_callback`.963*/964typedef struct {965nghttp2_frame_hd hd;966/**967* The length of the padding in this frame. This includes PAD_HIGH968* and PAD_LOW.969*/970size_t padlen;971} nghttp2_data;972973/**974* @enum975*976* The category of HEADERS, which indicates the role of the frame. In977* HTTP/2 spec, request, response, push response and other arbitrary978* headers (e.g., trailer fields) are all called just HEADERS. To979* give the application the role of incoming HEADERS frame, we define980* several categories.981*/982typedef enum {983/**984* The HEADERS frame is opening new stream, which is analogous to985* SYN_STREAM in SPDY.986*/987NGHTTP2_HCAT_REQUEST = 0,988/**989* The HEADERS frame is the first response headers, which is990* analogous to SYN_REPLY in SPDY.991*/992NGHTTP2_HCAT_RESPONSE = 1,993/**994* The HEADERS frame is the first headers sent against reserved995* stream.996*/997NGHTTP2_HCAT_PUSH_RESPONSE = 2,998/**999* The HEADERS frame which does not apply for the above categories,1000* which is analogous to HEADERS in SPDY. If non-final response1001* (e.g., status 1xx) is used, final response HEADERS frame will be1002* categorized here.1003*/1004NGHTTP2_HCAT_HEADERS = 31005} nghttp2_headers_category;10061007/**1008* @struct1009*1010* The structure to specify stream dependency.1011*/1012typedef struct {1013/**1014* The stream ID of the stream to depend on. Specifying 0 makes1015* stream not depend any other stream.1016*/1017int32_t stream_id;1018/**1019* The weight of this dependency.1020*/1021int32_t weight;1022/**1023* nonzero means exclusive dependency1024*/1025uint8_t exclusive;1026} nghttp2_priority_spec;10271028/**1029* @struct1030*1031* The HEADERS frame. It has the following members:1032*/1033typedef struct {1034/**1035* The frame header.1036*/1037nghttp2_frame_hd hd;1038/**1039* The length of the padding in this frame. This includes PAD_HIGH1040* and PAD_LOW.1041*/1042size_t padlen;1043/**1044* The priority specification1045*/1046nghttp2_priority_spec pri_spec;1047/**1048* The name/value pairs.1049*/1050nghttp2_nv *nva;1051/**1052* The number of name/value pairs in |nva|.1053*/1054size_t nvlen;1055/**1056* The category of this HEADERS frame.1057*/1058nghttp2_headers_category cat;1059} nghttp2_headers;10601061/**1062* @struct1063*1064* The PRIORITY frame. It has the following members:1065*/1066typedef struct {1067/**1068* The frame header.1069*/1070nghttp2_frame_hd hd;1071/**1072* The priority specification.1073*/1074nghttp2_priority_spec pri_spec;1075} nghttp2_priority;10761077/**1078* @struct1079*1080* The RST_STREAM frame. It has the following members:1081*/1082typedef struct {1083/**1084* The frame header.1085*/1086nghttp2_frame_hd hd;1087/**1088* The error code. See :type:`nghttp2_error_code`.1089*/1090uint32_t error_code;1091} nghttp2_rst_stream;10921093/**1094* @struct1095*1096* The SETTINGS ID/Value pair. It has the following members:1097*/1098typedef struct {1099/**1100* The SETTINGS ID. See :type:`nghttp2_settings_id`.1101*/1102int32_t settings_id;1103/**1104* The value of this entry.1105*/1106uint32_t value;1107} nghttp2_settings_entry;11081109/**1110* @struct1111*1112* The SETTINGS frame. It has the following members:1113*/1114typedef struct {1115/**1116* The frame header.1117*/1118nghttp2_frame_hd hd;1119/**1120* The number of SETTINGS ID/Value pairs in |iv|.1121*/1122size_t niv;1123/**1124* The pointer to the array of SETTINGS ID/Value pair.1125*/1126nghttp2_settings_entry *iv;1127} nghttp2_settings;11281129/**1130* @struct1131*1132* The PUSH_PROMISE frame. It has the following members:1133*/1134typedef struct {1135/**1136* The frame header.1137*/1138nghttp2_frame_hd hd;1139/**1140* The length of the padding in this frame. This includes PAD_HIGH1141* and PAD_LOW.1142*/1143size_t padlen;1144/**1145* The name/value pairs.1146*/1147nghttp2_nv *nva;1148/**1149* The number of name/value pairs in |nva|.1150*/1151size_t nvlen;1152/**1153* The promised stream ID1154*/1155int32_t promised_stream_id;1156/**1157* Reserved bit. Currently this is always set to 0 and application1158* should not expect something useful in here.1159*/1160uint8_t reserved;1161} nghttp2_push_promise;11621163/**1164* @struct1165*1166* The PING frame. It has the following members:1167*/1168typedef struct {1169/**1170* The frame header.1171*/1172nghttp2_frame_hd hd;1173/**1174* The opaque data1175*/1176uint8_t opaque_data[8];1177} nghttp2_ping;11781179/**1180* @struct1181*1182* The GOAWAY frame. It has the following members:1183*/1184typedef struct {1185/**1186* The frame header.1187*/1188nghttp2_frame_hd hd;1189/**1190* The last stream stream ID.1191*/1192int32_t last_stream_id;1193/**1194* The error code. See :type:`nghttp2_error_code`.1195*/1196uint32_t error_code;1197/**1198* The additional debug data1199*/1200uint8_t *opaque_data;1201/**1202* The length of |opaque_data| member.1203*/1204size_t opaque_data_len;1205/**1206* Reserved bit. Currently this is always set to 0 and application1207* should not expect something useful in here.1208*/1209uint8_t reserved;1210} nghttp2_goaway;12111212/**1213* @struct1214*1215* The WINDOW_UPDATE frame. It has the following members:1216*/1217typedef struct {1218/**1219* The frame header.1220*/1221nghttp2_frame_hd hd;1222/**1223* The window size increment.1224*/1225int32_t window_size_increment;1226/**1227* Reserved bit. Currently this is always set to 0 and application1228* should not expect something useful in here.1229*/1230uint8_t reserved;1231} nghttp2_window_update;12321233/**1234* @struct1235*1236* The extension frame. It has following members:1237*/1238typedef struct {1239/**1240* The frame header.1241*/1242nghttp2_frame_hd hd;1243/**1244* The pointer to extension payload. The exact pointer type is1245* determined by hd.type.1246*1247* Currently, no extension is supported. This is a place holder for1248* the future extensions.1249*/1250void *payload;1251} nghttp2_extension;12521253/**1254* @union1255*1256* This union includes all frames to pass them to various function1257* calls as nghttp2_frame type. The CONTINUATION frame is omitted1258* from here because the library deals with it internally.1259*/1260typedef union {1261/**1262* The frame header, which is convenient to inspect frame header.1263*/1264nghttp2_frame_hd hd;1265/**1266* The DATA frame.1267*/1268nghttp2_data data;1269/**1270* The HEADERS frame.1271*/1272nghttp2_headers headers;1273/**1274* The PRIORITY frame.1275*/1276nghttp2_priority priority;1277/**1278* The RST_STREAM frame.1279*/1280nghttp2_rst_stream rst_stream;1281/**1282* The SETTINGS frame.1283*/1284nghttp2_settings settings;1285/**1286* The PUSH_PROMISE frame.1287*/1288nghttp2_push_promise push_promise;1289/**1290* The PING frame.1291*/1292nghttp2_ping ping;1293/**1294* The GOAWAY frame.1295*/1296nghttp2_goaway goaway;1297/**1298* The WINDOW_UPDATE frame.1299*/1300nghttp2_window_update window_update;1301/**1302* The extension frame.1303*/1304nghttp2_extension ext;1305} nghttp2_frame;13061307/**1308* @functypedef1309*1310* Callback function invoked when |session| wants to send data to the1311* remote peer. The implementation of this function must send at most1312* |length| bytes of data stored in |data|. The |flags| is currently1313* not used and always 0. It must return the number of bytes sent if1314* it succeeds. If it cannot send any single byte without blocking,1315* it must return :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. For1316* other errors, it must return1317* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The1318* |user_data| pointer is the third argument passed in to the call to1319* `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.1320*1321* This callback is required if the application uses1322* `nghttp2_session_send()` to send data to the remote endpoint. If1323* the application uses solely `nghttp2_session_mem_send()` instead,1324* this callback function is unnecessary.1325*1326* To set this callback to :type:`nghttp2_session_callbacks`, use1327* `nghttp2_session_callbacks_set_send_callback()`.1328*1329* .. note::1330*1331* The |length| may be very small. If that is the case, and1332* application disables Nagle algorithm (``TCP_NODELAY``), then just1333* writing |data| to the network stack leads to very small packet,1334* and it is very inefficient. An application should be responsible1335* to buffer up small chunks of data as necessary to avoid this1336* situation.1337*/1338typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session,1339const uint8_t *data, size_t length,1340int flags, void *user_data);13411342/**1343* @functypedef1344*1345* Callback function invoked when1346* :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` is used in1347* :type:`nghttp2_data_source_read_callback` to send complete DATA1348* frame.1349*1350* The |frame| is a DATA frame to send. The |framehd| is the1351* serialized frame header (9 bytes). The |length| is the length of1352* application data to send (this does not include padding). The1353* |source| is the same pointer passed to1354* :type:`nghttp2_data_source_read_callback`.1355*1356* The application first must send frame header |framehd| of length 91357* bytes. If ``frame->data.padlen > 0``, send 1 byte of value1358* ``frame->data.padlen - 1``. Then send exactly |length| bytes of1359* application data. Finally, if ``frame->data.padlen > 1``, send1360* ``frame->data.padlen - 1`` bytes of zero as padding.1361*1362* The application has to send complete DATA frame in this callback.1363* If all data were written successfully, return 0.1364*1365* If it cannot send any data at all, just return1366* :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`; the library will call1367* this callback with the same parameters later (It is recommended to1368* send complete DATA frame at once in this function to deal with1369* error; if partial frame data has already sent, it is impossible to1370* send another data in that state, and all we can do is tear down1371* connection). When data is fully processed, but application wants1372* to make `nghttp2_session_mem_send()` or `nghttp2_session_send()`1373* return immediately without processing next frames, return1374* :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. If application decided to1375* reset this stream, return1376* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`, then1377* the library will send RST_STREAM with INTERNAL_ERROR as error code.1378* The application can also return1379* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, which will1380* result in connection closure. Returning any other value is treated1381* as :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned.1382*/1383typedef int (*nghttp2_send_data_callback)(nghttp2_session *session,1384nghttp2_frame *frame,1385const uint8_t *framehd, size_t length,1386nghttp2_data_source *source,1387void *user_data);13881389/**1390* @functypedef1391*1392* Callback function invoked when |session| wants to receive data from1393* the remote peer. The implementation of this function must read at1394* most |length| bytes of data and store it in |buf|. The |flags| is1395* currently not used and always 0. It must return the number of1396* bytes written in |buf| if it succeeds. If it cannot read any1397* single byte without blocking, it must return1398* :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF1399* before it reads any single byte, it must return1400* :enum:`nghttp2_error.NGHTTP2_ERR_EOF`. For other errors, it must1401* return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1402* Returning 0 is treated as1403* :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. The |user_data|1404* pointer is the third argument passed in to the call to1405* `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.1406*1407* This callback is required if the application uses1408* `nghttp2_session_recv()` to receive data from the remote endpoint.1409* If the application uses solely `nghttp2_session_mem_recv()`1410* instead, this callback function is unnecessary.1411*1412* To set this callback to :type:`nghttp2_session_callbacks`, use1413* `nghttp2_session_callbacks_set_recv_callback()`.1414*/1415typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf,1416size_t length, int flags,1417void *user_data);14181419/**1420* @functypedef1421*1422* Callback function invoked by `nghttp2_session_recv()` and1423* `nghttp2_session_mem_recv()` when a frame is received. The1424* |user_data| pointer is the third argument passed in to the call to1425* `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.1426*1427* If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen``1428* member of their data structure are always ``NULL`` and 01429* respectively. The header name/value pairs are emitted via1430* :type:`nghttp2_on_header_callback`.1431*1432* Only HEADERS and DATA frame can signal the end of incoming data.1433* If ``frame->hd.flags & NGHTTP2_FLAG_END_STREAM`` is nonzero, the1434* |frame| is the last frame from the remote peer in this stream.1435*1436* This callback won't be called for CONTINUATION frames.1437* HEADERS/PUSH_PROMISE + CONTINUATIONs are treated as single frame.1438*1439* The implementation of this function must return 0 if it succeeds.1440* If nonzero value is returned, it is treated as fatal error and1441* `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions1442* immediately return1443* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1444*1445* To set this callback to :type:`nghttp2_session_callbacks`, use1446* `nghttp2_session_callbacks_set_on_frame_recv_callback()`.1447*/1448typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session,1449const nghttp2_frame *frame,1450void *user_data);14511452/**1453* @functypedef1454*1455* Callback function invoked by `nghttp2_session_recv()` and1456* `nghttp2_session_mem_recv()` when an invalid non-DATA frame is1457* received. The error is indicated by the |lib_error_code|, which is1458* one of the values defined in :type:`nghttp2_error`. When this1459* callback function is invoked, the library automatically submits1460* either RST_STREAM or GOAWAY frame. The |user_data| pointer is the1461* third argument passed in to the call to1462* `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.1463*1464* If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen``1465* member of their data structure are always ``NULL`` and 01466* respectively.1467*1468* The implementation of this function must return 0 if it succeeds.1469* If nonzero is returned, it is treated as fatal error and1470* `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions1471* immediately return1472* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1473*1474* To set this callback to :type:`nghttp2_session_callbacks`, use1475* `nghttp2_session_callbacks_set_on_invalid_frame_recv_callback()`.1476*/1477typedef int (*nghttp2_on_invalid_frame_recv_callback)(1478nghttp2_session *session, const nghttp2_frame *frame, int lib_error_code,1479void *user_data);14801481/**1482* @functypedef1483*1484* Callback function invoked when a chunk of data in DATA frame is1485* received. The |stream_id| is the stream ID this DATA frame belongs1486* to. The |flags| is the flags of DATA frame which this data chunk1487* is contained. ``(flags & NGHTTP2_FLAG_END_STREAM) != 0`` does not1488* necessarily mean this chunk of data is the last one in the stream.1489* You should use :type:`nghttp2_on_frame_recv_callback` to know all1490* data frames are received. The |user_data| pointer is the third1491* argument passed in to the call to `nghttp2_session_client_new()` or1492* `nghttp2_session_server_new()`.1493*1494* If the application uses `nghttp2_session_mem_recv()`, it can return1495* :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make1496* `nghttp2_session_mem_recv()` return without processing further1497* input bytes. The memory by pointed by the |data| is retained until1498* `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called.1499* The application must retain the input bytes which was used to1500* produce the |data| parameter, because it may refer to the memory1501* region included in the input bytes.1502*1503* The implementation of this function must return 0 if it succeeds.1504* If nonzero is returned, it is treated as fatal error, and1505* `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions1506* immediately return1507* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1508*1509* To set this callback to :type:`nghttp2_session_callbacks`, use1510* `nghttp2_session_callbacks_set_on_data_chunk_recv_callback()`.1511*/1512typedef int (*nghttp2_on_data_chunk_recv_callback)(nghttp2_session *session,1513uint8_t flags,1514int32_t stream_id,1515const uint8_t *data,1516size_t len, void *user_data);15171518/**1519* @functypedef1520*1521* Callback function invoked just before the non-DATA frame |frame| is1522* sent. The |user_data| pointer is the third argument passed in to1523* the call to `nghttp2_session_client_new()` or1524* `nghttp2_session_server_new()`.1525*1526* The implementation of this function must return 0 if it succeeds.1527* It can also return :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL` to1528* cancel the transmission of the given frame.1529*1530* If there is a fatal error while executing this callback, the1531* implementation should return1532* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, which makes1533* `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions1534* immediately return1535* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1536*1537* If the other value is returned, it is treated as if1538* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned.1539* But the implementation should not rely on this since the library1540* may define new return value to extend its capability.1541*1542* To set this callback to :type:`nghttp2_session_callbacks`, use1543* `nghttp2_session_callbacks_set_before_frame_send_callback()`.1544*/1545typedef int (*nghttp2_before_frame_send_callback)(nghttp2_session *session,1546const nghttp2_frame *frame,1547void *user_data);15481549/**1550* @functypedef1551*1552* Callback function invoked after the frame |frame| is sent. The1553* |user_data| pointer is the third argument passed in to the call to1554* `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.1555*1556* The implementation of this function must return 0 if it succeeds.1557* If nonzero is returned, it is treated as fatal error and1558* `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions1559* immediately return1560* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1561*1562* To set this callback to :type:`nghttp2_session_callbacks`, use1563* `nghttp2_session_callbacks_set_on_frame_send_callback()`.1564*/1565typedef int (*nghttp2_on_frame_send_callback)(nghttp2_session *session,1566const nghttp2_frame *frame,1567void *user_data);15681569/**1570* @functypedef1571*1572* Callback function invoked after the non-DATA frame |frame| is not1573* sent because of the error. The error is indicated by the1574* |lib_error_code|, which is one of the values defined in1575* :type:`nghttp2_error`. The |user_data| pointer is the third1576* argument passed in to the call to `nghttp2_session_client_new()` or1577* `nghttp2_session_server_new()`.1578*1579* The implementation of this function must return 0 if it succeeds.1580* If nonzero is returned, it is treated as fatal error and1581* `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions1582* immediately return1583* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1584*1585* `nghttp2_session_get_stream_user_data()` can be used to get1586* associated data.1587*1588* To set this callback to :type:`nghttp2_session_callbacks`, use1589* `nghttp2_session_callbacks_set_on_frame_not_send_callback()`.1590*/1591typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session,1592const nghttp2_frame *frame,1593int lib_error_code,1594void *user_data);15951596/**1597* @functypedef1598*1599* Callback function invoked when the stream |stream_id| is closed.1600* The reason of closure is indicated by the |error_code|. The1601* |error_code| is usually one of :enum:`nghttp2_error_code`, but that1602* is not guaranteed. The stream_user_data, which was specified in1603* `nghttp2_submit_request()` or `nghttp2_submit_headers()`, is still1604* available in this function. The |user_data| pointer is the third1605* argument passed in to the call to `nghttp2_session_client_new()` or1606* `nghttp2_session_server_new()`.1607*1608* This function is also called for a stream in reserved state.1609*1610* The implementation of this function must return 0 if it succeeds.1611* If nonzero is returned, it is treated as fatal error and1612* `nghttp2_session_recv()`, `nghttp2_session_mem_recv()`,1613* `nghttp2_session_send()`, and `nghttp2_session_mem_send()`1614* functions immediately return1615* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1616*1617* To set this callback to :type:`nghttp2_session_callbacks`, use1618* `nghttp2_session_callbacks_set_on_stream_close_callback()`.1619*/1620typedef int (*nghttp2_on_stream_close_callback)(nghttp2_session *session,1621int32_t stream_id,1622uint32_t error_code,1623void *user_data);16241625/**1626* @functypedef1627*1628* Callback function invoked when the reception of header block in1629* HEADERS or PUSH_PROMISE is started. Each header name/value pair1630* will be emitted by :type:`nghttp2_on_header_callback`.1631*1632* The ``frame->hd.flags`` may not have1633* :enum:`nghttp2_flag.NGHTTP2_FLAG_END_HEADERS` flag set, which1634* indicates that one or more CONTINUATION frames are involved. But1635* the application does not need to care about that because the header1636* name/value pairs are emitted transparently regardless of1637* CONTINUATION frames.1638*1639* The server applications probably create an object to store1640* information about new stream if ``frame->hd.type ==1641* NGHTTP2_HEADERS`` and ``frame->headers.cat ==1642* NGHTTP2_HCAT_REQUEST``. If |session| is configured as server side,1643* ``frame->headers.cat`` is either ``NGHTTP2_HCAT_REQUEST``1644* containing request headers or ``NGHTTP2_HCAT_HEADERS`` containing1645* trailer fields and never get PUSH_PROMISE in this callback.1646*1647* For the client applications, ``frame->hd.type`` is either1648* ``NGHTTP2_HEADERS`` or ``NGHTTP2_PUSH_PROMISE``. In case of1649* ``NGHTTP2_HEADERS``, ``frame->headers.cat ==1650* NGHTTP2_HCAT_RESPONSE`` means that it is the first response1651* headers, but it may be non-final response which is indicated by 1xx1652* status code. In this case, there may be zero or more HEADERS frame1653* with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` which has1654* non-final response code and finally client gets exactly one HEADERS1655* frame with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS``1656* containing final response headers (non-1xx status code). The1657* trailer fields also has ``frame->headers.cat ==1658* NGHTTP2_HCAT_HEADERS`` which does not contain any status code.1659*1660* Returning1661* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will1662* close the stream (promised stream if frame is PUSH_PROMISE) by1663* issuing RST_STREAM with1664* :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. In this case,1665* :type:`nghttp2_on_header_callback` and1666* :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a1667* different error code is desirable, use1668* `nghttp2_submit_rst_stream()` with a desired error code and then1669* return :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.1670* Again, use ``frame->push_promise.promised_stream_id`` as stream_id1671* parameter in `nghttp2_submit_rst_stream()` if frame is1672* PUSH_PROMISE.1673*1674* The implementation of this function must return 0 if it succeeds.1675* It can return1676* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` to1677* reset the stream (promised stream if frame is PUSH_PROMISE). For1678* critical errors, it must return1679* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other1680* value is returned, it is treated as if1681* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned. If1682* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned,1683* `nghttp2_session_mem_recv()` function will immediately return1684* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1685*1686* To set this callback to :type:`nghttp2_session_callbacks`, use1687* `nghttp2_session_callbacks_set_on_begin_headers_callback()`.1688*/1689typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session,1690const nghttp2_frame *frame,1691void *user_data);16921693/**1694* @functypedef1695*1696* Callback function invoked when a header name/value pair is received1697* for the |frame|. The |name| of length |namelen| is header name.1698* The |value| of length |valuelen| is header value. The |flags| is1699* bitwise OR of one or more of :type:`nghttp2_nv_flag`.1700*1701* If :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_INDEX` is set in1702* |flags|, the receiver must not index this name/value pair when1703* forwarding it to the next hop. More specifically, "Literal Header1704* Field never Indexed" representation must be used in HPACK encoding.1705*1706* When this callback is invoked, ``frame->hd.type`` is either1707* :enum:`nghttp2_frame_type.NGHTTP2_HEADERS` or1708* :enum:`nghttp2_frame_type.NGHTTP2_PUSH_PROMISE`. After all header1709* name/value pairs are processed with this callback, and no error has1710* been detected, :type:`nghttp2_on_frame_recv_callback` will be1711* invoked. If there is an error in decompression,1712* :type:`nghttp2_on_frame_recv_callback` for the |frame| will not be1713* invoked.1714*1715* Both |name| and |value| are guaranteed to be NULL-terminated. The1716* |namelen| and |valuelen| do not include terminal NULL. If1717* `nghttp2_option_set_no_http_messaging()` is used with nonzero1718* value, NULL character may be included in |name| or |value| before1719* terminating NULL.1720*1721* Please note that unless `nghttp2_option_set_no_http_messaging()` is1722* used, nghttp2 library does perform validation against the |name|1723* and the |value| using `nghttp2_check_header_name()` and1724* `nghttp2_check_header_value()`. In addition to this, nghttp21725* performs validation based on HTTP Messaging rule, which is briefly1726* explained in :ref:`http-messaging` section.1727*1728* If the application uses `nghttp2_session_mem_recv()`, it can return1729* :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make1730* `nghttp2_session_mem_recv()` return without processing further1731* input bytes. The memory pointed by |frame|, |name| and |value|1732* parameters are retained until `nghttp2_session_mem_recv()` or1733* `nghttp2_session_recv()` is called. The application must retain1734* the input bytes which was used to produce these parameters, because1735* it may refer to the memory region included in the input bytes.1736*1737* Returning1738* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will1739* close the stream (promised stream if frame is PUSH_PROMISE) by1740* issuing RST_STREAM with1741* :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. In this case,1742* :type:`nghttp2_on_header_callback` and1743* :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a1744* different error code is desirable, use1745* `nghttp2_submit_rst_stream()` with a desired error code and then1746* return :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.1747* Again, use ``frame->push_promise.promised_stream_id`` as stream_id1748* parameter in `nghttp2_submit_rst_stream()` if frame is1749* PUSH_PROMISE.1750*1751* The implementation of this function must return 0 if it succeeds.1752* It may return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` or1753* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. For1754* other critical failures, it must return1755* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other1756* nonzero value is returned, it is treated as1757* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If1758* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned,1759* `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions1760* immediately return1761* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1762*1763* To set this callback to :type:`nghttp2_session_callbacks`, use1764* `nghttp2_session_callbacks_set_on_header_callback()`.1765*1766* .. warning::1767*1768* Application should properly limit the total buffer size to store1769* incoming header fields. Without it, peer may send large number1770* of header fields or large header fields to cause out of memory in1771* local endpoint. Due to how HPACK works, peer can do this1772* effectively without using much memory on their own.1773*/1774typedef int (*nghttp2_on_header_callback)(nghttp2_session *session,1775const nghttp2_frame *frame,1776const uint8_t *name, size_t namelen,1777const uint8_t *value, size_t valuelen,1778uint8_t flags, void *user_data);17791780/**1781* @functypedef1782*1783* Callback function invoked when a header name/value pair is received1784* for the |frame|. The |name| is header name. The |value| is header1785* value. The |flags| is bitwise OR of one or more of1786* :type:`nghttp2_nv_flag`.1787*1788* This callback behaves like :type:`nghttp2_on_header_callback`,1789* except that |name| and |value| are stored in reference counted1790* buffer. If application wishes to keep these references without1791* copying them, use `nghttp2_rcbuf_incref()` to increment their1792* reference count. It is the application's responsibility to call1793* `nghttp2_rcbuf_decref()` if they called `nghttp2_rcbuf_incref()` so1794* as not to leak memory. If the |session| is created by1795* `nghttp2_session_server_new3()` or `nghttp2_session_client_new3()`,1796* the function to free memory is the one belongs to the mem1797* parameter. As long as this free function alives, |name| and1798* |value| can live after |session| was destroyed.1799*/1800typedef int (*nghttp2_on_header_callback2)(nghttp2_session *session,1801const nghttp2_frame *frame,1802nghttp2_rcbuf *name,1803nghttp2_rcbuf *value, uint8_t flags,1804void *user_data);18051806/**1807* @functypedef1808*1809* Callback function invoked when a invalid header name/value pair is1810* received for the |frame|.1811*1812* The parameter and behaviour are similar to1813* :type:`nghttp2_on_header_callback`. The difference is that this1814* callback is only invoked when a invalid header name/value pair is1815* received which is treated as stream error if this callback is not1816* set. Only invalid regular header field are passed to this1817* callback. In other words, invalid pseudo header field is not1818* passed to this callback. Also header fields which includes upper1819* cased latter are also treated as error without passing them to this1820* callback.1821*1822* This callback is only considered if HTTP messaging validation is1823* turned on (which is on by default, see1824* `nghttp2_option_set_no_http_messaging()`).1825*1826* With this callback, application inspects the incoming invalid1827* field, and it also can reset stream from this callback by returning1828* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. By1829* default, the error code is1830* :enum:`nghttp2_error_code.NGHTTP2_PROTOCOL_ERROR`. To change the1831* error code, call `nghttp2_submit_rst_stream()` with the error code1832* of choice in addition to returning1833* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.1834*1835* If 0 is returned, the header field is ignored, and the stream is1836* not reset.1837*/1838typedef int (*nghttp2_on_invalid_header_callback)(1839nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name,1840size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags,1841void *user_data);18421843/**1844* @functypedef1845*1846* Callback function invoked when a invalid header name/value pair is1847* received for the |frame|.1848*1849* The parameter and behaviour are similar to1850* :type:`nghttp2_on_header_callback2`. The difference is that this1851* callback is only invoked when a invalid header name/value pair is1852* received which is silently ignored if this callback is not set.1853* Only invalid regular header field are passed to this callback. In1854* other words, invalid pseudo header field is not passed to this1855* callback. Also header fields which includes upper cased latter are1856* also treated as error without passing them to this callback.1857*1858* This callback is only considered if HTTP messaging validation is1859* turned on (which is on by default, see1860* `nghttp2_option_set_no_http_messaging()`).1861*1862* With this callback, application inspects the incoming invalid1863* field, and it also can reset stream from this callback by returning1864* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. By1865* default, the error code is1866* :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. To change the1867* error code, call `nghttp2_submit_rst_stream()` with the error code1868* of choice in addition to returning1869* :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.1870*/1871typedef int (*nghttp2_on_invalid_header_callback2)(1872nghttp2_session *session, const nghttp2_frame *frame, nghttp2_rcbuf *name,1873nghttp2_rcbuf *value, uint8_t flags, void *user_data);18741875/**1876* @functypedef1877*1878* Callback function invoked when the library asks application how1879* many padding bytes are required for the transmission of the1880* |frame|. The application must choose the total length of payload1881* including padded bytes in range [frame->hd.length, max_payloadlen],1882* inclusive. Choosing number not in this range will be treated as1883* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Returning1884* ``frame->hd.length`` means no padding is added. Returning1885* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will make1886* `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions1887* immediately return1888* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1889*1890* To set this callback to :type:`nghttp2_session_callbacks`, use1891* `nghttp2_session_callbacks_set_select_padding_callback()`.1892*/1893typedef ssize_t (*nghttp2_select_padding_callback)(nghttp2_session *session,1894const nghttp2_frame *frame,1895size_t max_payloadlen,1896void *user_data);18971898/**1899* @functypedef1900*1901* Callback function invoked when library wants to get max length of1902* data to send data to the remote peer. The implementation of this1903* function should return a value in the following range. [1,1904* min(|session_remote_window_size|, |stream_remote_window_size|,1905* |remote_max_frame_size|)]. If a value greater than this range is1906* returned than the max allow value will be used. Returning a value1907* smaller than this range is treated as1908* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The1909* |frame_type| is provided for future extensibility and identifies1910* the type of frame (see :type:`nghttp2_frame_type`) for which to get1911* the length for. Currently supported frame types are:1912* :enum:`nghttp2_frame_type.NGHTTP2_DATA`.1913*1914* This callback can be used to control the length in bytes for which1915* :type:`nghttp2_data_source_read_callback` is allowed to send to the1916* remote endpoint. This callback is optional. Returning1917* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will signal the1918* entire session failure.1919*1920* To set this callback to :type:`nghttp2_session_callbacks`, use1921* `nghttp2_session_callbacks_set_data_source_read_length_callback()`.1922*/1923typedef ssize_t (*nghttp2_data_source_read_length_callback)(1924nghttp2_session *session, uint8_t frame_type, int32_t stream_id,1925int32_t session_remote_window_size, int32_t stream_remote_window_size,1926uint32_t remote_max_frame_size, void *user_data);19271928/**1929* @functypedef1930*1931* Callback function invoked when a frame header is received. The1932* |hd| points to received frame header.1933*1934* Unlike :type:`nghttp2_on_frame_recv_callback`, this callback will1935* also be called when frame header of CONTINUATION frame is received.1936*1937* If both :type:`nghttp2_on_begin_frame_callback` and1938* :type:`nghttp2_on_begin_headers_callback` are set and HEADERS or1939* PUSH_PROMISE is received, :type:`nghttp2_on_begin_frame_callback`1940* will be called first.1941*1942* The implementation of this function must return 0 if it succeeds.1943* If nonzero value is returned, it is treated as fatal error and1944* `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions1945* immediately return1946* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1947*1948* To set this callback to :type:`nghttp2_session_callbacks`, use1949* `nghttp2_session_callbacks_set_on_begin_frame_callback()`.1950*/1951typedef int (*nghttp2_on_begin_frame_callback)(nghttp2_session *session,1952const nghttp2_frame_hd *hd,1953void *user_data);19541955/**1956* @functypedef1957*1958* Callback function invoked when chunk of extension frame payload is1959* received. The |hd| points to frame header. The received1960* chunk is |data| of length |len|.1961*1962* The implementation of this function must return 0 if it succeeds.1963*1964* To abort processing this extension frame, return1965* :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`.1966*1967* If fatal error occurred, application should return1968* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,1969* `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions1970* immediately return1971* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other1972* values are returned, currently they are treated as1973* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.1974*/1975typedef int (*nghttp2_on_extension_chunk_recv_callback)(1976nghttp2_session *session, const nghttp2_frame_hd *hd, const uint8_t *data,1977size_t len, void *user_data);19781979/**1980* @functypedef1981*1982* Callback function invoked when library asks the application to1983* unpack extension payload from its wire format. The extension1984* payload has been passed to the application using1985* :type:`nghttp2_on_extension_chunk_recv_callback`. The frame header1986* is already unpacked by the library and provided as |hd|.1987*1988* To receive extension frames, the application must tell desired1989* extension frame type to the library using1990* `nghttp2_option_set_user_recv_extension_type()`.1991*1992* The implementation of this function may store the pointer to the1993* created object as a result of unpacking in |*payload|, and returns1994* 0. The pointer stored in |*payload| is opaque to the library, and1995* the library does not own its pointer. |*payload| is initialized as1996* ``NULL``. The |*payload| is available as ``frame->ext.payload`` in1997* :type:`nghttp2_on_frame_recv_callback`. Therefore if application1998* can free that memory inside :type:`nghttp2_on_frame_recv_callback`1999* callback. Of course, application has a liberty not ot use2000* |*payload|, and do its own mechanism to process extension frames.2001*2002* To abort processing this extension frame, return2003* :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`.2004*2005* If fatal error occurred, application should return2006* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,2007* `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions2008* immediately return2009* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other2010* values are returned, currently they are treated as2011* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.2012*/2013typedef int (*nghttp2_unpack_extension_callback)(nghttp2_session *session,2014void **payload,2015const nghttp2_frame_hd *hd,2016void *user_data);20172018/**2019* @functypedef2020*2021* Callback function invoked when library asks the application to pack2022* extension payload in its wire format. The frame header will be2023* packed by library. Application must pack payload only.2024* ``frame->ext.payload`` is the object passed to2025* `nghttp2_submit_extension()` as payload parameter. Application2026* must pack extension payload to the |buf| of its capacity |len|2027* bytes. The |len| is at least 16KiB.2028*2029* The implementation of this function should return the number of2030* bytes written into |buf| when it succeeds.2031*2032* To abort processing this extension frame, return2033* :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`, and2034* :type:`nghttp2_on_frame_not_send_callback` will be invoked.2035*2036* If fatal error occurred, application should return2037* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case,2038* `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions2039* immediately return2040* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other2041* values are returned, currently they are treated as2042* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the return2043* value is strictly larger than |len|, it is treated as2044* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.2045*/2046typedef ssize_t (*nghttp2_pack_extension_callback)(nghttp2_session *session,2047uint8_t *buf, size_t len,2048const nghttp2_frame *frame,2049void *user_data);20502051/**2052* @functypedef2053*2054* Callback function invoked when library provides the error message2055* intended for human consumption. This callback is solely for2056* debugging purpose. The |msg| is typically NULL-terminated string2057* of length |len|. |len| does not include the sentinel NULL2058* character.2059*2060* This function is deprecated. The new application should use2061* :type:`nghttp2_error_callback2`.2062*2063* The format of error message may change between nghttp2 library2064* versions. The application should not depend on the particular2065* format.2066*2067* Normally, application should return 0 from this callback. If fatal2068* error occurred while doing something in this callback, application2069* should return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.2070* In this case, library will return immediately with return value2071* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if2072* nonzero value is returned from this callback, they are treated as2073* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, but application2074* should not rely on this details.2075*/2076typedef int (*nghttp2_error_callback)(nghttp2_session *session, const char *msg,2077size_t len, void *user_data);20782079/**2080* @functypedef2081*2082* Callback function invoked when library provides the error code, and2083* message. This callback is solely for debugging purpose.2084* |lib_error_code| is one of error code defined in2085* :enum:`nghttp2_error`. The |msg| is typically NULL-terminated2086* string of length |len|, and intended for human consumption. |len|2087* does not include the sentinel NULL character.2088*2089* The format of error message may change between nghttp2 library2090* versions. The application should not depend on the particular2091* format.2092*2093* Normally, application should return 0 from this callback. If fatal2094* error occurred while doing something in this callback, application2095* should return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.2096* In this case, library will return immediately with return value2097* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if2098* nonzero value is returned from this callback, they are treated as2099* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, but application2100* should not rely on this details.2101*/2102typedef int (*nghttp2_error_callback2)(nghttp2_session *session,2103int lib_error_code, const char *msg,2104size_t len, void *user_data);21052106struct nghttp2_session_callbacks;21072108/**2109* @struct2110*2111* Callback functions for :type:`nghttp2_session`. The details of2112* this structure are intentionally hidden from the public API.2113*/2114typedef struct nghttp2_session_callbacks nghttp2_session_callbacks;21152116/**2117* @function2118*2119* Initializes |*callbacks_ptr| with NULL values.2120*2121* The initialized object can be used when initializing multiple2122* :type:`nghttp2_session` objects.2123*2124* When the application finished using this object, it can use2125* `nghttp2_session_callbacks_del()` to free its memory.2126*2127* This function returns 0 if it succeeds, or one of the following2128* negative error codes:2129*2130* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`2131* Out of memory.2132*/2133NGHTTP2_EXTERN int2134nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr);21352136/**2137* @function2138*2139* Frees any resources allocated for |callbacks|. If |callbacks| is2140* ``NULL``, this function does nothing.2141*/2142NGHTTP2_EXTERN void2143nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks);21442145/**2146* @function2147*2148* Sets callback function invoked when a session wants to send data to2149* the remote peer. This callback is not necessary if the application2150* uses solely `nghttp2_session_mem_send()` to serialize data to2151* transmit.2152*/2153NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback(2154nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback);21552156/**2157* @function2158*2159* Sets callback function invoked when the a session wants to receive2160* data from the remote peer. This callback is not necessary if the2161* application uses solely `nghttp2_session_mem_recv()` to process2162* received data.2163*/2164NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback(2165nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback);21662167/**2168* @function2169*2170* Sets callback function invoked by `nghttp2_session_recv()` and2171* `nghttp2_session_mem_recv()` when a frame is received.2172*/2173NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback(2174nghttp2_session_callbacks *cbs,2175nghttp2_on_frame_recv_callback on_frame_recv_callback);21762177/**2178* @function2179*2180* Sets callback function invoked by `nghttp2_session_recv()` and2181* `nghttp2_session_mem_recv()` when an invalid non-DATA frame is2182* received.2183*/2184NGHTTP2_EXTERN void2185nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(2186nghttp2_session_callbacks *cbs,2187nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback);21882189/**2190* @function2191*2192* Sets callback function invoked when a chunk of data in DATA frame2193* is received.2194*/2195NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_data_chunk_recv_callback(2196nghttp2_session_callbacks *cbs,2197nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback);21982199/**2200* @function2201*2202* Sets callback function invoked before a non-DATA frame is sent.2203*/2204NGHTTP2_EXTERN void nghttp2_session_callbacks_set_before_frame_send_callback(2205nghttp2_session_callbacks *cbs,2206nghttp2_before_frame_send_callback before_frame_send_callback);22072208/**2209* @function2210*2211* Sets callback function invoked after a frame is sent.2212*/2213NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_send_callback(2214nghttp2_session_callbacks *cbs,2215nghttp2_on_frame_send_callback on_frame_send_callback);22162217/**2218* @function2219*2220* Sets callback function invoked when a non-DATA frame is not sent2221* because of an error.2222*/2223NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_not_send_callback(2224nghttp2_session_callbacks *cbs,2225nghttp2_on_frame_not_send_callback on_frame_not_send_callback);22262227/**2228* @function2229*2230* Sets callback function invoked when the stream is closed.2231*/2232NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_stream_close_callback(2233nghttp2_session_callbacks *cbs,2234nghttp2_on_stream_close_callback on_stream_close_callback);22352236/**2237* @function2238*2239* Sets callback function invoked when the reception of header block2240* in HEADERS or PUSH_PROMISE is started.2241*/2242NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_headers_callback(2243nghttp2_session_callbacks *cbs,2244nghttp2_on_begin_headers_callback on_begin_headers_callback);22452246/**2247* @function2248*2249* Sets callback function invoked when a header name/value pair is2250* received. If both2251* `nghttp2_session_callbacks_set_on_header_callback()` and2252* `nghttp2_session_callbacks_set_on_header_callback2()` are used to2253* set callbacks, the latter has the precedence.2254*/2255NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback(2256nghttp2_session_callbacks *cbs,2257nghttp2_on_header_callback on_header_callback);22582259/**2260* @function2261*2262* Sets callback function invoked when a header name/value pair is2263* received.2264*/2265NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback2(2266nghttp2_session_callbacks *cbs,2267nghttp2_on_header_callback2 on_header_callback2);22682269/**2270* @function2271*2272* Sets callback function invoked when a invalid header name/value2273* pair is received. If both2274* `nghttp2_session_callbacks_set_on_invalid_header_callback()` and2275* `nghttp2_session_callbacks_set_on_invalid_header_callback2()` are2276* used to set callbacks, the latter takes the precedence.2277*/2278NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback(2279nghttp2_session_callbacks *cbs,2280nghttp2_on_invalid_header_callback on_invalid_header_callback);22812282/**2283* @function2284*2285* Sets callback function invoked when a invalid header name/value2286* pair is received.2287*/2288NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback2(2289nghttp2_session_callbacks *cbs,2290nghttp2_on_invalid_header_callback2 on_invalid_header_callback2);22912292/**2293* @function2294*2295* Sets callback function invoked when the library asks application2296* how many padding bytes are required for the transmission of the2297* given frame.2298*/2299NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback(2300nghttp2_session_callbacks *cbs,2301nghttp2_select_padding_callback select_padding_callback);23022303/**2304* @function2305*2306* Sets callback function determine the length allowed in2307* :type:`nghttp2_data_source_read_callback`.2308*/2309NGHTTP2_EXTERN void2310nghttp2_session_callbacks_set_data_source_read_length_callback(2311nghttp2_session_callbacks *cbs,2312nghttp2_data_source_read_length_callback data_source_read_length_callback);23132314/**2315* @function2316*2317* Sets callback function invoked when a frame header is received.2318*/2319NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_frame_callback(2320nghttp2_session_callbacks *cbs,2321nghttp2_on_begin_frame_callback on_begin_frame_callback);23222323/**2324* @function2325*2326* Sets callback function invoked when2327* :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` is used in2328* :type:`nghttp2_data_source_read_callback` to avoid data copy.2329*/2330NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_data_callback(2331nghttp2_session_callbacks *cbs,2332nghttp2_send_data_callback send_data_callback);23332334/**2335* @function2336*2337* Sets callback function invoked when the library asks the2338* application to pack extension frame payload in wire format.2339*/2340NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback(2341nghttp2_session_callbacks *cbs,2342nghttp2_pack_extension_callback pack_extension_callback);23432344/**2345* @function2346*2347* Sets callback function invoked when the library asks the2348* application to unpack extension frame payload from wire format.2349*/2350NGHTTP2_EXTERN void nghttp2_session_callbacks_set_unpack_extension_callback(2351nghttp2_session_callbacks *cbs,2352nghttp2_unpack_extension_callback unpack_extension_callback);23532354/**2355* @function2356*2357* Sets callback function invoked when chunk of extension frame2358* payload is received.2359*/2360NGHTTP2_EXTERN void2361nghttp2_session_callbacks_set_on_extension_chunk_recv_callback(2362nghttp2_session_callbacks *cbs,2363nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback);23642365/**2366* @function2367*2368* Sets callback function invoked when library tells error message to2369* the application.2370*2371* This function is deprecated. The new application should use2372* `nghttp2_session_callbacks_set_error_callback2()`.2373*2374* If both :type:`nghttp2_error_callback` and2375* :type:`nghttp2_error_callback2` are set, the latter takes2376* precedence.2377*/2378NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback(2379nghttp2_session_callbacks *cbs, nghttp2_error_callback error_callback);23802381/**2382* @function2383*2384* Sets callback function invoked when library tells error code, and2385* message to the application.2386*2387* If both :type:`nghttp2_error_callback` and2388* :type:`nghttp2_error_callback2` are set, the latter takes2389* precedence.2390*/2391NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback2(2392nghttp2_session_callbacks *cbs, nghttp2_error_callback2 error_callback2);23932394/**2395* @functypedef2396*2397* Custom memory allocator to replace malloc(). The |mem_user_data|2398* is the mem_user_data member of :type:`nghttp2_mem` structure.2399*/2400typedef void *(*nghttp2_malloc)(size_t size, void *mem_user_data);24012402/**2403* @functypedef2404*2405* Custom memory allocator to replace free(). The |mem_user_data| is2406* the mem_user_data member of :type:`nghttp2_mem` structure.2407*/2408typedef void (*nghttp2_free)(void *ptr, void *mem_user_data);24092410/**2411* @functypedef2412*2413* Custom memory allocator to replace calloc(). The |mem_user_data|2414* is the mem_user_data member of :type:`nghttp2_mem` structure.2415*/2416typedef void *(*nghttp2_calloc)(size_t nmemb, size_t size, void *mem_user_data);24172418/**2419* @functypedef2420*2421* Custom memory allocator to replace realloc(). The |mem_user_data|2422* is the mem_user_data member of :type:`nghttp2_mem` structure.2423*/2424typedef void *(*nghttp2_realloc)(void *ptr, size_t size, void *mem_user_data);24252426/**2427* @struct2428*2429* Custom memory allocator functions and user defined pointer. The2430* |mem_user_data| member is passed to each allocator function. This2431* can be used, for example, to achieve per-session memory pool.2432*2433* In the following example code, ``my_malloc``, ``my_free``,2434* ``my_calloc`` and ``my_realloc`` are the replacement of the2435* standard allocators ``malloc``, ``free``, ``calloc`` and2436* ``realloc`` respectively::2437*2438* void *my_malloc_cb(size_t size, void *mem_user_data) {2439* return my_malloc(size);2440* }2441*2442* void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); }2443*2444* void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) {2445* return my_calloc(nmemb, size);2446* }2447*2448* void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) {2449* return my_realloc(ptr, size);2450* }2451*2452* void session_new() {2453* nghttp2_session *session;2454* nghttp2_session_callbacks *callbacks;2455* nghttp2_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb,2456* my_realloc_cb};2457*2458* ...2459*2460* nghttp2_session_client_new3(&session, callbacks, NULL, NULL, &mem);2461*2462* ...2463* }2464*/2465typedef struct {2466/**2467* An arbitrary user supplied data. This is passed to each2468* allocator function.2469*/2470void *mem_user_data;2471/**2472* Custom allocator function to replace malloc().2473*/2474nghttp2_malloc malloc;2475/**2476* Custom allocator function to replace free().2477*/2478nghttp2_free free;2479/**2480* Custom allocator function to replace calloc().2481*/2482nghttp2_calloc calloc;2483/**2484* Custom allocator function to replace realloc().2485*/2486nghttp2_realloc realloc;2487} nghttp2_mem;24882489struct nghttp2_option;24902491/**2492* @struct2493*2494* Configuration options for :type:`nghttp2_session`. The details of2495* this structure are intentionally hidden from the public API.2496*/2497typedef struct nghttp2_option nghttp2_option;24982499/**2500* @function2501*2502* Initializes |*option_ptr| with default values.2503*2504* When the application finished using this object, it can use2505* `nghttp2_option_del()` to free its memory.2506*2507* This function returns 0 if it succeeds, or one of the following2508* negative error codes:2509*2510* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`2511* Out of memory.2512*/2513NGHTTP2_EXTERN int nghttp2_option_new(nghttp2_option **option_ptr);25142515/**2516* @function2517*2518* Frees any resources allocated for |option|. If |option| is2519* ``NULL``, this function does nothing.2520*/2521NGHTTP2_EXTERN void nghttp2_option_del(nghttp2_option *option);25222523/**2524* @function2525*2526* This option prevents the library from sending WINDOW_UPDATE for a2527* connection automatically. If this option is set to nonzero, the2528* library won't send WINDOW_UPDATE for DATA until application calls2529* `nghttp2_session_consume()` to indicate the consumed amount of2530* data. Don't use `nghttp2_submit_window_update()` for this purpose.2531* By default, this option is set to zero.2532*/2533NGHTTP2_EXTERN void2534nghttp2_option_set_no_auto_window_update(nghttp2_option *option, int val);25352536/**2537* @function2538*2539* This option sets the SETTINGS_MAX_CONCURRENT_STREAMS value of2540* remote endpoint as if it is received in SETTINGS frame. Without2541* specifying this option, the maximum number of outgoing concurrent2542* streams is initially limited to 100 to avoid issues when the local2543* endpoint submits lots of requests before receiving initial SETTINGS2544* frame from the remote endpoint, since sending them at once to the2545* remote endpoint could lead to rejection of some of the requests.2546* This value will be overwritten when the local endpoint receives2547* initial SETTINGS frame from the remote endpoint, either to the2548* value advertised in SETTINGS_MAX_CONCURRENT_STREAMS or to the2549* default value (unlimited) if none was advertised.2550*/2551NGHTTP2_EXTERN void2552nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option,2553uint32_t val);25542555/**2556* @function2557*2558* By default, nghttp2 library, if configured as server, requires2559* first 24 bytes of client magic byte string (MAGIC). In most cases,2560* this will simplify the implementation of server. But sometimes2561* server may want to detect the application protocol based on first2562* few bytes on clear text communication.2563*2564* If this option is used with nonzero |val|, nghttp2 library does not2565* handle MAGIC. It still checks following SETTINGS frame. This2566* means that applications should deal with MAGIC by themselves.2567*2568* If this option is not used or used with zero value, if MAGIC does2569* not match :macro:`NGHTTP2_CLIENT_MAGIC`, `nghttp2_session_recv()`2570* and `nghttp2_session_mem_recv()` will return error2571* :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`, which is fatal2572* error.2573*/2574NGHTTP2_EXTERN void2575nghttp2_option_set_no_recv_client_magic(nghttp2_option *option, int val);25762577/**2578* @function2579*2580* By default, nghttp2 library enforces subset of HTTP Messaging rules2581* described in `HTTP/2 specification, section 82582* <https://tools.ietf.org/html/rfc7540#section-8>`_. See2583* :ref:`http-messaging` section for details. For those applications2584* who use nghttp2 library as non-HTTP use, give nonzero to |val| to2585* disable this enforcement. Please note that disabling this feature2586* does not change the fundamental client and server model of HTTP.2587* That is, even if the validation is disabled, only client can send2588* requests.2589*/2590NGHTTP2_EXTERN void nghttp2_option_set_no_http_messaging(nghttp2_option *option,2591int val);25922593/**2594* @function2595*2596* RFC 7540 does not enforce any limit on the number of incoming2597* reserved streams (in RFC 7540 terms, streams in reserved (remote)2598* state). This only affects client side, since only server can push2599* streams. Malicious server can push arbitrary number of streams,2600* and make client's memory exhausted. This option can set the2601* maximum number of such incoming streams to avoid possible memory2602* exhaustion. If this option is set, and pushed streams are2603* automatically closed on reception, without calling user provided2604* callback, if they exceed the given limit. The default value is2605* 200. If session is configured as server side, this option has no2606* effect. Server can control the number of streams to push.2607*/2608NGHTTP2_EXTERN void2609nghttp2_option_set_max_reserved_remote_streams(nghttp2_option *option,2610uint32_t val);26112612/**2613* @function2614*2615* Sets extension frame type the application is willing to handle with2616* user defined callbacks (see2617* :type:`nghttp2_on_extension_chunk_recv_callback` and2618* :type:`nghttp2_unpack_extension_callback`). The |type| is2619* extension frame type, and must be strictly greater than 0x9.2620* Otherwise, this function does nothing. The application can call2621* this function multiple times to set more than one frame type to2622* receive. The application does not have to call this function if it2623* just sends extension frames.2624*/2625NGHTTP2_EXTERN void2626nghttp2_option_set_user_recv_extension_type(nghttp2_option *option,2627uint8_t type);26282629/**2630* @function2631*2632* Sets extension frame type the application is willing to receive2633* using builtin handler. The |type| is the extension frame type to2634* receive, and must be strictly greater than 0x9. Otherwise, this2635* function does nothing. The application can call this function2636* multiple times to set more than one frame type to receive. The2637* application does not have to call this function if it just sends2638* extension frames.2639*2640* If same frame type is passed to both2641* `nghttp2_option_set_builtin_recv_extension_type()` and2642* `nghttp2_option_set_user_recv_extension_type()`, the latter takes2643* precedence.2644*/2645NGHTTP2_EXTERN void2646nghttp2_option_set_builtin_recv_extension_type(nghttp2_option *option,2647uint8_t type);26482649/**2650* @function2651*2652* This option prevents the library from sending PING frame with ACK2653* flag set automatically when PING frame without ACK flag set is2654* received. If this option is set to nonzero, the library won't send2655* PING frame with ACK flag set in the response for incoming PING2656* frame. The application can send PING frame with ACK flag set using2657* `nghttp2_submit_ping()` with :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK`2658* as flags parameter.2659*/2660NGHTTP2_EXTERN void nghttp2_option_set_no_auto_ping_ack(nghttp2_option *option,2661int val);26622663/**2664* @function2665*2666* This option sets the maximum length of header block (a set of2667* header fields per one HEADERS frame) to send. The length of a2668* given set of header fields is calculated using2669* `nghttp2_hd_deflate_bound()`. The default value is 64KiB. If2670* application attempts to send header fields larger than this limit,2671* the transmission of the frame fails with error code2672* :enum:`nghttp2_error.NGHTTP2_ERR_FRAME_SIZE_ERROR`.2673*/2674NGHTTP2_EXTERN void2675nghttp2_option_set_max_send_header_block_length(nghttp2_option *option,2676size_t val);26772678/**2679* @function2680*2681* This option sets the maximum dynamic table size for deflating2682* header fields. The default value is 4KiB. In HTTP/2, receiver of2683* deflated header block can specify maximum dynamic table size. The2684* actual maximum size is the minimum of the size receiver specified2685* and this option value.2686*/2687NGHTTP2_EXTERN void2688nghttp2_option_set_max_deflate_dynamic_table_size(nghttp2_option *option,2689size_t val);26902691/**2692* @function2693*2694* This option prevents the library from retaining closed streams to2695* maintain the priority tree. If this option is set to nonzero,2696* applications can discard closed stream completely to save memory.2697*2698* If2699* :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`2700* of value of 1 is submitted via `nghttp2_submit_settings()`, any2701* closed streams are not retained regardless of this option.2702*/2703NGHTTP2_EXTERN void nghttp2_option_set_no_closed_streams(nghttp2_option *option,2704int val);27052706/**2707* @function2708*2709* This function sets the maximum number of outgoing SETTINGS ACK and2710* PING ACK frames retained in :type:`nghttp2_session` object. If2711* more than those frames are retained, the peer is considered to be2712* misbehaving and session will be closed. The default value is 1000.2713*/2714NGHTTP2_EXTERN void nghttp2_option_set_max_outbound_ack(nghttp2_option *option,2715size_t val);27162717/**2718* @function2719*2720* This function sets the maximum number of SETTINGS entries per2721* SETTINGS frame that will be accepted. If more than those entries2722* are received, the peer is considered to be misbehaving and session2723* will be closed. The default value is 32.2724*/2725NGHTTP2_EXTERN void nghttp2_option_set_max_settings(nghttp2_option *option,2726size_t val);27272728/**2729* @function2730*2731* This option, if set to nonzero, allows server to fallback to2732* :rfc:`7540` priorities if SETTINGS_NO_RFC7540_PRIORITIES was not2733* received from client, and server submitted2734* :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`2735* = 1 via `nghttp2_submit_settings()`. Most of the advanced2736* functionality for RFC 7540 priorities are still disabled. This2737* fallback only enables the minimal feature set of RFC 75402738* priorities to deal with priority signaling from client.2739*2740* Client session ignores this option.2741*/2742NGHTTP2_EXTERN void2743nghttp2_option_set_server_fallback_rfc7540_priorities(nghttp2_option *option,2744int val);27452746/**2747* @function2748*2749* This option, if set to nonzero, turns off RFC 9113 leading and2750* trailing white spaces validation against HTTP field value. Some2751* important fields, such as HTTP/2 pseudo header fields, are2752* validated more strictly and this option does not apply to them.2753*/2754NGHTTP2_EXTERN void2755nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation(2756nghttp2_option *option, int val);27572758/**2759* @function2760*2761* Initializes |*session_ptr| for client use. The all members of2762* |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|2763* does not store |callbacks|. The |user_data| is an arbitrary user2764* supplied data, which will be passed to the callback functions.2765*2766* The :type:`nghttp2_send_callback` must be specified. If the2767* application code uses `nghttp2_session_recv()`, the2768* :type:`nghttp2_recv_callback` must be specified. The other members2769* of |callbacks| can be ``NULL``.2770*2771* If this function fails, |*session_ptr| is left untouched.2772*2773* This function returns 0 if it succeeds, or one of the following2774* negative error codes:2775*2776* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`2777* Out of memory.2778*/2779NGHTTP2_EXTERN int2780nghttp2_session_client_new(nghttp2_session **session_ptr,2781const nghttp2_session_callbacks *callbacks,2782void *user_data);27832784/**2785* @function2786*2787* Initializes |*session_ptr| for server use. The all members of2788* |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|2789* does not store |callbacks|. The |user_data| is an arbitrary user2790* supplied data, which will be passed to the callback functions.2791*2792* The :type:`nghttp2_send_callback` must be specified. If the2793* application code uses `nghttp2_session_recv()`, the2794* :type:`nghttp2_recv_callback` must be specified. The other members2795* of |callbacks| can be ``NULL``.2796*2797* If this function fails, |*session_ptr| is left untouched.2798*2799* This function returns 0 if it succeeds, or one of the following2800* negative error codes:2801*2802* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`2803* Out of memory.2804*/2805NGHTTP2_EXTERN int2806nghttp2_session_server_new(nghttp2_session **session_ptr,2807const nghttp2_session_callbacks *callbacks,2808void *user_data);28092810/**2811* @function2812*2813* Like `nghttp2_session_client_new()`, but with additional options2814* specified in the |option|.2815*2816* The |option| can be ``NULL`` and the call is equivalent to2817* `nghttp2_session_client_new()`.2818*2819* This function does not take ownership |option|. The application is2820* responsible for freeing |option| if it finishes using the object.2821*2822* The library code does not refer to |option| after this function2823* returns.2824*2825* This function returns 0 if it succeeds, or one of the following2826* negative error codes:2827*2828* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`2829* Out of memory.2830*/2831NGHTTP2_EXTERN int2832nghttp2_session_client_new2(nghttp2_session **session_ptr,2833const nghttp2_session_callbacks *callbacks,2834void *user_data, const nghttp2_option *option);28352836/**2837* @function2838*2839* Like `nghttp2_session_server_new()`, but with additional options2840* specified in the |option|.2841*2842* The |option| can be ``NULL`` and the call is equivalent to2843* `nghttp2_session_server_new()`.2844*2845* This function does not take ownership |option|. The application is2846* responsible for freeing |option| if it finishes using the object.2847*2848* The library code does not refer to |option| after this function2849* returns.2850*2851* This function returns 0 if it succeeds, or one of the following2852* negative error codes:2853*2854* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`2855* Out of memory.2856*/2857NGHTTP2_EXTERN int2858nghttp2_session_server_new2(nghttp2_session **session_ptr,2859const nghttp2_session_callbacks *callbacks,2860void *user_data, const nghttp2_option *option);28612862/**2863* @function2864*2865* Like `nghttp2_session_client_new2()`, but with additional custom2866* memory allocator specified in the |mem|.2867*2868* The |mem| can be ``NULL`` and the call is equivalent to2869* `nghttp2_session_client_new2()`.2870*2871* This function does not take ownership |mem|. The application is2872* responsible for freeing |mem|.2873*2874* The library code does not refer to |mem| pointer after this2875* function returns, so the application can safely free it.2876*2877* This function returns 0 if it succeeds, or one of the following2878* negative error codes:2879*2880* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`2881* Out of memory.2882*/2883NGHTTP2_EXTERN int nghttp2_session_client_new3(2884nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,2885void *user_data, const nghttp2_option *option, nghttp2_mem *mem);28862887/**2888* @function2889*2890* Like `nghttp2_session_server_new2()`, but with additional custom2891* memory allocator specified in the |mem|.2892*2893* The |mem| can be ``NULL`` and the call is equivalent to2894* `nghttp2_session_server_new2()`.2895*2896* This function does not take ownership |mem|. The application is2897* responsible for freeing |mem|.2898*2899* The library code does not refer to |mem| pointer after this2900* function returns, so the application can safely free it.2901*2902* This function returns 0 if it succeeds, or one of the following2903* negative error codes:2904*2905* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`2906* Out of memory.2907*/2908NGHTTP2_EXTERN int nghttp2_session_server_new3(2909nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,2910void *user_data, const nghttp2_option *option, nghttp2_mem *mem);29112912/**2913* @function2914*2915* Frees any resources allocated for |session|. If |session| is2916* ``NULL``, this function does nothing.2917*/2918NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session);29192920/**2921* @function2922*2923* Sends pending frames to the remote peer.2924*2925* This function retrieves the highest prioritized frame from the2926* outbound queue and sends it to the remote peer. It does this as2927* many times as possible until the user callback2928* :type:`nghttp2_send_callback` returns2929* :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`, the outbound queue2930* becomes empty or flow control is triggered (remote window size2931* becomes depleted or maximum number of concurrent streams is2932* reached). This function calls several callback functions which are2933* passed when initializing the |session|. Here is the simple time2934* chart which tells when each callback is invoked:2935*2936* 1. Get the next frame to send from outbound queue.2937*2938* 2. Prepare transmission of the frame.2939*2940* 3. If the control frame cannot be sent because some preconditions2941* are not met (e.g., request HEADERS cannot be sent after GOAWAY),2942* :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort2943* the following steps.2944*2945* 4. If the frame is HEADERS, PUSH_PROMISE or DATA,2946* :type:`nghttp2_select_padding_callback` is invoked.2947*2948* 5. If the frame is request HEADERS, the stream is opened here.2949*2950* 6. :type:`nghttp2_before_frame_send_callback` is invoked.2951*2952* 7. If :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL` is returned from2953* :type:`nghttp2_before_frame_send_callback`, the current frame2954* transmission is canceled, and2955* :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort2956* the following steps.2957*2958* 8. :type:`nghttp2_send_callback` is invoked one or more times to2959* send the frame.2960*2961* 9. :type:`nghttp2_on_frame_send_callback` is invoked.2962*2963* 10. If the transmission of the frame triggers closure of the2964* stream, the stream is closed and2965* :type:`nghttp2_on_stream_close_callback` is invoked.2966*2967* This function returns 0 if it succeeds, or one of the following2968* negative error codes:2969*2970* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`2971* Out of memory.2972* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`2973* The callback function failed.2974*/2975NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session);29762977/**2978* @function2979*2980* Returns the serialized data to send.2981*2982* This function behaves like `nghttp2_session_send()` except that it2983* does not use :type:`nghttp2_send_callback` to transmit data.2984* Instead, it assigns the pointer to the serialized data to the2985* |*data_ptr| and returns its length. The other callbacks are called2986* in the same way as they are in `nghttp2_session_send()`.2987*2988* If no data is available to send, this function returns 0.2989*2990* This function may not return all serialized data in one invocation.2991* To get all data, call this function repeatedly until it returns 02992* or one of negative error codes.2993*2994* The assigned |*data_ptr| is valid until the next call of2995* `nghttp2_session_mem_send()` or `nghttp2_session_send()`.2996*2997* The caller must send all data before sending the next chunk of2998* data.2999*3000* This function returns the length of the data pointed by the3001* |*data_ptr| if it succeeds, or one of the following negative error3002* codes:3003*3004* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3005* Out of memory.3006*3007* .. note::3008*3009* This function may produce very small byte string. If that is the3010* case, and application disables Nagle algorithm (``TCP_NODELAY``),3011* then writing this small chunk leads to very small packet, and it3012* is very inefficient. An application should be responsible to3013* buffer up small chunks of data as necessary to avoid this3014* situation.3015*/3016NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session,3017const uint8_t **data_ptr);30183019/**3020* @function3021*3022* Receives frames from the remote peer.3023*3024* This function receives as many frames as possible until the user3025* callback :type:`nghttp2_recv_callback` returns3026* :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. This function calls3027* several callback functions which are passed when initializing the3028* |session|. Here is the simple time chart which tells when each3029* callback is invoked:3030*3031* 1. :type:`nghttp2_recv_callback` is invoked one or more times to3032* receive frame header.3033*3034* 2. When frame header is received,3035* :type:`nghttp2_on_begin_frame_callback` is invoked.3036*3037* 3. If the frame is DATA frame:3038*3039* 1. :type:`nghttp2_recv_callback` is invoked to receive DATA3040* payload. For each chunk of data,3041* :type:`nghttp2_on_data_chunk_recv_callback` is invoked.3042*3043* 2. If one DATA frame is completely received,3044* :type:`nghttp2_on_frame_recv_callback` is invoked. If the3045* reception of the frame triggers the closure of the stream,3046* :type:`nghttp2_on_stream_close_callback` is invoked.3047*3048* 4. If the frame is the control frame:3049*3050* 1. :type:`nghttp2_recv_callback` is invoked one or more times to3051* receive whole frame.3052*3053* 2. If the received frame is valid, then following actions are3054* taken. If the frame is either HEADERS or PUSH_PROMISE,3055* :type:`nghttp2_on_begin_headers_callback` is invoked. Then3056* :type:`nghttp2_on_header_callback` is invoked for each header3057* name/value pair. For invalid header field,3058* :type:`nghttp2_on_invalid_header_callback` is called. After3059* all name/value pairs are emitted successfully,3060* :type:`nghttp2_on_frame_recv_callback` is invoked. For other3061* frames, :type:`nghttp2_on_frame_recv_callback` is invoked.3062* If the reception of the frame triggers the closure of the3063* stream, :type:`nghttp2_on_stream_close_callback` is invoked.3064*3065* 3. If the received frame is unpacked but is interpreted as3066* invalid, :type:`nghttp2_on_invalid_frame_recv_callback` is3067* invoked.3068*3069* This function returns 0 if it succeeds, or one of the following3070* negative error codes:3071*3072* :enum:`nghttp2_error.NGHTTP2_ERR_EOF`3073* The remote peer did shutdown on the connection.3074* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3075* Out of memory.3076* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`3077* The callback function failed.3078* :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`3079* Invalid client magic was detected. This error only returns3080* when |session| was configured as server and3081* `nghttp2_option_set_no_recv_client_magic()` is not used with3082* nonzero value.3083* :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED`3084* Flooding was detected in this HTTP/2 session, and it must be3085* closed. This is most likely caused by misbehaviour of peer.3086*/3087NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session);30883089/**3090* @function3091*3092* Processes data |in| as an input from the remote endpoint. The3093* |inlen| indicates the number of bytes to receive in the |in|.3094*3095* This function behaves like `nghttp2_session_recv()` except that it3096* does not use :type:`nghttp2_recv_callback` to receive data; the3097* |in| is the only data for the invocation of this function. If all3098* bytes are processed, this function returns. The other callbacks3099* are called in the same way as they are in `nghttp2_session_recv()`.3100*3101* In the current implementation, this function always tries to3102* processes |inlen| bytes of input data unless either an error occurs or3103* :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from3104* :type:`nghttp2_on_header_callback` or3105* :type:`nghttp2_on_data_chunk_recv_callback`. If3106* :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value3107* includes the number of bytes which was used to produce the data or3108* frame for the callback.3109*3110* This function returns the number of processed bytes, or one of the3111* following negative error codes:3112*3113* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3114* Out of memory.3115* :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`3116* The callback function failed.3117* :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`3118* Invalid client magic was detected. This error only returns3119* when |session| was configured as server and3120* `nghttp2_option_set_no_recv_client_magic()` is not used with3121* nonzero value.3122* :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED`3123* Flooding was detected in this HTTP/2 session, and it must be3124* closed. This is most likely caused by misbehaviour of peer.3125*/3126NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session,3127const uint8_t *in,3128size_t inlen);31293130/**3131* @function3132*3133* Puts back previously deferred DATA frame in the stream |stream_id|3134* to the outbound queue.3135*3136* This function returns 0 if it succeeds, or one of the following3137* negative error codes:3138*3139* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3140* The stream does not exist; or no deferred data exist.3141* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3142* Out of memory.3143*/3144NGHTTP2_EXTERN int nghttp2_session_resume_data(nghttp2_session *session,3145int32_t stream_id);31463147/**3148* @function3149*3150* Returns nonzero value if |session| wants to receive data from the3151* remote peer.3152*3153* If both `nghttp2_session_want_read()` and3154* `nghttp2_session_want_write()` return 0, the application should3155* drop the connection.3156*/3157NGHTTP2_EXTERN int nghttp2_session_want_read(nghttp2_session *session);31583159/**3160* @function3161*3162* Returns nonzero value if |session| wants to send data to the remote3163* peer.3164*3165* If both `nghttp2_session_want_read()` and3166* `nghttp2_session_want_write()` return 0, the application should3167* drop the connection.3168*/3169NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session);31703171/**3172* @function3173*3174* Returns stream_user_data for the stream |stream_id|. The3175* stream_user_data is provided by `nghttp2_submit_request()`,3176* `nghttp2_submit_headers()` or3177* `nghttp2_session_set_stream_user_data()`. Unless it is set using3178* `nghttp2_session_set_stream_user_data()`, if the stream is3179* initiated by the remote endpoint, stream_user_data is always3180* ``NULL``. If the stream does not exist, this function returns3181* ``NULL``.3182*/3183NGHTTP2_EXTERN void *3184nghttp2_session_get_stream_user_data(nghttp2_session *session,3185int32_t stream_id);31863187/**3188* @function3189*3190* Sets the |stream_user_data| to the stream denoted by the3191* |stream_id|. If a stream user data is already set to the stream,3192* it is replaced with the |stream_user_data|. It is valid to specify3193* ``NULL`` in the |stream_user_data|, which nullifies the associated3194* data pointer.3195*3196* It is valid to set the |stream_user_data| to the stream reserved by3197* PUSH_PROMISE frame.3198*3199* This function returns 0 if it succeeds, or one of following3200* negative error codes:3201*3202* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3203* The stream does not exist3204*/3205NGHTTP2_EXTERN int3206nghttp2_session_set_stream_user_data(nghttp2_session *session,3207int32_t stream_id, void *stream_user_data);32083209/**3210* @function3211*3212* Sets |user_data| to |session|, overwriting the existing user data3213* specified in `nghttp2_session_client_new()`, or3214* `nghttp2_session_server_new()`.3215*/3216NGHTTP2_EXTERN void nghttp2_session_set_user_data(nghttp2_session *session,3217void *user_data);32183219/**3220* @function3221*3222* Returns the number of frames in the outbound queue. This does not3223* include the deferred DATA frames.3224*/3225NGHTTP2_EXTERN size_t3226nghttp2_session_get_outbound_queue_size(nghttp2_session *session);32273228/**3229* @function3230*3231* Returns the number of DATA payload in bytes received without3232* WINDOW_UPDATE transmission for the stream |stream_id|. The local3233* (receive) window size can be adjusted by3234* `nghttp2_submit_window_update()`. This function takes into account3235* that and returns effective data length. In particular, if the3236* local window size is reduced by submitting negative3237* window_size_increment with `nghttp2_submit_window_update()`, this3238* function returns the number of bytes less than actually received.3239*3240* This function returns -1 if it fails.3241*/3242NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_recv_data_length(3243nghttp2_session *session, int32_t stream_id);32443245/**3246* @function3247*3248* Returns the local (receive) window size for the stream |stream_id|.3249* The local window size can be adjusted by3250* `nghttp2_submit_window_update()`. This function takes into account3251* that and returns effective window size.3252*3253* This function does not take into account the amount of received3254* data from the remote endpoint. Use3255* `nghttp2_session_get_stream_local_window_size()` to know the amount3256* of data the remote endpoint can send without receiving stream level3257* WINDOW_UPDATE frame. Note that each stream is still subject to the3258* connection level flow control.3259*3260* This function returns -1 if it fails.3261*/3262NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_local_window_size(3263nghttp2_session *session, int32_t stream_id);32643265/**3266* @function3267*3268* Returns the amount of flow-controlled payload (e.g., DATA) that the3269* remote endpoint can send without receiving stream level3270* WINDOW_UPDATE frame. It is also subject to the connection level3271* flow control. So the actual amount of data to send is3272* min(`nghttp2_session_get_stream_local_window_size()`,3273* `nghttp2_session_get_local_window_size()`).3274*3275* This function returns -1 if it fails.3276*/3277NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_local_window_size(3278nghttp2_session *session, int32_t stream_id);32793280/**3281* @function3282*3283* Returns the number of DATA payload in bytes received without3284* WINDOW_UPDATE transmission for a connection. The local (receive)3285* window size can be adjusted by `nghttp2_submit_window_update()`.3286* This function takes into account that and returns effective data3287* length. In particular, if the local window size is reduced by3288* submitting negative window_size_increment with3289* `nghttp2_submit_window_update()`, this function returns the number3290* of bytes less than actually received.3291*3292* This function returns -1 if it fails.3293*/3294NGHTTP2_EXTERN int32_t3295nghttp2_session_get_effective_recv_data_length(nghttp2_session *session);32963297/**3298* @function3299*3300* Returns the local (receive) window size for a connection. The3301* local window size can be adjusted by3302* `nghttp2_submit_window_update()`. This function takes into account3303* that and returns effective window size.3304*3305* This function does not take into account the amount of received3306* data from the remote endpoint. Use3307* `nghttp2_session_get_local_window_size()` to know the amount of3308* data the remote endpoint can send without receiving3309* connection-level WINDOW_UPDATE frame. Note that each stream is3310* still subject to the stream level flow control.3311*3312* This function returns -1 if it fails.3313*/3314NGHTTP2_EXTERN int32_t3315nghttp2_session_get_effective_local_window_size(nghttp2_session *session);33163317/**3318* @function3319*3320* Returns the amount of flow-controlled payload (e.g., DATA) that the3321* remote endpoint can send without receiving connection level3322* WINDOW_UPDATE frame. Note that each stream is still subject to the3323* stream level flow control (see3324* `nghttp2_session_get_stream_local_window_size()`).3325*3326* This function returns -1 if it fails.3327*/3328NGHTTP2_EXTERN int32_t3329nghttp2_session_get_local_window_size(nghttp2_session *session);33303331/**3332* @function3333*3334* Returns the remote window size for a given stream |stream_id|.3335*3336* This is the amount of flow-controlled payload (e.g., DATA) that the3337* local endpoint can send without stream level WINDOW_UPDATE. There3338* is also connection level flow control, so the effective size of3339* payload that the local endpoint can actually send is3340* min(`nghttp2_session_get_stream_remote_window_size()`,3341* `nghttp2_session_get_remote_window_size()`).3342*3343* This function returns -1 if it fails.3344*/3345NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_remote_window_size(3346nghttp2_session *session, int32_t stream_id);33473348/**3349* @function3350*3351* Returns the remote window size for a connection.3352*3353* This function always succeeds.3354*/3355NGHTTP2_EXTERN int32_t3356nghttp2_session_get_remote_window_size(nghttp2_session *session);33573358/**3359* @function3360*3361* Returns 1 if local peer half closed the given stream |stream_id|.3362* Returns 0 if it did not. Returns -1 if no such stream exists.3363*/3364NGHTTP2_EXTERN int3365nghttp2_session_get_stream_local_close(nghttp2_session *session,3366int32_t stream_id);33673368/**3369* @function3370*3371* Returns 1 if remote peer half closed the given stream |stream_id|.3372* Returns 0 if it did not. Returns -1 if no such stream exists.3373*/3374NGHTTP2_EXTERN int3375nghttp2_session_get_stream_remote_close(nghttp2_session *session,3376int32_t stream_id);33773378/**3379* @function3380*3381* Returns the current dynamic table size of HPACK inflater, including3382* the overhead 32 bytes per entry described in RFC 7541.3383*/3384NGHTTP2_EXTERN size_t3385nghttp2_session_get_hd_inflate_dynamic_table_size(nghttp2_session *session);33863387/**3388* @function3389*3390* Returns the current dynamic table size of HPACK deflater including3391* the overhead 32 bytes per entry described in RFC 7541.3392*/3393NGHTTP2_EXTERN size_t3394nghttp2_session_get_hd_deflate_dynamic_table_size(nghttp2_session *session);33953396/**3397* @function3398*3399* Signals the session so that the connection should be terminated.3400*3401* The last stream ID is the minimum value between the stream ID of a3402* stream for which :type:`nghttp2_on_frame_recv_callback` was called3403* most recently and the last stream ID we have sent to the peer3404* previously.3405*3406* The |error_code| is the error code of this GOAWAY frame. The3407* pre-defined error code is one of :enum:`nghttp2_error_code`.3408*3409* After the transmission, both `nghttp2_session_want_read()` and3410* `nghttp2_session_want_write()` return 0.3411*3412* This function should be called when the connection should be3413* terminated after sending GOAWAY. If the remaining streams should3414* be processed after GOAWAY, use `nghttp2_submit_goaway()` instead.3415*3416* This function returns 0 if it succeeds, or one of the following3417* negative error codes:3418*3419* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3420* Out of memory.3421*/3422NGHTTP2_EXTERN int nghttp2_session_terminate_session(nghttp2_session *session,3423uint32_t error_code);34243425/**3426* @function3427*3428* Signals the session so that the connection should be terminated.3429*3430* This function behaves like `nghttp2_session_terminate_session()`,3431* but the last stream ID can be specified by the application for fine3432* grained control of stream. The HTTP/2 specification does not allow3433* last_stream_id to be increased. So the actual value sent as3434* last_stream_id is the minimum value between the given3435* |last_stream_id| and the last_stream_id we have previously sent to3436* the peer.3437*3438* The |last_stream_id| is peer's stream ID or 0. So if |session| is3439* initialized as client, |last_stream_id| must be even or 0. If3440* |session| is initialized as server, |last_stream_id| must be odd or3441* 0.3442*3443* This function returns 0 if it succeeds, or one of the following3444* negative error codes:3445*3446* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3447* Out of memory.3448* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3449* The |last_stream_id| is invalid.3450*/3451NGHTTP2_EXTERN int nghttp2_session_terminate_session2(nghttp2_session *session,3452int32_t last_stream_id,3453uint32_t error_code);34543455/**3456* @function3457*3458* Signals to the client that the server started graceful shutdown3459* procedure.3460*3461* This function is only usable for server. If this function is3462* called with client side session, this function returns3463* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.3464*3465* To gracefully shutdown HTTP/2 session, server should call this3466* function to send GOAWAY with last_stream_id (1u << 31) - 1. And3467* after some delay (e.g., 1 RTT), send another GOAWAY with the stream3468* ID that the server has some processing using3469* `nghttp2_submit_goaway()`. See also3470* `nghttp2_session_get_last_proc_stream_id()`.3471*3472* Unlike `nghttp2_submit_goaway()`, this function just sends GOAWAY3473* and does nothing more. This is a mere indication to the client3474* that session shutdown is imminent. The application should call3475* `nghttp2_submit_goaway()` with appropriate last_stream_id after3476* this call.3477*3478* If one or more GOAWAY frame have been already sent by either3479* `nghttp2_submit_goaway()` or `nghttp2_session_terminate_session()`,3480* this function has no effect.3481*3482* This function returns 0 if it succeeds, or one of the following3483* negative error codes:3484*3485* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3486* Out of memory.3487* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`3488* The |session| is initialized as client.3489*/3490NGHTTP2_EXTERN int nghttp2_submit_shutdown_notice(nghttp2_session *session);34913492/**3493* @function3494*3495* Returns the value of SETTINGS |id| notified by a remote endpoint.3496* The |id| must be one of values defined in3497* :enum:`nghttp2_settings_id`.3498*/3499NGHTTP2_EXTERN uint32_t nghttp2_session_get_remote_settings(3500nghttp2_session *session, nghttp2_settings_id id);35013502/**3503* @function3504*3505* Returns the value of SETTINGS |id| of local endpoint acknowledged3506* by the remote endpoint. The |id| must be one of the values defined3507* in :enum:`nghttp2_settings_id`.3508*/3509NGHTTP2_EXTERN uint32_t nghttp2_session_get_local_settings(3510nghttp2_session *session, nghttp2_settings_id id);35113512/**3513* @function3514*3515* Tells the |session| that next stream ID is |next_stream_id|. The3516* |next_stream_id| must be equal or greater than the value returned3517* by `nghttp2_session_get_next_stream_id()`.3518*3519* This function returns 0 if it succeeds, or one of the following3520* negative error codes:3521*3522* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3523* The |next_stream_id| is strictly less than the value3524* `nghttp2_session_get_next_stream_id()` returns; or3525* |next_stream_id| is invalid (e.g., even integer for client, or3526* odd integer for server).3527*/3528NGHTTP2_EXTERN int nghttp2_session_set_next_stream_id(nghttp2_session *session,3529int32_t next_stream_id);35303531/**3532* @function3533*3534* Returns the next outgoing stream ID. Notice that return type is3535* uint32_t. If we run out of stream ID for this session, this3536* function returns 1 << 31.3537*/3538NGHTTP2_EXTERN uint32_t3539nghttp2_session_get_next_stream_id(nghttp2_session *session);35403541/**3542* @function3543*3544* Tells the |session| that |size| bytes for a stream denoted by3545* |stream_id| were consumed by application and are ready to3546* WINDOW_UPDATE. The consumed bytes are counted towards both3547* connection and stream level WINDOW_UPDATE (see3548* `nghttp2_session_consume_connection()` and3549* `nghttp2_session_consume_stream()` to update consumption3550* independently). This function is intended to be used without3551* automatic window update (see3552* `nghttp2_option_set_no_auto_window_update()`).3553*3554* This function returns 0 if it succeeds, or one of the following3555* negative error codes:3556*3557* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3558* Out of memory.3559* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3560* The |stream_id| is 0.3561* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`3562* Automatic WINDOW_UPDATE is not disabled.3563*/3564NGHTTP2_EXTERN int nghttp2_session_consume(nghttp2_session *session,3565int32_t stream_id, size_t size);35663567/**3568* @function3569*3570* Like `nghttp2_session_consume()`, but this only tells library that3571* |size| bytes were consumed only for connection level. Note that3572* HTTP/2 maintains connection and stream level flow control windows3573* independently.3574*3575* This function returns 0 if it succeeds, or one of the following3576* negative error codes:3577*3578* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3579* Out of memory.3580* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`3581* Automatic WINDOW_UPDATE is not disabled.3582*/3583NGHTTP2_EXTERN int nghttp2_session_consume_connection(nghttp2_session *session,3584size_t size);35853586/**3587* @function3588*3589* Like `nghttp2_session_consume()`, but this only tells library that3590* |size| bytes were consumed only for stream denoted by |stream_id|.3591* Note that HTTP/2 maintains connection and stream level flow control3592* windows independently.3593*3594* This function returns 0 if it succeeds, or one of the following3595* negative error codes:3596*3597* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3598* Out of memory.3599* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3600* The |stream_id| is 0.3601* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`3602* Automatic WINDOW_UPDATE is not disabled.3603*/3604NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session,3605int32_t stream_id,3606size_t size);36073608/**3609* @function3610*3611* Changes priority of existing stream denoted by |stream_id|. The3612* new priority specification is |pri_spec|.3613*3614* The priority is changed silently and instantly, and no PRIORITY3615* frame will be sent to notify the peer of this change. This3616* function may be useful for server to change the priority of pushed3617* stream.3618*3619* If |session| is initialized as server, and ``pri_spec->stream_id``3620* points to the idle stream, the idle stream is created if it does3621* not exist. The created idle stream will depend on root stream3622* (stream 0) with weight 16.3623*3624* Otherwise, if stream denoted by ``pri_spec->stream_id`` is not3625* found, we use default priority instead of given |pri_spec|. That3626* is make stream depend on root stream with weight 16.3627*3628* If3629* :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`3630* of value of 1 is submitted via `nghttp2_submit_settings()`, this3631* function does nothing and returns 0.3632*3633* This function returns 0 if it succeeds, or one of the following3634* negative error codes:3635*3636* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3637* Out of memory.3638* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3639* Attempted to depend on itself; or no stream exist for the given3640* |stream_id|; or |stream_id| is 03641*/3642NGHTTP2_EXTERN int3643nghttp2_session_change_stream_priority(nghttp2_session *session,3644int32_t stream_id,3645const nghttp2_priority_spec *pri_spec);36463647/**3648* @function3649*3650* Creates idle stream with the given |stream_id|, and priority3651* |pri_spec|.3652*3653* The stream creation is done without sending PRIORITY frame, which3654* means that peer does not know about the existence of this idle3655* stream in the local endpoint.3656*3657* RFC 7540 does not disallow the use of creation of idle stream with3658* odd or even stream ID regardless of client or server. So this3659* function can create odd or even stream ID regardless of client or3660* server. But probably it is a bit safer to use the stream ID the3661* local endpoint can initiate (in other words, use odd stream ID for3662* client, and even stream ID for server), to avoid potential3663* collision from peer's instruction. Also we can use3664* `nghttp2_session_set_next_stream_id()` to avoid to open created3665* idle streams accidentally if we follow this recommendation.3666*3667* If |session| is initialized as server, and ``pri_spec->stream_id``3668* points to the idle stream, the idle stream is created if it does3669* not exist. The created idle stream will depend on root stream3670* (stream 0) with weight 16.3671*3672* Otherwise, if stream denoted by ``pri_spec->stream_id`` is not3673* found, we use default priority instead of given |pri_spec|. That3674* is make stream depend on root stream with weight 16.3675*3676* If3677* :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`3678* of value of 1 is submitted via `nghttp2_submit_settings()`, this3679* function does nothing and returns 0.3680*3681* This function returns 0 if it succeeds, or one of the following3682* negative error codes:3683*3684* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3685* Out of memory.3686* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3687* Attempted to depend on itself; or stream denoted by |stream_id|3688* already exists; or |stream_id| cannot be used to create idle3689* stream (in other words, local endpoint has already opened3690* stream ID greater than or equal to the given stream ID; or3691* |stream_id| is 03692*/3693NGHTTP2_EXTERN int3694nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id,3695const nghttp2_priority_spec *pri_spec);36963697/**3698* @function3699*3700* Performs post-process of HTTP Upgrade request. This function can3701* be called from both client and server, but the behavior is very3702* different in each other.3703*3704* .. warning::3705*3706* This function is deprecated in favor of3707* `nghttp2_session_upgrade2()`, because this function lacks the3708* parameter to tell the library the request method used in the3709* original HTTP request. This information is required for client3710* to validate actual response body length against content-length3711* header field (see `nghttp2_option_set_no_http_messaging()`). If3712* HEAD is used in request, the length of response body must be 03713* regardless of value included in content-length header field.3714*3715* If called from client side, the |settings_payload| must be the3716* value sent in ``HTTP2-Settings`` header field and must be decoded3717* by base64url decoder. The |settings_payloadlen| is the length of3718* |settings_payload|. The |settings_payload| is unpacked and its3719* setting values will be submitted using `nghttp2_submit_settings()`.3720* This means that the client application code does not need to submit3721* SETTINGS by itself. The stream with stream ID=1 is opened and the3722* |stream_user_data| is used for its stream_user_data. The opened3723* stream becomes half-closed (local) state.3724*3725* If called from server side, the |settings_payload| must be the3726* value received in ``HTTP2-Settings`` header field and must be3727* decoded by base64url decoder. The |settings_payloadlen| is the3728* length of |settings_payload|. It is treated as if the SETTINGS3729* frame with that payload is received. Thus, callback functions for3730* the reception of SETTINGS frame will be invoked. The stream with3731* stream ID=1 is opened. The |stream_user_data| is ignored. The3732* opened stream becomes half-closed (remote).3733*3734* This function returns 0 if it succeeds, or one of the following3735* negative error codes:3736*3737* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3738* Out of memory.3739* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3740* The |settings_payload| is badly formed.3741* :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`3742* The stream ID 1 is already used or closed; or is not available.3743*/3744NGHTTP2_EXTERN int nghttp2_session_upgrade(nghttp2_session *session,3745const uint8_t *settings_payload,3746size_t settings_payloadlen,3747void *stream_user_data);37483749/**3750* @function3751*3752* Performs post-process of HTTP Upgrade request. This function can3753* be called from both client and server, but the behavior is very3754* different in each other.3755*3756* If called from client side, the |settings_payload| must be the3757* value sent in ``HTTP2-Settings`` header field and must be decoded3758* by base64url decoder. The |settings_payloadlen| is the length of3759* |settings_payload|. The |settings_payload| is unpacked and its3760* setting values will be submitted using `nghttp2_submit_settings()`.3761* This means that the client application code does not need to submit3762* SETTINGS by itself. The stream with stream ID=1 is opened and the3763* |stream_user_data| is used for its stream_user_data. The opened3764* stream becomes half-closed (local) state.3765*3766* If called from server side, the |settings_payload| must be the3767* value received in ``HTTP2-Settings`` header field and must be3768* decoded by base64url decoder. The |settings_payloadlen| is the3769* length of |settings_payload|. It is treated as if the SETTINGS3770* frame with that payload is received. Thus, callback functions for3771* the reception of SETTINGS frame will be invoked. The stream with3772* stream ID=1 is opened. The |stream_user_data| is ignored. The3773* opened stream becomes half-closed (remote).3774*3775* If the request method is HEAD, pass nonzero value to3776* |head_request|. Otherwise, pass 0.3777*3778* This function returns 0 if it succeeds, or one of the following3779* negative error codes:3780*3781* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3782* Out of memory.3783* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3784* The |settings_payload| is badly formed.3785* :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`3786* The stream ID 1 is already used or closed; or is not available.3787*/3788NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session,3789const uint8_t *settings_payload,3790size_t settings_payloadlen,3791int head_request,3792void *stream_user_data);37933794/**3795* @function3796*3797* Serializes the SETTINGS values |iv| in the |buf|. The size of the3798* |buf| is specified by |buflen|. The number of entries in the |iv|3799* array is given by |niv|. The required space in |buf| for the |niv|3800* entries is ``6*niv`` bytes and if the given buffer is too small, an3801* error is returned. This function is used mainly for creating a3802* SETTINGS payload to be sent with the ``HTTP2-Settings`` header3803* field in an HTTP Upgrade request. The data written in |buf| is NOT3804* base64url encoded and the application is responsible for encoding.3805*3806* This function returns the number of bytes written in |buf|, or one3807* of the following negative error codes:3808*3809* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3810* The |iv| contains duplicate settings ID or invalid value.3811*3812* :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`3813* The provided |buflen| size is too small to hold the output.3814*/3815NGHTTP2_EXTERN ssize_t nghttp2_pack_settings_payload(3816uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv);38173818/**3819* @function3820*3821* Returns string describing the |lib_error_code|. The3822* |lib_error_code| must be one of the :enum:`nghttp2_error`.3823*/3824NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code);38253826/**3827* @function3828*3829* Returns string representation of HTTP/2 error code |error_code|3830* (e.g., ``PROTOCOL_ERROR`` is returned if ``error_code ==3831* NGHTTP2_PROTOCOL_ERROR``). If string representation is unknown for3832* given |error_code|, this function returns string ``unknown``.3833*/3834NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code);38353836/**3837* @function3838*3839* Initializes |pri_spec| with the |stream_id| of the stream to depend3840* on with |weight| and its exclusive flag. If |exclusive| is3841* nonzero, exclusive flag is set.3842*3843* The |weight| must be in [:macro:`NGHTTP2_MIN_WEIGHT`,3844* :macro:`NGHTTP2_MAX_WEIGHT`], inclusive.3845*/3846NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec,3847int32_t stream_id,3848int32_t weight, int exclusive);38493850/**3851* @function3852*3853* Initializes |pri_spec| with the default values. The default values3854* are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and3855* exclusive = 0.3856*/3857NGHTTP2_EXTERN void3858nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec);38593860/**3861* @function3862*3863* Returns nonzero if the |pri_spec| is filled with default values.3864*/3865NGHTTP2_EXTERN int3866nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec);38673868/**3869* @function3870*3871* Submits HEADERS frame and optionally one or more DATA frames.3872*3873* The |pri_spec| is priority specification of this request. ``NULL``3874* means the default priority (see3875* `nghttp2_priority_spec_default_init()`). To specify the priority,3876* use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``,3877* this function will copy its data members.3878*3879* The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`,3880* :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight``3881* is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes3882* :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than3883* :macro:`NGHTTP2_MAX_WEIGHT`, it becomes3884* :macro:`NGHTTP2_MAX_WEIGHT`.3885*3886* If3887* :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`3888* of value of 1 is received by a remote endpoint, |pri_spec| is3889* ignored, and treated as if ``NULL`` is specified.3890*3891* The |nva| is an array of name/value pair :type:`nghttp2_nv` with3892* |nvlen| elements. The application is responsible to include3893* required pseudo-header fields (header field whose name starts with3894* ":") in |nva| and must place pseudo-headers before regular header3895* fields.3896*3897* This function creates copies of all name/value pairs in |nva|. It3898* also lower-cases all names in |nva|. The order of elements in3899* |nva| is preserved. For header fields with3900* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and3901* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,3902* header field name and value are not copied respectively. With3903* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application3904* is responsible to pass header field name in lowercase. The3905* application should maintain the references to them until3906* :type:`nghttp2_on_frame_send_callback` or3907* :type:`nghttp2_on_frame_not_send_callback` is called.3908*3909* HTTP/2 specification has requirement about header fields in the3910* request HEADERS. See the specification for more details.3911*3912* If |data_prd| is not ``NULL``, it provides data which will be sent3913* in subsequent DATA frames. In this case, a method that allows3914* request message bodies3915* (https://tools.ietf.org/html/rfc7231#section-4) must be specified3916* with ``:method`` key in |nva| (e.g. ``POST``). This function does3917* not take ownership of the |data_prd|. The function copies the3918* members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have3919* END_STREAM set. The |stream_user_data| is data associated to the3920* stream opened by this request and can be an arbitrary pointer,3921* which can be retrieved later by3922* `nghttp2_session_get_stream_user_data()`.3923*3924* This function returns assigned stream ID if it succeeds, or one of3925* the following negative error codes:3926*3927* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`3928* Out of memory.3929* :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`3930* No stream ID is available because maximum stream ID was3931* reached.3932* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`3933* Trying to depend on itself (new stream ID equals3934* ``pri_spec->stream_id``).3935* :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`3936* The |session| is server session.3937*3938* .. warning::3939*3940* This function returns assigned stream ID if it succeeds. But3941* that stream is not created yet. The application must not submit3942* frame to that stream ID before3943* :type:`nghttp2_before_frame_send_callback` is called for this3944* frame. This means `nghttp2_session_get_stream_user_data()` does3945* not work before the callback. But3946* `nghttp2_session_set_stream_user_data()` handles this situation3947* specially, and it can set data to a stream during this period.3948*3949*/3950NGHTTP2_EXTERN int32_t nghttp2_submit_request(3951nghttp2_session *session, const nghttp2_priority_spec *pri_spec,3952const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd,3953void *stream_user_data);39543955/**3956* @function3957*3958* Submits response HEADERS frame and optionally one or more DATA3959* frames against the stream |stream_id|.3960*3961* The |nva| is an array of name/value pair :type:`nghttp2_nv` with3962* |nvlen| elements. The application is responsible to include3963* required pseudo-header fields (header field whose name starts with3964* ":") in |nva| and must place pseudo-headers before regular header3965* fields.3966*3967* This function creates copies of all name/value pairs in |nva|. It3968* also lower-cases all names in |nva|. The order of elements in3969* |nva| is preserved. For header fields with3970* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and3971* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,3972* header field name and value are not copied respectively. With3973* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application3974* is responsible to pass header field name in lowercase. The3975* application should maintain the references to them until3976* :type:`nghttp2_on_frame_send_callback` or3977* :type:`nghttp2_on_frame_not_send_callback` is called.3978*3979* HTTP/2 specification has requirement about header fields in the3980* response HEADERS. See the specification for more details.3981*3982* If |data_prd| is not ``NULL``, it provides data which will be sent3983* in subsequent DATA frames. This function does not take ownership3984* of the |data_prd|. The function copies the members of the3985* |data_prd|. If |data_prd| is ``NULL``, HEADERS will have3986* END_STREAM flag set.3987*3988* This method can be used as normal HTTP response and push response.3989* When pushing a resource using this function, the |session| must be3990* configured using `nghttp2_session_server_new()` or its variants and3991* the target stream denoted by the |stream_id| must be reserved using3992* `nghttp2_submit_push_promise()`.3993*3994* To send non-final response headers (e.g., HTTP status 101), don't3995* use this function because this function half-closes the outbound3996* stream. Instead, use `nghttp2_submit_headers()` for this purpose.3997*3998* This function returns 0 if it succeeds, or one of the following3999* negative error codes:4000*4001* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4002* Out of memory.4003* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4004* The |stream_id| is 0.4005* :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`4006* DATA or HEADERS has been already submitted and not fully4007* processed yet. Normally, this does not happen, but when4008* application wrongly calls `nghttp2_submit_response()` twice,4009* this may happen.4010* :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`4011* The |session| is client session.4012*4013* .. warning::4014*4015* Calling this function twice for the same stream ID may lead to4016* program crash. It is generally considered to a programming error4017* to commit response twice.4018*/4019NGHTTP2_EXTERN int4020nghttp2_submit_response(nghttp2_session *session, int32_t stream_id,4021const nghttp2_nv *nva, size_t nvlen,4022const nghttp2_data_provider *data_prd);40234024/**4025* @function4026*4027* Submits trailer fields HEADERS against the stream |stream_id|.4028*4029* The |nva| is an array of name/value pair :type:`nghttp2_nv` with4030* |nvlen| elements. The application must not include pseudo-header4031* fields (headers whose names starts with ":") in |nva|.4032*4033* This function creates copies of all name/value pairs in |nva|. It4034* also lower-cases all names in |nva|. The order of elements in4035* |nva| is preserved. For header fields with4036* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and4037* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,4038* header field name and value are not copied respectively. With4039* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application4040* is responsible to pass header field name in lowercase. The4041* application should maintain the references to them until4042* :type:`nghttp2_on_frame_send_callback` or4043* :type:`nghttp2_on_frame_not_send_callback` is called.4044*4045* For server, trailer fields must follow response HEADERS or response4046* DATA without END_STREAM flat set. The library does not enforce4047* this requirement, and applications should do this for themselves.4048* If `nghttp2_submit_trailer()` is called before any response HEADERS4049* submission (usually by `nghttp2_submit_response()`), the content of4050* |nva| will be sent as response headers, which will result in error.4051*4052* This function has the same effect with `nghttp2_submit_headers()`,4053* with flags = :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` and both4054* pri_spec and stream_user_data to NULL.4055*4056* To submit trailer fields after `nghttp2_submit_response()` is4057* called, the application has to specify4058* :type:`nghttp2_data_provider` to `nghttp2_submit_response()`.4059* Inside of :type:`nghttp2_data_source_read_callback`, when setting4060* :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF`, also set4061* :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM`. After4062* that, the application can send trailer fields using4063* `nghttp2_submit_trailer()`. `nghttp2_submit_trailer()` can be used4064* inside :type:`nghttp2_data_source_read_callback`.4065*4066* This function returns 0 if it succeeds and |stream_id| is -1.4067* Otherwise, this function returns 0 if it succeeds, or one of the4068* following negative error codes:4069*4070* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4071* Out of memory.4072* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4073* The |stream_id| is 0.4074*/4075NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session,4076int32_t stream_id,4077const nghttp2_nv *nva, size_t nvlen);40784079/**4080* @function4081*4082* Submits HEADERS frame. The |flags| is bitwise OR of the4083* following values:4084*4085* * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`4086*4087* If |flags| includes :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`,4088* this frame has END_STREAM flag set.4089*4090* The library handles the CONTINUATION frame internally and it4091* correctly sets END_HEADERS to the last sequence of the PUSH_PROMISE4092* or CONTINUATION frame.4093*4094* If the |stream_id| is -1, this frame is assumed as request (i.e.,4095* request HEADERS frame which opens new stream). In this case, the4096* assigned stream ID will be returned. Otherwise, specify stream ID4097* in |stream_id|.4098*4099* The |pri_spec| is priority specification of this request. ``NULL``4100* means the default priority (see4101* `nghttp2_priority_spec_default_init()`). To specify the priority,4102* use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``,4103* this function will copy its data members.4104*4105* The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`,4106* :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight``4107* is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes4108* :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than4109* :macro:`NGHTTP2_MAX_WEIGHT`, it becomes :macro:`NGHTTP2_MAX_WEIGHT`.4110*4111* If4112* :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`4113* of value of 1 is received by a remote endpoint, |pri_spec| is4114* ignored, and treated as if ``NULL`` is specified.4115*4116* The |nva| is an array of name/value pair :type:`nghttp2_nv` with4117* |nvlen| elements. The application is responsible to include4118* required pseudo-header fields (header field whose name starts with4119* ":") in |nva| and must place pseudo-headers before regular header4120* fields.4121*4122* This function creates copies of all name/value pairs in |nva|. It4123* also lower-cases all names in |nva|. The order of elements in4124* |nva| is preserved. For header fields with4125* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and4126* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,4127* header field name and value are not copied respectively. With4128* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application4129* is responsible to pass header field name in lowercase. The4130* application should maintain the references to them until4131* :type:`nghttp2_on_frame_send_callback` or4132* :type:`nghttp2_on_frame_not_send_callback` is called.4133*4134* The |stream_user_data| is a pointer to an arbitrary data which is4135* associated to the stream this frame will open. Therefore it is4136* only used if this frame opens streams, in other words, it changes4137* stream state from idle or reserved to open.4138*4139* This function is low-level in a sense that the application code can4140* specify flags directly. For usual HTTP request,4141* `nghttp2_submit_request()` is useful. Likewise, for HTTP response,4142* prefer `nghttp2_submit_response()`.4143*4144* This function returns newly assigned stream ID if it succeeds and4145* |stream_id| is -1. Otherwise, this function returns 0 if it4146* succeeds, or one of the following negative error codes:4147*4148* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4149* Out of memory.4150* :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`4151* No stream ID is available because maximum stream ID was4152* reached.4153* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4154* The |stream_id| is 0; or trying to depend on itself (stream ID4155* equals ``pri_spec->stream_id``).4156* :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`4157* DATA or HEADERS has been already submitted and not fully4158* processed yet. This happens if stream denoted by |stream_id|4159* is in reserved state.4160* :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`4161* The |stream_id| is -1, and |session| is server session.4162*4163* .. warning::4164*4165* This function returns assigned stream ID if it succeeds and4166* |stream_id| is -1. But that stream is not opened yet. The4167* application must not submit frame to that stream ID before4168* :type:`nghttp2_before_frame_send_callback` is called for this4169* frame.4170*4171*/4172NGHTTP2_EXTERN int32_t nghttp2_submit_headers(4173nghttp2_session *session, uint8_t flags, int32_t stream_id,4174const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen,4175void *stream_user_data);41764177/**4178* @function4179*4180* Submits one or more DATA frames to the stream |stream_id|. The4181* data to be sent are provided by |data_prd|. If |flags| contains4182* :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame4183* has END_STREAM flag set.4184*4185* This function does not take ownership of the |data_prd|. The4186* function copies the members of the |data_prd|.4187*4188* This function returns 0 if it succeeds, or one of the following4189* negative error codes:4190*4191* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4192* Out of memory.4193* :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`4194* DATA or HEADERS has been already submitted and not fully4195* processed yet.4196* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4197* The |stream_id| is 0.4198* :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED`4199* The stream was already closed; or the |stream_id| is invalid.4200*4201* .. note::4202*4203* Currently, only one DATA or HEADERS is allowed for a stream at a4204* time. Submitting these frames more than once before first DATA4205* or HEADERS is finished results in4206* :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code. The4207* earliest callback which tells that previous frame is done is4208* :type:`nghttp2_on_frame_send_callback`. In side that callback,4209* new data can be submitted using `nghttp2_submit_data()`. Of4210* course, all data except for last one must not have4211* :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|.4212* This sounds a bit complicated, and we recommend to use4213* `nghttp2_submit_request()` and `nghttp2_submit_response()` to4214* avoid this cascading issue. The experience shows that for HTTP4215* use, these two functions are enough to implement both client and4216* server.4217*/4218NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,4219int32_t stream_id,4220const nghttp2_data_provider *data_prd);42214222/**4223* @function4224*4225* Submits PRIORITY frame to change the priority of stream |stream_id|4226* to the priority specification |pri_spec|.4227*4228* The |flags| is currently ignored and should be4229* :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.4230*4231* The |pri_spec| is priority specification of this request. ``NULL``4232* is not allowed for this function. To specify the priority, use4233* `nghttp2_priority_spec_init()`. This function will copy its data4234* members.4235*4236* The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`,4237* :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight``4238* is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes4239* :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than4240* :macro:`NGHTTP2_MAX_WEIGHT`, it becomes4241* :macro:`NGHTTP2_MAX_WEIGHT`.4242*4243* If4244* :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`4245* of value of 1 is received by a remote endpoint, this function does4246* nothing and returns 0.4247*4248* This function returns 0 if it succeeds, or one of the following4249* negative error codes:4250*4251* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4252* Out of memory.4253* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4254* The |stream_id| is 0; or the |pri_spec| is NULL; or trying to4255* depend on itself.4256*/4257NGHTTP2_EXTERN int4258nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,4259int32_t stream_id,4260const nghttp2_priority_spec *pri_spec);42614262/**4263* @macro4264*4265* :macro:`NGHTTP2_EXTPRI_DEFAULT_URGENCY` is the default urgency4266* level for :rfc:`9218` extensible priorities.4267*/4268#define NGHTTP2_EXTPRI_DEFAULT_URGENCY 342694270/**4271* @macro4272*4273* :macro:`NGHTTP2_EXTPRI_URGENCY_HIGH` is the highest urgency level4274* for :rfc:`9218` extensible priorities.4275*/4276#define NGHTTP2_EXTPRI_URGENCY_HIGH 042774278/**4279* @macro4280*4281* :macro:`NGHTTP2_EXTPRI_URGENCY_LOW` is the lowest urgency level for4282* :rfc:`9218` extensible priorities.4283*/4284#define NGHTTP2_EXTPRI_URGENCY_LOW 742854286/**4287* @macro4288*4289* :macro:`NGHTTP2_EXTPRI_URGENCY_LEVELS` is the number of urgency4290* levels for :rfc:`9218` extensible priorities.4291*/4292#define NGHTTP2_EXTPRI_URGENCY_LEVELS (NGHTTP2_EXTPRI_URGENCY_LOW + 1)42934294/**4295* @struct4296*4297* :type:`nghttp2_extpri` is :rfc:`9218` extensible priorities4298* specification for a stream.4299*/4300typedef struct nghttp2_extpri {4301/**4302* :member:`urgency` is the urgency of a stream, it must be in4303* [:macro:`NGHTTP2_EXTPRI_URGENCY_HIGH`,4304* :macro:`NGHTTP2_EXTPRI_URGENCY_LOW`], inclusive, and 0 is the4305* highest urgency.4306*/4307uint32_t urgency;4308/**4309* :member:`inc` indicates that a content can be processed4310* incrementally or not. If inc is 0, it cannot be processed4311* incrementally. If inc is 1, it can be processed incrementally.4312* Other value is not permitted.4313*/4314int inc;4315} nghttp2_extpri;43164317/**4318* @function4319*4320* Submits RST_STREAM frame to cancel/reject the stream |stream_id|4321* with the error code |error_code|.4322*4323* The pre-defined error code is one of :enum:`nghttp2_error_code`.4324*4325* The |flags| is currently ignored and should be4326* :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.4327*4328* This function returns 0 if it succeeds, or one of the following4329* negative error codes:4330*4331* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4332* Out of memory.4333* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4334* The |stream_id| is 0.4335*/4336NGHTTP2_EXTERN int nghttp2_submit_rst_stream(nghttp2_session *session,4337uint8_t flags, int32_t stream_id,4338uint32_t error_code);43394340/**4341* @function4342*4343* Stores local settings and submits SETTINGS frame. The |iv| is the4344* pointer to the array of :type:`nghttp2_settings_entry`. The |niv|4345* indicates the number of :type:`nghttp2_settings_entry`.4346*4347* The |flags| is currently ignored and should be4348* :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.4349*4350* This function does not take ownership of the |iv|. This function4351* copies all the elements in the |iv|.4352*4353* While updating individual stream's local window size, if the window4354* size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE,4355* RST_STREAM is issued against such a stream.4356*4357* SETTINGS with :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK` is4358* automatically submitted by the library and application could not4359* send it at its will.4360*4361* This function returns 0 if it succeeds, or one of the following4362* negative error codes:4363*4364* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4365* The |iv| contains invalid value (e.g., initial window size4366* strictly greater than (1 << 31) - 1.4367* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4368* Out of memory.4369*/4370NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session,4371uint8_t flags,4372const nghttp2_settings_entry *iv,4373size_t niv);43744375/**4376* @function4377*4378* Submits PUSH_PROMISE frame.4379*4380* The |flags| is currently ignored. The library handles the4381* CONTINUATION frame internally and it correctly sets END_HEADERS to4382* the last sequence of the PUSH_PROMISE or CONTINUATION frame.4383*4384* The |stream_id| must be client initiated stream ID.4385*4386* The |nva| is an array of name/value pair :type:`nghttp2_nv` with4387* |nvlen| elements. The application is responsible to include4388* required pseudo-header fields (header field whose name starts with4389* ":") in |nva| and must place pseudo-headers before regular header4390* fields.4391*4392* This function creates copies of all name/value pairs in |nva|. It4393* also lower-cases all names in |nva|. The order of elements in4394* |nva| is preserved. For header fields with4395* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and4396* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,4397* header field name and value are not copied respectively. With4398* :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application4399* is responsible to pass header field name in lowercase. The4400* application should maintain the references to them until4401* :type:`nghttp2_on_frame_send_callback` or4402* :type:`nghttp2_on_frame_not_send_callback` is called.4403*4404* The |promised_stream_user_data| is a pointer to an arbitrary data4405* which is associated to the promised stream this frame will open and4406* make it in reserved state. It is available using4407* `nghttp2_session_get_stream_user_data()`. The application can4408* access it in :type:`nghttp2_before_frame_send_callback` and4409* :type:`nghttp2_on_frame_send_callback` of this frame.4410*4411* The client side is not allowed to use this function.4412*4413* To submit response headers and data, use4414* `nghttp2_submit_response()`.4415*4416* This function returns assigned promised stream ID if it succeeds,4417* or one of the following negative error codes:4418*4419* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4420* Out of memory.4421* :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`4422* This function was invoked when |session| is initialized as4423* client.4424* :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`4425* No stream ID is available because maximum stream ID was4426* reached.4427* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4428* The |stream_id| is 0; The |stream_id| does not designate stream4429* that peer initiated.4430* :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED`4431* The stream was already closed; or the |stream_id| is invalid.4432*4433* .. warning::4434*4435* This function returns assigned promised stream ID if it succeeds.4436* As of 1.16.0, stream object for pushed resource is created when4437* this function succeeds. In that case, the application can submit4438* push response for the promised frame.4439*4440* In 1.15.0 or prior versions, pushed stream is not opened yet when4441* this function succeeds. The application must not submit frame to4442* that stream ID before :type:`nghttp2_before_frame_send_callback`4443* is called for this frame.4444*4445*/4446NGHTTP2_EXTERN int32_t nghttp2_submit_push_promise(4447nghttp2_session *session, uint8_t flags, int32_t stream_id,4448const nghttp2_nv *nva, size_t nvlen, void *promised_stream_user_data);44494450/**4451* @function4452*4453* Submits PING frame. You don't have to send PING back when you4454* received PING frame. The library automatically submits PING frame4455* in this case.4456*4457* The |flags| is bitwise OR of 0 or more of the following value.4458*4459* * :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK`4460*4461* Unless `nghttp2_option_set_no_auto_ping_ack()` is used, the |flags|4462* should be :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.4463*4464* If the |opaque_data| is non ``NULL``, then it should point to the 84465* bytes array of memory to specify opaque data to send with PING4466* frame. If the |opaque_data| is ``NULL``, zero-cleared 8 bytes will4467* be sent as opaque data.4468*4469* This function returns 0 if it succeeds, or one of the following4470* negative error codes:4471*4472* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4473* Out of memory.4474*/4475NGHTTP2_EXTERN int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags,4476const uint8_t *opaque_data);44774478/**4479* @function4480*4481* Submits GOAWAY frame with the last stream ID |last_stream_id| and4482* the error code |error_code|.4483*4484* The pre-defined error code is one of :enum:`nghttp2_error_code`.4485*4486* The |flags| is currently ignored and should be4487* :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.4488*4489* The |last_stream_id| is peer's stream ID or 0. So if |session| is4490* initialized as client, |last_stream_id| must be even or 0. If4491* |session| is initialized as server, |last_stream_id| must be odd or4492* 0.4493*4494* The HTTP/2 specification says last_stream_id must not be increased4495* from the value previously sent. So the actual value sent as4496* last_stream_id is the minimum value between the given4497* |last_stream_id| and the last_stream_id previously sent to the4498* peer.4499*4500* If the |opaque_data| is not ``NULL`` and |opaque_data_len| is not4501* zero, those data will be sent as additional debug data. The4502* library makes a copy of the memory region pointed by |opaque_data|4503* with the length |opaque_data_len|, so the caller does not need to4504* keep this memory after the return of this function. If the4505* |opaque_data_len| is 0, the |opaque_data| could be ``NULL``.4506*4507* After successful transmission of GOAWAY, following things happen.4508* All incoming streams having strictly more than |last_stream_id| are4509* closed. All incoming HEADERS which starts new stream are simply4510* ignored. After all active streams are handled, both4511* `nghttp2_session_want_read()` and `nghttp2_session_want_write()`4512* return 0 and the application can close session.4513*4514* This function returns 0 if it succeeds, or one of the following4515* negative error codes:4516*4517* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4518* Out of memory.4519* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4520* The |opaque_data_len| is too large; the |last_stream_id| is4521* invalid.4522*/4523NGHTTP2_EXTERN int nghttp2_submit_goaway(nghttp2_session *session,4524uint8_t flags, int32_t last_stream_id,4525uint32_t error_code,4526const uint8_t *opaque_data,4527size_t opaque_data_len);45284529/**4530* @function4531*4532* Returns the last stream ID of a stream for which4533* :type:`nghttp2_on_frame_recv_callback` was invoked most recently.4534* The returned value can be used as last_stream_id parameter for4535* `nghttp2_submit_goaway()` and4536* `nghttp2_session_terminate_session2()`.4537*4538* This function always succeeds.4539*/4540NGHTTP2_EXTERN int32_t4541nghttp2_session_get_last_proc_stream_id(nghttp2_session *session);45424543/**4544* @function4545*4546* Returns nonzero if new request can be sent from local endpoint.4547*4548* This function return 0 if request is not allowed for this session.4549* There are several reasons why request is not allowed. Some of the4550* reasons are: session is server; stream ID has been spent; GOAWAY4551* has been sent or received.4552*4553* The application can call `nghttp2_submit_request()` without4554* consulting this function. In that case, `nghttp2_submit_request()`4555* may return error. Or, request is failed to sent, and4556* :type:`nghttp2_on_stream_close_callback` is called.4557*/4558NGHTTP2_EXTERN int4559nghttp2_session_check_request_allowed(nghttp2_session *session);45604561/**4562* @function4563*4564* Returns nonzero if |session| is initialized as server side session.4565*/4566NGHTTP2_EXTERN int4567nghttp2_session_check_server_session(nghttp2_session *session);45684569/**4570* @function4571*4572* Submits WINDOW_UPDATE frame.4573*4574* The |flags| is currently ignored and should be4575* :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.4576*4577* The |stream_id| is the stream ID to send this WINDOW_UPDATE. To4578* send connection level WINDOW_UPDATE, specify 0 to |stream_id|.4579*4580* If the |window_size_increment| is positive, the WINDOW_UPDATE with4581* that value as window_size_increment is queued. If the4582* |window_size_increment| is larger than the received bytes from the4583* remote endpoint, the local window size is increased by that4584* difference. If the sole purpose is to increase the local window4585* size, consider to use `nghttp2_session_set_local_window_size()`.4586*4587* If the |window_size_increment| is negative, the local window size4588* is decreased by -|window_size_increment|. If automatic4589* WINDOW_UPDATE is enabled4590* (`nghttp2_option_set_no_auto_window_update()`), and the library4591* decided that the WINDOW_UPDATE should be submitted, then4592* WINDOW_UPDATE is queued with the current received bytes count. If4593* the sole purpose is to decrease the local window size, consider to4594* use `nghttp2_session_set_local_window_size()`.4595*4596* If the |window_size_increment| is 0, the function does nothing and4597* returns 0.4598*4599* This function returns 0 if it succeeds, or one of the following4600* negative error codes:4601*4602* :enum:`nghttp2_error.NGHTTP2_ERR_FLOW_CONTROL`4603* The local window size overflow or gets negative.4604* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4605* Out of memory.4606*/4607NGHTTP2_EXTERN int nghttp2_submit_window_update(nghttp2_session *session,4608uint8_t flags,4609int32_t stream_id,4610int32_t window_size_increment);46114612/**4613* @function4614*4615* Set local window size (local endpoints's window size) to the given4616* |window_size| for the given stream denoted by |stream_id|. To4617* change connection level window size, specify 0 to |stream_id|. To4618* increase window size, this function may submit WINDOW_UPDATE frame4619* to transmission queue.4620*4621* The |flags| is currently ignored and should be4622* :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.4623*4624* This sounds similar to `nghttp2_submit_window_update()`, but there4625* are 2 differences. The first difference is that this function4626* takes the absolute value of window size to set, rather than the4627* delta. To change the window size, this may be easier to use since4628* the application just declares the intended window size, rather than4629* calculating delta. The second difference is that4630* `nghttp2_submit_window_update()` affects the received bytes count4631* which has not acked yet. By the specification of4632* `nghttp2_submit_window_update()`, to strictly increase the local4633* window size, we have to submit delta including all received bytes4634* count, which might not be desirable in some cases. On the other4635* hand, this function does not affect the received bytes count. It4636* just sets the local window size to the given value.4637*4638* This function returns 0 if it succeeds, or one of the following4639* negative error codes:4640*4641* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4642* The |stream_id| is negative.4643* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4644* Out of memory.4645*/4646NGHTTP2_EXTERN int4647nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags,4648int32_t stream_id, int32_t window_size);46494650/**4651* @function4652*4653* Submits extension frame.4654*4655* Application can pass arbitrary frame flags and stream ID in |flags|4656* and |stream_id| respectively. The |payload| is opaque pointer, and4657* it can be accessible though ``frame->ext.payload`` in4658* :type:`nghttp2_pack_extension_callback`. The library will not own4659* passed |payload| pointer.4660*4661* The application must set :type:`nghttp2_pack_extension_callback`4662* using `nghttp2_session_callbacks_set_pack_extension_callback()`.4663*4664* The application should retain the memory pointed by |payload| until4665* the transmission of extension frame is done (which is indicated by4666* :type:`nghttp2_on_frame_send_callback`), or transmission fails4667* (which is indicated by :type:`nghttp2_on_frame_not_send_callback`).4668* If application does not touch this memory region after packing it4669* into a wire format, application can free it inside4670* :type:`nghttp2_pack_extension_callback`.4671*4672* The standard HTTP/2 frame cannot be sent with this function, so4673* |type| must be strictly grater than 0x9. Otherwise, this function4674* will fail with error code4675* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`.4676*4677* This function returns 0 if it succeeds, or one of the following4678* negative error codes:4679*4680* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`4681* If :type:`nghttp2_pack_extension_callback` is not set.4682* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4683* If |type| specifies standard HTTP/2 frame type. The frame4684* types in the rage [0x0, 0x9], both inclusive, are standard4685* HTTP/2 frame type, and cannot be sent using this function.4686* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4687* Out of memory4688*/4689NGHTTP2_EXTERN int nghttp2_submit_extension(nghttp2_session *session,4690uint8_t type, uint8_t flags,4691int32_t stream_id, void *payload);46924693/**4694* @struct4695*4696* The payload of ALTSVC frame. ALTSVC frame is a non-critical4697* extension to HTTP/2. If this frame is received, and4698* `nghttp2_option_set_user_recv_extension_type()` is not set, and4699* `nghttp2_option_set_builtin_recv_extension_type()` is set for4700* :enum:`nghttp2_frame_type.NGHTTP2_ALTSVC`,4701* ``nghttp2_extension.payload`` will point to this struct.4702*4703* It has the following members:4704*/4705typedef struct {4706/**4707* The pointer to origin which this alternative service is4708* associated with. This is not necessarily NULL-terminated.4709*/4710uint8_t *origin;4711/**4712* The length of the |origin|.4713*/4714size_t origin_len;4715/**4716* The pointer to Alt-Svc field value contained in ALTSVC frame.4717* This is not necessarily NULL-terminated.4718*/4719uint8_t *field_value;4720/**4721* The length of the |field_value|.4722*/4723size_t field_value_len;4724} nghttp2_ext_altsvc;47254726/**4727* @function4728*4729* Submits ALTSVC frame.4730*4731* ALTSVC frame is a non-critical extension to HTTP/2, and defined in4732* `RFC 7383 <https://tools.ietf.org/html/rfc7838#section-4>`_.4733*4734* The |flags| is currently ignored and should be4735* :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.4736*4737* The |origin| points to the origin this alternative service is4738* associated with. The |origin_len| is the length of the origin. If4739* |stream_id| is 0, the origin must be specified. If |stream_id| is4740* not zero, the origin must be empty (in other words, |origin_len|4741* must be 0).4742*4743* The ALTSVC frame is only usable from server side. If this function4744* is invoked with client side session, this function returns4745* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.4746*4747* This function returns 0 if it succeeds, or one of the following4748* negative error codes:4749*4750* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4751* Out of memory4752* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`4753* The function is called from client side session4754* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4755* The sum of |origin_len| and |field_value_len| is larger than4756* 16382; or |origin_len| is 0 while |stream_id| is 0; or4757* |origin_len| is not 0 while |stream_id| is not 0.4758*/4759NGHTTP2_EXTERN int nghttp2_submit_altsvc(nghttp2_session *session,4760uint8_t flags, int32_t stream_id,4761const uint8_t *origin,4762size_t origin_len,4763const uint8_t *field_value,4764size_t field_value_len);47654766/**4767* @struct4768*4769* The single entry of an origin.4770*/4771typedef struct {4772/**4773* The pointer to origin. No validation is made against this field4774* by the library. This is not necessarily NULL-terminated.4775*/4776uint8_t *origin;4777/**4778* The length of the |origin|.4779*/4780size_t origin_len;4781} nghttp2_origin_entry;47824783/**4784* @struct4785*4786* The payload of ORIGIN frame. ORIGIN frame is a non-critical4787* extension to HTTP/2 and defined by `RFC 83364788* <https://tools.ietf.org/html/rfc8336>`_.4789*4790* If this frame is received, and4791* `nghttp2_option_set_user_recv_extension_type()` is not set, and4792* `nghttp2_option_set_builtin_recv_extension_type()` is set for4793* :enum:`nghttp2_frame_type.NGHTTP2_ORIGIN`,4794* ``nghttp2_extension.payload`` will point to this struct.4795*4796* It has the following members:4797*/4798typedef struct {4799/**4800* The number of origins contained in |ov|.4801*/4802size_t nov;4803/**4804* The pointer to the array of origins contained in ORIGIN frame.4805*/4806nghttp2_origin_entry *ov;4807} nghttp2_ext_origin;48084809/**4810* @function4811*4812* Submits ORIGIN frame.4813*4814* ORIGIN frame is a non-critical extension to HTTP/2 and defined by4815* `RFC 8336 <https://tools.ietf.org/html/rfc8336>`_.4816*4817* The |flags| is currently ignored and should be4818* :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.4819*4820* The |ov| points to the array of origins. The |nov| specifies the4821* number of origins included in |ov|. This function creates copies4822* of all elements in |ov|.4823*4824* The ORIGIN frame is only usable by a server. If this function is4825* invoked with client side session, this function returns4826* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.4827*4828* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4829* Out of memory4830* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`4831* The function is called from client side session.4832* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4833* There are too many origins, or an origin is too large to fit4834* into a default frame payload.4835*/4836NGHTTP2_EXTERN int nghttp2_submit_origin(nghttp2_session *session,4837uint8_t flags,4838const nghttp2_origin_entry *ov,4839size_t nov);48404841/**4842* @struct4843*4844* The payload of PRIORITY_UPDATE frame. PRIORITY_UPDATE frame is a4845* non-critical extension to HTTP/2. If this frame is received, and4846* `nghttp2_option_set_user_recv_extension_type()` is not set, and4847* `nghttp2_option_set_builtin_recv_extension_type()` is set for4848* :enum:`nghttp2_frame_type.NGHTTP2_PRIORITY_UPDATE`,4849* ``nghttp2_extension.payload`` will point to this struct.4850*4851* It has the following members:4852*/4853typedef struct {4854/**4855* The stream ID of the stream whose priority is updated.4856*/4857int32_t stream_id;4858/**4859* The pointer to Priority field value. It is not necessarily4860* NULL-terminated.4861*/4862uint8_t *field_value;4863/**4864* The length of the :member:`field_value`.4865*/4866size_t field_value_len;4867} nghttp2_ext_priority_update;48684869/**4870* @function4871*4872* Submits PRIORITY_UPDATE frame.4873*4874* PRIORITY_UPDATE frame is a non-critical extension to HTTP/2, and4875* defined in :rfc:`9218#section-7.1`.4876*4877* The |flags| is currently ignored and should be4878* :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.4879*4880* The |stream_id| is the ID of stream which is prioritized. The4881* |field_value| points to the Priority field value. The4882* |field_value_len| is the length of the Priority field value.4883*4884* If this function is called by server,4885* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` is returned.4886*4887* If4888* :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`4889* of value of 0 is received by a remote endpoint (or it is omitted),4890* this function does nothing and returns 0.4891*4892* This function returns 0 if it succeeds, or one of the following4893* negative error codes:4894*4895* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4896* Out of memory4897* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`4898* The function is called from server side session4899* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4900* The |field_value_len| is larger than 16380; or |stream_id| is4901* 0.4902*/4903NGHTTP2_EXTERN int nghttp2_submit_priority_update(nghttp2_session *session,4904uint8_t flags,4905int32_t stream_id,4906const uint8_t *field_value,4907size_t field_value_len);49084909/**4910* @function4911*4912* Changes the priority of the existing stream denoted by |stream_id|.4913* The new priority is |extpri|. This function is meant to be used by4914* server for :rfc:`9218` extensible prioritization scheme.4915*4916* If |session| is initialized as client, this function returns4917* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. For client, use4918* `nghttp2_submit_priority_update()` instead.4919*4920* If :member:`extpri->urgency <nghttp2_extpri.urgency>` is out of4921* bound, it is set to :macro:`NGHTTP2_EXTPRI_URGENCY_LOW`.4922*4923* If |ignore_client_signal| is nonzero, server starts to ignore4924* client priority signals for this stream.4925*4926* If4927* :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`4928* of value of 1 is not submitted via `nghttp2_submit_settings()`,4929* this function does nothing and returns 0.4930*4931* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`4932* Out of memory.4933* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`4934* The |session| is initialized as client.4935* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`4936* |stream_id| is zero; or a stream denoted by |stream_id| is not4937* found.4938*/4939NGHTTP2_EXTERN int nghttp2_session_change_extpri_stream_priority(4940nghttp2_session *session, int32_t stream_id, const nghttp2_extpri *extpri,4941int ignore_client_signal);49424943/**4944* @function4945*4946* Compares ``lhs->name`` of length ``lhs->namelen`` bytes and4947* ``rhs->name`` of length ``rhs->namelen`` bytes. Returns negative4948* integer if ``lhs->name`` is found to be less than ``rhs->name``; or4949* returns positive integer if ``lhs->name`` is found to be greater4950* than ``rhs->name``; or returns 0 otherwise.4951*/4952NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs,4953const nghttp2_nv *rhs);49544955/**4956* @function4957*4958* A helper function for dealing with NPN in client side or ALPN in4959* server side. The |in| contains peer's protocol list in preferable4960* order. The format of |in| is length-prefixed and not4961* null-terminated. For example, ``h2`` and4962* ``http/1.1`` stored in |in| like this::4963*4964* in[0] = 24965* in[1..2] = "h2"4966* in[3] = 84967* in[4..11] = "http/1.1"4968* inlen = 124969*4970* The selection algorithm is as follows:4971*4972* 1. If peer's list contains HTTP/2 protocol the library supports,4973* it is selected and returns 1. The following step is not taken.4974*4975* 2. If peer's list contains ``http/1.1``, this function selects4976* ``http/1.1`` and returns 0. The following step is not taken.4977*4978* 3. This function selects nothing and returns -1 (So called4979* non-overlap case). In this case, |out| and |outlen| are left4980* untouched.4981*4982* Selecting ``h2`` means that ``h2`` is written into |*out| and its4983* length (which is 2) is assigned to |*outlen|.4984*4985* For ALPN, refer to https://tools.ietf.org/html/rfc73014986*4987* See http://technotes.googlecode.com/git/nextprotoneg.html for more4988* details about NPN.4989*4990* For NPN, to use this method you should do something like::4991*4992* static int select_next_proto_cb(SSL* ssl,4993* unsigned char **out,4994* unsigned char *outlen,4995* const unsigned char *in,4996* unsigned int inlen,4997* void *arg)4998* {4999* int rv;5000* rv = nghttp2_select_next_protocol(out, outlen, in, inlen);5001* if (rv == -1) {5002* return SSL_TLSEXT_ERR_NOACK;5003* }5004* if (rv == 1) {5005* ((MyType*)arg)->http2_selected = 1;5006* }5007* return SSL_TLSEXT_ERR_OK;5008* }5009* ...5010* SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, my_obj);5011*5012*/5013NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out,5014unsigned char *outlen,5015const unsigned char *in,5016unsigned int inlen);50175018/**5019* @function5020*5021* Returns a pointer to a nghttp2_info struct with version information5022* about the run-time library in use. The |least_version| argument5023* can be set to a 24 bit numerical value for the least accepted5024* version number and if the condition is not met, this function will5025* return a ``NULL``. Pass in 0 to skip the version checking.5026*/5027NGHTTP2_EXTERN nghttp2_info *nghttp2_version(int least_version);50285029/**5030* @function5031*5032* Returns nonzero if the :type:`nghttp2_error` library error code5033* |lib_error| is fatal.5034*/5035NGHTTP2_EXTERN int nghttp2_is_fatal(int lib_error_code);50365037/**5038* @function5039*5040* Returns nonzero if HTTP header field name |name| of length |len| is5041* valid according to http://tools.ietf.org/html/rfc7230#section-3.25042*5043* Because this is a header field name in HTTP2, the upper cased alphabet5044* is treated as error.5045*/5046NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len);50475048/**5049* @function5050*5051* Returns nonzero if HTTP header field value |value| of length |len|5052* is valid according to5053* http://tools.ietf.org/html/rfc7230#section-3.25054*5055* This function is considered obsolete, and application should5056* consider to use `nghttp2_check_header_value_rfc9113()` instead.5057*/5058NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len);50595060/**5061* @function5062*5063* Returns nonzero if HTTP header field value |value| of length |len|5064* is valid according to5065* http://tools.ietf.org/html/rfc7230#section-3.2, plus5066* https://datatracker.ietf.org/doc/html/rfc9113#section-8.2.15067*/5068NGHTTP2_EXTERN int nghttp2_check_header_value_rfc9113(const uint8_t *value,5069size_t len);50705071/**5072* @function5073*5074* Returns nonzero if the |value| which is supposed to be the value of5075* the :method header field is valid according to5076* https://datatracker.ietf.org/doc/html/rfc7231#section-4 and5077* https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.65078*/5079NGHTTP2_EXTERN int nghttp2_check_method(const uint8_t *value, size_t len);50805081/**5082* @function5083*5084* Returns nonzero if the |value| which is supposed to be the value of5085* the :path header field is valid according to5086* https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.35087*5088* |value| is valid if it merely consists of the allowed characters.5089* In particular, it does not check whether |value| follows the syntax5090* of path. The allowed characters are all characters valid by5091* `nghttp2_check_header_value` minus SPC and HT.5092*/5093NGHTTP2_EXTERN int nghttp2_check_path(const uint8_t *value, size_t len);50945095/**5096* @function5097*5098* Returns nonzero if the |value| which is supposed to be the value of the5099* :authority or host header field is valid according to5100* https://tools.ietf.org/html/rfc3986#section-3.25101*5102* |value| is valid if it merely consists of the allowed characters.5103* In particular, it does not check whether |value| follows the syntax5104* of authority.5105*/5106NGHTTP2_EXTERN int nghttp2_check_authority(const uint8_t *value, size_t len);51075108/* HPACK API */51095110struct nghttp2_hd_deflater;51115112/**5113* @struct5114*5115* HPACK deflater object.5116*/5117typedef struct nghttp2_hd_deflater nghttp2_hd_deflater;51185119/**5120* @function5121*5122* Initializes |*deflater_ptr| for deflating name/values pairs.5123*5124* The |max_deflate_dynamic_table_size| is the upper bound of header5125* table size the deflater will use.5126*5127* If this function fails, |*deflater_ptr| is left untouched.5128*5129* This function returns 0 if it succeeds, or one of the following5130* negative error codes:5131*5132* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`5133* Out of memory.5134*/5135NGHTTP2_EXTERN int5136nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,5137size_t max_deflate_dynamic_table_size);51385139/**5140* @function5141*5142* Like `nghttp2_hd_deflate_new()`, but with additional custom memory5143* allocator specified in the |mem|.5144*5145* The |mem| can be ``NULL`` and the call is equivalent to5146* `nghttp2_hd_deflate_new()`.5147*5148* This function does not take ownership |mem|. The application is5149* responsible for freeing |mem|.5150*5151* The library code does not refer to |mem| pointer after this5152* function returns, so the application can safely free it.5153*/5154NGHTTP2_EXTERN int5155nghttp2_hd_deflate_new2(nghttp2_hd_deflater **deflater_ptr,5156size_t max_deflate_dynamic_table_size,5157nghttp2_mem *mem);51585159/**5160* @function5161*5162* Deallocates any resources allocated for |deflater|.5163*/5164NGHTTP2_EXTERN void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater);51655166/**5167* @function5168*5169* Changes header table size of the |deflater| to5170* |settings_max_dynamic_table_size| bytes. This may trigger eviction5171* in the dynamic table.5172*5173* The |settings_max_dynamic_table_size| should be the value received5174* in SETTINGS_HEADER_TABLE_SIZE.5175*5176* The deflater never uses more memory than5177* ``max_deflate_dynamic_table_size`` bytes specified in5178* `nghttp2_hd_deflate_new()`. Therefore, if5179* |settings_max_dynamic_table_size| >5180* ``max_deflate_dynamic_table_size``, resulting maximum table size5181* becomes ``max_deflate_dynamic_table_size``.5182*5183* This function returns 0 if it succeeds, or one of the following5184* negative error codes:5185*5186* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`5187* Out of memory.5188*/5189NGHTTP2_EXTERN int5190nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater,5191size_t settings_max_dynamic_table_size);51925193/**5194* @function5195*5196* Deflates the |nva|, which has the |nvlen| name/value pairs, into5197* the |buf| of length |buflen|.5198*5199* If |buf| is not large enough to store the deflated header block,5200* this function fails with5201* :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller5202* should use `nghttp2_hd_deflate_bound()` to know the upper bound of5203* buffer size required to deflate given header name/value pairs.5204*5205* Once this function fails, subsequent call of this function always5206* returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`.5207*5208* After this function returns, it is safe to delete the |nva|.5209*5210* This function returns the number of bytes written to |buf| if it5211* succeeds, or one of the following negative error codes:5212*5213* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`5214* Out of memory.5215* :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`5216* Deflation process has failed.5217* :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`5218* The provided |buflen| size is too small to hold the output.5219*/5220NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,5221uint8_t *buf, size_t buflen,5222const nghttp2_nv *nva,5223size_t nvlen);52245225/**5226* @function5227*5228* Deflates the |nva|, which has the |nvlen| name/value pairs, into5229* the |veclen| size of buf vector |vec|. The each size of buffer5230* must be set in len field of :type:`nghttp2_vec`. If and only if5231* one chunk is filled up completely, next chunk will be used. If5232* |vec| is not large enough to store the deflated header block, this5233* function fails with5234* :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller5235* should use `nghttp2_hd_deflate_bound()` to know the upper bound of5236* buffer size required to deflate given header name/value pairs.5237*5238* Once this function fails, subsequent call of this function always5239* returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`.5240*5241* After this function returns, it is safe to delete the |nva|.5242*5243* This function returns the number of bytes written to |vec| if it5244* succeeds, or one of the following negative error codes:5245*5246* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`5247* Out of memory.5248* :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`5249* Deflation process has failed.5250* :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`5251* The provided |buflen| size is too small to hold the output.5252*/5253NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater,5254const nghttp2_vec *vec,5255size_t veclen,5256const nghttp2_nv *nva,5257size_t nvlen);52585259/**5260* @function5261*5262* Returns an upper bound on the compressed size after deflation of5263* |nva| of length |nvlen|.5264*/5265NGHTTP2_EXTERN size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,5266const nghttp2_nv *nva,5267size_t nvlen);52685269/**5270* @function5271*5272* Returns the number of entries that header table of |deflater|5273* contains. This is the sum of the number of static table and5274* dynamic table, so the return value is at least 61.5275*/5276NGHTTP2_EXTERN5277size_t nghttp2_hd_deflate_get_num_table_entries(nghttp2_hd_deflater *deflater);52785279/**5280* @function5281*5282* Returns the table entry denoted by |idx| from header table of5283* |deflater|. The |idx| is 1-based, and idx=1 returns first entry of5284* static table. idx=62 returns first entry of dynamic table if it5285* exists. Specifying idx=0 is error, and this function returns NULL.5286* If |idx| is strictly greater than the number of entries the tables5287* contain, this function returns NULL.5288*/5289NGHTTP2_EXTERN5290const nghttp2_nv *5291nghttp2_hd_deflate_get_table_entry(nghttp2_hd_deflater *deflater, size_t idx);52925293/**5294* @function5295*5296* Returns the used dynamic table size, including the overhead 325297* bytes per entry described in RFC 7541.5298*/5299NGHTTP2_EXTERN5300size_t nghttp2_hd_deflate_get_dynamic_table_size(nghttp2_hd_deflater *deflater);53015302/**5303* @function5304*5305* Returns the maximum dynamic table size.5306*/5307NGHTTP2_EXTERN5308size_t5309nghttp2_hd_deflate_get_max_dynamic_table_size(nghttp2_hd_deflater *deflater);53105311struct nghttp2_hd_inflater;53125313/**5314* @struct5315*5316* HPACK inflater object.5317*/5318typedef struct nghttp2_hd_inflater nghttp2_hd_inflater;53195320/**5321* @function5322*5323* Initializes |*inflater_ptr| for inflating name/values pairs.5324*5325* If this function fails, |*inflater_ptr| is left untouched.5326*5327* This function returns 0 if it succeeds, or one of the following5328* negative error codes:5329*5330* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`5331* Out of memory.5332*/5333NGHTTP2_EXTERN int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr);53345335/**5336* @function5337*5338* Like `nghttp2_hd_inflate_new()`, but with additional custom memory5339* allocator specified in the |mem|.5340*5341* The |mem| can be ``NULL`` and the call is equivalent to5342* `nghttp2_hd_inflate_new()`.5343*5344* This function does not take ownership |mem|. The application is5345* responsible for freeing |mem|.5346*5347* The library code does not refer to |mem| pointer after this5348* function returns, so the application can safely free it.5349*/5350NGHTTP2_EXTERN int nghttp2_hd_inflate_new2(nghttp2_hd_inflater **inflater_ptr,5351nghttp2_mem *mem);53525353/**5354* @function5355*5356* Deallocates any resources allocated for |inflater|.5357*/5358NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater);53595360/**5361* @function5362*5363* Changes header table size in the |inflater|. This may trigger5364* eviction in the dynamic table.5365*5366* The |settings_max_dynamic_table_size| should be the value5367* transmitted in SETTINGS_HEADER_TABLE_SIZE.5368*5369* This function must not be called while header block is being5370* inflated. In other words, this function must be called after5371* initialization of |inflater|, but before calling5372* `nghttp2_hd_inflate_hd2()`, or after5373* `nghttp2_hd_inflate_end_headers()`. Otherwise,5374* `NGHTTP2_ERR_INVALID_STATE` was returned.5375*5376* This function returns 0 if it succeeds, or one of the following5377* negative error codes:5378*5379* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`5380* Out of memory.5381* :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`5382* The function is called while header block is being inflated.5383* Probably, application missed to call5384* `nghttp2_hd_inflate_end_headers()`.5385*/5386NGHTTP2_EXTERN int5387nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater,5388size_t settings_max_dynamic_table_size);53895390/**5391* @enum5392*5393* The flags for header inflation.5394*/5395typedef enum {5396/**5397* No flag set.5398*/5399NGHTTP2_HD_INFLATE_NONE = 0,5400/**5401* Indicates all headers were inflated.5402*/5403NGHTTP2_HD_INFLATE_FINAL = 0x01,5404/**5405* Indicates a header was emitted.5406*/5407NGHTTP2_HD_INFLATE_EMIT = 0x025408} nghttp2_hd_inflate_flag;54095410/**5411* @function5412*5413* .. warning::5414*5415* Deprecated. Use `nghttp2_hd_inflate_hd2()` instead.5416*5417* Inflates name/value block stored in |in| with length |inlen|. This5418* function performs decompression. For each successful emission of5419* header name/value pair,5420* :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in5421* |*inflate_flags| and name/value pair is assigned to the |nv_out|5422* and the function returns. The caller must not free the members of5423* |nv_out|.5424*5425* The |nv_out| may include pointers to the memory region in the |in|.5426* The caller must retain the |in| while the |nv_out| is used.5427*5428* The application should call this function repeatedly until the5429* ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and5430* return value is non-negative. This means the all input values are5431* processed successfully. Then the application must call5432* `nghttp2_hd_inflate_end_headers()` to prepare for the next header5433* block input.5434*5435* The caller can feed complete compressed header block. It also can5436* feed it in several chunks. The caller must set |in_final| to5437* nonzero if the given input is the last block of the compressed5438* header.5439*5440* This function returns the number of bytes processed if it succeeds,5441* or one of the following negative error codes:5442*5443* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`5444* Out of memory.5445* :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`5446* Inflation process has failed.5447* :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR`5448* The header field name or value is too large.5449*5450* Example follows::5451*5452* int inflate_header_block(nghttp2_hd_inflater *hd_inflater,5453* uint8_t *in, size_t inlen, int final)5454* {5455* ssize_t rv;5456*5457* for(;;) {5458* nghttp2_nv nv;5459* int inflate_flags = 0;5460*5461* rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags,5462* in, inlen, final);5463*5464* if(rv < 0) {5465* fprintf(stderr, "inflate failed with error code %zd", rv);5466* return -1;5467* }5468*5469* in += rv;5470* inlen -= rv;5471*5472* if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {5473* fwrite(nv.name, nv.namelen, 1, stderr);5474* fprintf(stderr, ": ");5475* fwrite(nv.value, nv.valuelen, 1, stderr);5476* fprintf(stderr, "\n");5477* }5478* if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {5479* nghttp2_hd_inflate_end_headers(hd_inflater);5480* break;5481* }5482* if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&5483* inlen == 0) {5484* break;5485* }5486* }5487*5488* return 0;5489* }5490*5491*/5492NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,5493nghttp2_nv *nv_out,5494int *inflate_flags, uint8_t *in,5495size_t inlen, int in_final);54965497/**5498* @function5499*5500* Inflates name/value block stored in |in| with length |inlen|. This5501* function performs decompression. For each successful emission of5502* header name/value pair,5503* :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in5504* |*inflate_flags| and name/value pair is assigned to the |nv_out|5505* and the function returns. The caller must not free the members of5506* |nv_out|.5507*5508* The |nv_out| may include pointers to the memory region in the |in|.5509* The caller must retain the |in| while the |nv_out| is used.5510*5511* The application should call this function repeatedly until the5512* ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and5513* return value is non-negative. If that happens, all given input5514* data (|inlen| bytes) are processed successfully. Then the5515* application must call `nghttp2_hd_inflate_end_headers()` to prepare5516* for the next header block input.5517*5518* In other words, if |in_final| is nonzero, and this function returns5519* |inlen|, you can assert that5520* :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in5521* |*inflate_flags|.5522*5523* The caller can feed complete compressed header block. It also can5524* feed it in several chunks. The caller must set |in_final| to5525* nonzero if the given input is the last block of the compressed5526* header.5527*5528* This function returns the number of bytes processed if it succeeds,5529* or one of the following negative error codes:5530*5531* :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`5532* Out of memory.5533* :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`5534* Inflation process has failed.5535* :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR`5536* The header field name or value is too large.5537*5538* Example follows::5539*5540* int inflate_header_block(nghttp2_hd_inflater *hd_inflater,5541* uint8_t *in, size_t inlen, int final)5542* {5543* ssize_t rv;5544*5545* for(;;) {5546* nghttp2_nv nv;5547* int inflate_flags = 0;5548*5549* rv = nghttp2_hd_inflate_hd2(hd_inflater, &nv, &inflate_flags,5550* in, inlen, final);5551*5552* if(rv < 0) {5553* fprintf(stderr, "inflate failed with error code %zd", rv);5554* return -1;5555* }5556*5557* in += rv;5558* inlen -= rv;5559*5560* if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {5561* fwrite(nv.name, nv.namelen, 1, stderr);5562* fprintf(stderr, ": ");5563* fwrite(nv.value, nv.valuelen, 1, stderr);5564* fprintf(stderr, "\n");5565* }5566* if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {5567* nghttp2_hd_inflate_end_headers(hd_inflater);5568* break;5569* }5570* if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&5571* inlen == 0) {5572* break;5573* }5574* }5575*5576* return 0;5577* }5578*5579*/5580NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater,5581nghttp2_nv *nv_out,5582int *inflate_flags,5583const uint8_t *in, size_t inlen,5584int in_final);55855586/**5587* @function5588*5589* Signals the end of decompression for one header block.5590*5591* This function returns 0 if it succeeds. Currently this function5592* always succeeds.5593*/5594NGHTTP2_EXTERN int5595nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater);55965597/**5598* @function5599*5600* Returns the number of entries that header table of |inflater|5601* contains. This is the sum of the number of static table and5602* dynamic table, so the return value is at least 61.5603*/5604NGHTTP2_EXTERN5605size_t nghttp2_hd_inflate_get_num_table_entries(nghttp2_hd_inflater *inflater);56065607/**5608* @function5609*5610* Returns the table entry denoted by |idx| from header table of5611* |inflater|. The |idx| is 1-based, and idx=1 returns first entry of5612* static table. idx=62 returns first entry of dynamic table if it5613* exists. Specifying idx=0 is error, and this function returns NULL.5614* If |idx| is strictly greater than the number of entries the tables5615* contain, this function returns NULL.5616*/5617NGHTTP2_EXTERN5618const nghttp2_nv *5619nghttp2_hd_inflate_get_table_entry(nghttp2_hd_inflater *inflater, size_t idx);56205621/**5622* @function5623*5624* Returns the used dynamic table size, including the overhead 325625* bytes per entry described in RFC 7541.5626*/5627NGHTTP2_EXTERN5628size_t nghttp2_hd_inflate_get_dynamic_table_size(nghttp2_hd_inflater *inflater);56295630/**5631* @function5632*5633* Returns the maximum dynamic table size.5634*/5635NGHTTP2_EXTERN5636size_t5637nghttp2_hd_inflate_get_max_dynamic_table_size(nghttp2_hd_inflater *inflater);56385639struct nghttp2_stream;56405641/**5642* @struct5643*5644* The structure to represent HTTP/2 stream. The details of this5645* structure are intentionally hidden from the public API.5646*/5647typedef struct nghttp2_stream nghttp2_stream;56485649/**5650* @function5651*5652* Returns pointer to :type:`nghttp2_stream` object denoted by5653* |stream_id|. If stream was not found, returns NULL.5654*5655* Returns imaginary root stream (see5656* `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|.5657*5658* Unless |stream_id| == 0, the returned pointer is valid until next5659* call of `nghttp2_session_send()`, `nghttp2_session_mem_send()`,5660* `nghttp2_session_recv()`, and `nghttp2_session_mem_recv()`.5661*/5662NGHTTP2_EXTERN nghttp2_stream *5663nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id);56645665/**5666* @enum5667*5668* State of stream as described in RFC 7540.5669*/5670typedef enum {5671/**5672* idle state.5673*/5674NGHTTP2_STREAM_STATE_IDLE = 1,5675/**5676* open state.5677*/5678NGHTTP2_STREAM_STATE_OPEN,5679/**5680* reserved (local) state.5681*/5682NGHTTP2_STREAM_STATE_RESERVED_LOCAL,5683/**5684* reserved (remote) state.5685*/5686NGHTTP2_STREAM_STATE_RESERVED_REMOTE,5687/**5688* half closed (local) state.5689*/5690NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL,5691/**5692* half closed (remote) state.5693*/5694NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE,5695/**5696* closed state.5697*/5698NGHTTP2_STREAM_STATE_CLOSED5699} nghttp2_stream_proto_state;57005701/**5702* @function5703*5704* Returns state of |stream|. The root stream retrieved by5705* `nghttp2_session_get_root_stream()` will have stream state5706* :enum:`nghttp2_stream_proto_state.NGHTTP2_STREAM_STATE_IDLE`.5707*/5708NGHTTP2_EXTERN nghttp2_stream_proto_state5709nghttp2_stream_get_state(nghttp2_stream *stream);57105711/**5712* @function5713*5714* Returns root of dependency tree, which is imaginary stream with5715* stream ID 0. The returned pointer is valid until |session| is5716* freed by `nghttp2_session_del()`.5717*/5718NGHTTP2_EXTERN nghttp2_stream *5719nghttp2_session_get_root_stream(nghttp2_session *session);57205721/**5722* @function5723*5724* Returns the parent stream of |stream| in dependency tree. Returns5725* NULL if there is no such stream.5726*/5727NGHTTP2_EXTERN nghttp2_stream *5728nghttp2_stream_get_parent(nghttp2_stream *stream);57295730NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream);57315732/**5733* @function5734*5735* Returns the next sibling stream of |stream| in dependency tree.5736* Returns NULL if there is no such stream.5737*/5738NGHTTP2_EXTERN nghttp2_stream *5739nghttp2_stream_get_next_sibling(nghttp2_stream *stream);57405741/**5742* @function5743*5744* Returns the previous sibling stream of |stream| in dependency tree.5745* Returns NULL if there is no such stream.5746*/5747NGHTTP2_EXTERN nghttp2_stream *5748nghttp2_stream_get_previous_sibling(nghttp2_stream *stream);57495750/**5751* @function5752*5753* Returns the first child stream of |stream| in dependency tree.5754* Returns NULL if there is no such stream.5755*/5756NGHTTP2_EXTERN nghttp2_stream *5757nghttp2_stream_get_first_child(nghttp2_stream *stream);57585759/**5760* @function5761*5762* Returns dependency weight to the parent stream of |stream|.5763*/5764NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream);57655766/**5767* @function5768*5769* Returns the sum of the weight for |stream|'s children.5770*/5771NGHTTP2_EXTERN int32_t5772nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream);57735774/**5775* @functypedef5776*5777* Callback function invoked when the library outputs debug logging.5778* The function is called with arguments suitable for ``vfprintf(3)``5779*5780* The debug output is only enabled if the library is built with5781* ``DEBUGBUILD`` macro defined.5782*/5783typedef void (*nghttp2_debug_vprintf_callback)(const char *format,5784va_list args);57855786/**5787* @function5788*5789* Sets a debug output callback called by the library when built with5790* ``DEBUGBUILD`` macro defined. If this option is not used, debug5791* log is written into standard error output.5792*5793* For builds without ``DEBUGBUILD`` macro defined, this function is5794* noop.5795*5796* Note that building with ``DEBUGBUILD`` may cause significant5797* performance penalty to libnghttp2 because of extra processing. It5798* should be used for debugging purpose only.5799*5800* .. Warning::5801*5802* Building with ``DEBUGBUILD`` may cause significant performance5803* penalty to libnghttp2 because of extra processing. It should be5804* used for debugging purpose only. We write this two times because5805* this is important.5806*/5807NGHTTP2_EXTERN void nghttp2_set_debug_vprintf_callback(5808nghttp2_debug_vprintf_callback debug_vprintf_callback);58095810#ifdef __cplusplus5811}5812#endif58135814#endif /* NGHTTP2_H */581558165817