|
|
|||
File indexing completed on 2026-05-16 08:19:54
0001 /* 0002 * nghttp2 - HTTP/2 C Library 0003 * 0004 * Copyright (c) 2013, 2014 Tatsuhiro Tsujikawa 0005 * 0006 * Permission is hereby granted, free of charge, to any person obtaining 0007 * a copy of this software and associated documentation files (the 0008 * "Software"), to deal in the Software without restriction, including 0009 * without limitation the rights to use, copy, modify, merge, publish, 0010 * distribute, sublicense, and/or sell copies of the Software, and to 0011 * permit persons to whom the Software is furnished to do so, subject to 0012 * the following conditions: 0013 * 0014 * The above copyright notice and this permission notice shall be 0015 * included in all copies or substantial portions of the Software. 0016 * 0017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 0018 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 0019 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 0020 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 0021 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 0022 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 0023 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 0024 */ 0025 #ifndef NGHTTP2_H 0026 #define NGHTTP2_H 0027 0028 /* Define WIN32 when build target is Win32 API (borrowed from 0029 libcurl) */ 0030 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) 0031 # define WIN32 0032 #endif 0033 0034 /* Compatibility for non-Clang compilers */ 0035 #ifndef __has_declspec_attribute 0036 # define __has_declspec_attribute(x) 0 0037 #endif 0038 0039 #ifdef __cplusplus 0040 extern "C" { 0041 #endif 0042 0043 #include <stdlib.h> 0044 #if defined(_MSC_VER) && (_MSC_VER < 1800) 0045 /* MSVC < 2013 does not have inttypes.h because it is not C99 0046 compliant. See compiler macros and version number in 0047 https://sourceforge.net/p/predef/wiki/Compilers/ */ 0048 # include <stdint.h> 0049 #else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ 0050 # include <inttypes.h> 0051 #endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ 0052 #include <sys/types.h> 0053 #include <stdarg.h> 0054 #include <stddef.h> 0055 0056 #include <nghttp2/nghttp2ver.h> 0057 0058 #ifdef NGHTTP2_STATICLIB 0059 # define NGHTTP2_EXTERN 0060 #elif defined(WIN32) || \ 0061 (__has_declspec_attribute(dllexport) && __has_declspec_attribute(dllimport)) 0062 # ifdef BUILDING_NGHTTP2 0063 # define NGHTTP2_EXTERN __declspec(dllexport) 0064 # else /* !BUILDING_NGHTTP2 */ 0065 # define NGHTTP2_EXTERN __declspec(dllimport) 0066 # endif /* !BUILDING_NGHTTP2 */ 0067 #else /* !defined(WIN32) */ 0068 # ifdef BUILDING_NGHTTP2 0069 # define NGHTTP2_EXTERN __attribute__((visibility("default"))) 0070 # else /* !BUILDING_NGHTTP2 */ 0071 # define NGHTTP2_EXTERN 0072 # endif /* !BUILDING_NGHTTP2 */ 0073 #endif /* !defined(WIN32) */ 0074 0075 #ifdef BUILDING_NGHTTP2 0076 # undef NGHTTP2_NO_SSIZE_T 0077 #endif /* BUILDING_NGHTTP2 */ 0078 0079 /** 0080 * @typedef 0081 * 0082 * :type:`nghttp2_ssize` is a signed counterpart of size_t. 0083 */ 0084 typedef ptrdiff_t nghttp2_ssize; 0085 0086 /** 0087 * @macro 0088 * 0089 * The protocol version identification string of this library 0090 * supports. This identifier is used if HTTP/2 is used over TLS. 0091 */ 0092 #define NGHTTP2_PROTO_VERSION_ID "h2" 0093 /** 0094 * @macro 0095 * 0096 * The length of :macro:`NGHTTP2_PROTO_VERSION_ID`. 0097 */ 0098 #define NGHTTP2_PROTO_VERSION_ID_LEN 2 0099 0100 /** 0101 * @macro 0102 * 0103 * The serialized form of ALPN protocol identifier this library 0104 * supports. Notice that first byte is the length of following 0105 * protocol identifier. This is the same wire format of `TLS ALPN 0106 * extension <https://tools.ietf.org/html/rfc7301>`_. This is useful 0107 * to process incoming ALPN tokens in wire format. 0108 */ 0109 #define NGHTTP2_PROTO_ALPN "\x2h2" 0110 0111 /** 0112 * @macro 0113 * 0114 * The length of :macro:`NGHTTP2_PROTO_ALPN`. 0115 */ 0116 #define NGHTTP2_PROTO_ALPN_LEN (sizeof(NGHTTP2_PROTO_ALPN) - 1) 0117 0118 /** 0119 * @macro 0120 * 0121 * The protocol version identification string of this library 0122 * supports. This identifier is used if HTTP/2 is used over cleartext 0123 * TCP. 0124 */ 0125 #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c" 0126 0127 /** 0128 * @macro 0129 * 0130 * The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`. 0131 */ 0132 #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 3 0133 0134 struct nghttp2_session; 0135 /** 0136 * @struct 0137 * 0138 * The primary structure to hold the resources needed for a HTTP/2 0139 * session. The details of this structure are intentionally hidden 0140 * from the public API. 0141 */ 0142 typedef struct nghttp2_session nghttp2_session; 0143 0144 /** 0145 * @macro 0146 * 0147 * The age of :type:`nghttp2_info` 0148 */ 0149 #define NGHTTP2_VERSION_AGE 1 0150 0151 /** 0152 * @struct 0153 * 0154 * This struct is what `nghttp2_version()` returns. It holds 0155 * information about the particular nghttp2 version. 0156 */ 0157 typedef struct { 0158 /** 0159 * Age of this struct. This instance of nghttp2 sets it to 0160 * :macro:`NGHTTP2_VERSION_AGE` but a future version may bump it and 0161 * add more struct fields at the bottom 0162 */ 0163 int age; 0164 /** 0165 * the :macro:`NGHTTP2_VERSION_NUM` number (since age ==1) 0166 */ 0167 int version_num; 0168 /** 0169 * points to the :macro:`NGHTTP2_VERSION` string (since age ==1) 0170 */ 0171 const char *version_str; 0172 /** 0173 * points to the :macro:`NGHTTP2_PROTO_VERSION_ID` string this 0174 * instance implements (since age ==1) 0175 */ 0176 const char *proto_str; 0177 /* -------- the above fields all exist when age == 1 */ 0178 } nghttp2_info; 0179 0180 /** 0181 * @macro 0182 * 0183 * .. warning:: 0184 * 0185 * Deprecated. :rfc:`7540` priorities are deprecated by 0186 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 0187 * prioritization scheme. 0188 * 0189 * The default weight of stream dependency. 0190 */ 0191 #define NGHTTP2_DEFAULT_WEIGHT 16 0192 0193 /** 0194 * @macro 0195 * 0196 * .. warning:: 0197 * 0198 * Deprecated. :rfc:`7540` priorities are deprecated by 0199 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 0200 * prioritization scheme. 0201 * 0202 * The maximum weight of stream dependency. 0203 */ 0204 #define NGHTTP2_MAX_WEIGHT 256 0205 0206 /** 0207 * @macro 0208 * 0209 * .. warning:: 0210 * 0211 * Deprecated. :rfc:`7540` priorities are deprecated by 0212 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 0213 * prioritization scheme. 0214 * 0215 * The minimum weight of stream dependency. 0216 */ 0217 #define NGHTTP2_MIN_WEIGHT 1 0218 0219 /** 0220 * @macro 0221 * 0222 * The maximum window size 0223 */ 0224 #define NGHTTP2_MAX_WINDOW_SIZE ((int32_t)((1U << 31) - 1)) 0225 0226 /** 0227 * @macro 0228 * 0229 * The initial window size for stream level flow control. 0230 */ 0231 #define NGHTTP2_INITIAL_WINDOW_SIZE ((1 << 16) - 1) 0232 /** 0233 * @macro 0234 * 0235 * The initial window size for connection level flow control. 0236 */ 0237 #define NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE ((1 << 16) - 1) 0238 0239 /** 0240 * @macro 0241 * 0242 * The default header table size. 0243 */ 0244 #define NGHTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12) 0245 0246 /** 0247 * @macro 0248 * 0249 * The client magic string, which is the first 24 bytes byte string of 0250 * client connection preface. 0251 */ 0252 #define NGHTTP2_CLIENT_MAGIC "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" 0253 0254 /** 0255 * @macro 0256 * 0257 * The length of :macro:`NGHTTP2_CLIENT_MAGIC`. 0258 */ 0259 #define NGHTTP2_CLIENT_MAGIC_LEN 24 0260 0261 /** 0262 * @macro 0263 * 0264 * The default max number of settings per SETTINGS frame 0265 */ 0266 #define NGHTTP2_DEFAULT_MAX_SETTINGS 32 0267 0268 /** 0269 * @enum 0270 * 0271 * Error codes used in this library. The code range is [-999, -500], 0272 * inclusive. The following values are defined: 0273 */ 0274 typedef enum { 0275 /** 0276 * Invalid argument passed. 0277 */ 0278 NGHTTP2_ERR_INVALID_ARGUMENT = -501, 0279 /** 0280 * Out of buffer space. 0281 */ 0282 NGHTTP2_ERR_BUFFER_ERROR = -502, 0283 /** 0284 * The specified protocol version is not supported. 0285 */ 0286 NGHTTP2_ERR_UNSUPPORTED_VERSION = -503, 0287 /** 0288 * Used as a return value from :type:`nghttp2_send_callback2`, 0289 * :type:`nghttp2_recv_callback` and 0290 * :type:`nghttp2_send_data_callback` to indicate that the operation 0291 * would block. 0292 */ 0293 NGHTTP2_ERR_WOULDBLOCK = -504, 0294 /** 0295 * General protocol error 0296 */ 0297 NGHTTP2_ERR_PROTO = -505, 0298 /** 0299 * The frame is invalid. 0300 */ 0301 NGHTTP2_ERR_INVALID_FRAME = -506, 0302 /** 0303 * The peer performed a shutdown on the connection. 0304 */ 0305 NGHTTP2_ERR_EOF = -507, 0306 /** 0307 * Used as a return value from 0308 * :func:`nghttp2_data_source_read_callback2` to indicate that data 0309 * transfer is postponed. See 0310 * :func:`nghttp2_data_source_read_callback2` for details. 0311 */ 0312 NGHTTP2_ERR_DEFERRED = -508, 0313 /** 0314 * Stream ID has reached the maximum value. Therefore no stream ID 0315 * is available. 0316 */ 0317 NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509, 0318 /** 0319 * The stream is already closed; or the stream ID is invalid. 0320 */ 0321 NGHTTP2_ERR_STREAM_CLOSED = -510, 0322 /** 0323 * RST_STREAM has been added to the outbound queue. The stream is 0324 * in closing state. 0325 */ 0326 NGHTTP2_ERR_STREAM_CLOSING = -511, 0327 /** 0328 * The transmission is not allowed for this stream (e.g., a frame 0329 * with END_STREAM flag set has already sent). 0330 */ 0331 NGHTTP2_ERR_STREAM_SHUT_WR = -512, 0332 /** 0333 * The stream ID is invalid. 0334 */ 0335 NGHTTP2_ERR_INVALID_STREAM_ID = -513, 0336 /** 0337 * The state of the stream is not valid (e.g., DATA cannot be sent 0338 * to the stream if response HEADERS has not been sent). 0339 */ 0340 NGHTTP2_ERR_INVALID_STREAM_STATE = -514, 0341 /** 0342 * Another DATA frame has already been deferred. 0343 */ 0344 NGHTTP2_ERR_DEFERRED_DATA_EXIST = -515, 0345 /** 0346 * Starting new stream is not allowed (e.g., GOAWAY has been sent 0347 * and/or received). 0348 */ 0349 NGHTTP2_ERR_START_STREAM_NOT_ALLOWED = -516, 0350 /** 0351 * GOAWAY has already been sent. 0352 */ 0353 NGHTTP2_ERR_GOAWAY_ALREADY_SENT = -517, 0354 /** 0355 * The received frame contains the invalid header block (e.g., There 0356 * are duplicate header names; or the header names are not encoded 0357 * in US-ASCII character set and not lower cased; or the header name 0358 * is zero-length string; or the header value contains multiple 0359 * in-sequence NUL bytes). 0360 */ 0361 NGHTTP2_ERR_INVALID_HEADER_BLOCK = -518, 0362 /** 0363 * Indicates that the context is not suitable to perform the 0364 * requested operation. 0365 */ 0366 NGHTTP2_ERR_INVALID_STATE = -519, 0367 /** 0368 * The user callback function failed due to the temporal error. 0369 */ 0370 NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE = -521, 0371 /** 0372 * The length of the frame is invalid, either too large or too small. 0373 */ 0374 NGHTTP2_ERR_FRAME_SIZE_ERROR = -522, 0375 /** 0376 * Header block inflate/deflate error. 0377 */ 0378 NGHTTP2_ERR_HEADER_COMP = -523, 0379 /** 0380 * Flow control error 0381 */ 0382 NGHTTP2_ERR_FLOW_CONTROL = -524, 0383 /** 0384 * Insufficient buffer size given to function. 0385 */ 0386 NGHTTP2_ERR_INSUFF_BUFSIZE = -525, 0387 /** 0388 * Callback was paused by the application 0389 */ 0390 NGHTTP2_ERR_PAUSE = -526, 0391 /** 0392 * There are too many in-flight SETTING frame and no more 0393 * transmission of SETTINGS is allowed. 0394 */ 0395 NGHTTP2_ERR_TOO_MANY_INFLIGHT_SETTINGS = -527, 0396 /** 0397 * The server push is disabled. 0398 */ 0399 NGHTTP2_ERR_PUSH_DISABLED = -528, 0400 /** 0401 * DATA or HEADERS frame for a given stream has been already 0402 * submitted and has not been fully processed yet. Application 0403 * should wait for the transmission of the previously submitted 0404 * frame before submitting another. 0405 */ 0406 NGHTTP2_ERR_DATA_EXIST = -529, 0407 /** 0408 * The current session is closing due to a connection error or 0409 * `nghttp2_session_terminate_session()` is called. 0410 */ 0411 NGHTTP2_ERR_SESSION_CLOSING = -530, 0412 /** 0413 * Invalid HTTP header field was received and stream is going to be 0414 * closed. 0415 */ 0416 NGHTTP2_ERR_HTTP_HEADER = -531, 0417 /** 0418 * Violation in HTTP messaging rule. 0419 */ 0420 NGHTTP2_ERR_HTTP_MESSAGING = -532, 0421 /** 0422 * Stream was refused. 0423 */ 0424 NGHTTP2_ERR_REFUSED_STREAM = -533, 0425 /** 0426 * Unexpected internal error, but recovered. 0427 */ 0428 NGHTTP2_ERR_INTERNAL = -534, 0429 /** 0430 * Indicates that a processing was canceled. 0431 */ 0432 NGHTTP2_ERR_CANCEL = -535, 0433 /** 0434 * When a local endpoint expects to receive SETTINGS frame, it 0435 * receives an other type of frame. 0436 */ 0437 NGHTTP2_ERR_SETTINGS_EXPECTED = -536, 0438 /** 0439 * When a local endpoint receives too many settings entries 0440 * in a single SETTINGS frame. 0441 */ 0442 NGHTTP2_ERR_TOO_MANY_SETTINGS = -537, 0443 /** 0444 * The errors < :enum:`nghttp2_error.NGHTTP2_ERR_FATAL` mean that 0445 * the library is under unexpected condition and processing was 0446 * terminated (e.g., out of memory). If application receives this 0447 * error code, it must stop using that :type:`nghttp2_session` 0448 * object and only allowed operation for that object is deallocate 0449 * it using `nghttp2_session_del()`. 0450 */ 0451 NGHTTP2_ERR_FATAL = -900, 0452 /** 0453 * Out of memory. This is a fatal error. 0454 */ 0455 NGHTTP2_ERR_NOMEM = -901, 0456 /** 0457 * The user callback function failed. This is a fatal error. 0458 */ 0459 NGHTTP2_ERR_CALLBACK_FAILURE = -902, 0460 /** 0461 * Invalid client magic (see :macro:`NGHTTP2_CLIENT_MAGIC`) was 0462 * received and further processing is not possible. 0463 */ 0464 NGHTTP2_ERR_BAD_CLIENT_MAGIC = -903, 0465 /** 0466 * Possible flooding by peer was detected in this HTTP/2 session. 0467 * Flooding is measured by how many PING and SETTINGS frames with 0468 * ACK flag set are queued for transmission. These frames are 0469 * response for the peer initiated frames, and peer can cause memory 0470 * exhaustion on server side to send these frames forever and does 0471 * not read network. 0472 */ 0473 NGHTTP2_ERR_FLOODED = -904, 0474 /** 0475 * When a local endpoint receives too many CONTINUATION frames 0476 * following a HEADER frame. 0477 */ 0478 NGHTTP2_ERR_TOO_MANY_CONTINUATIONS = -905, 0479 } nghttp2_error; 0480 0481 /** 0482 * @struct 0483 * 0484 * The object representing single contiguous buffer. 0485 */ 0486 typedef struct { 0487 /** 0488 * The pointer to the buffer. 0489 */ 0490 uint8_t *base; 0491 /** 0492 * The length of the buffer. 0493 */ 0494 size_t len; 0495 } nghttp2_vec; 0496 0497 struct nghttp2_rcbuf; 0498 0499 /** 0500 * @struct 0501 * 0502 * The object representing reference counted buffer. The details of 0503 * this structure are intentionally hidden from the public API. 0504 */ 0505 typedef struct nghttp2_rcbuf nghttp2_rcbuf; 0506 0507 /** 0508 * @function 0509 * 0510 * Increments the reference count of |rcbuf| by 1. 0511 */ 0512 NGHTTP2_EXTERN void nghttp2_rcbuf_incref(nghttp2_rcbuf *rcbuf); 0513 0514 /** 0515 * @function 0516 * 0517 * Decrements the reference count of |rcbuf| by 1. If the reference 0518 * count becomes zero, the object pointed by |rcbuf| will be freed. 0519 * In this case, application must not use |rcbuf| again. 0520 */ 0521 NGHTTP2_EXTERN void nghttp2_rcbuf_decref(nghttp2_rcbuf *rcbuf); 0522 0523 /** 0524 * @function 0525 * 0526 * Returns the underlying buffer managed by |rcbuf|. 0527 */ 0528 NGHTTP2_EXTERN nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf); 0529 0530 /** 0531 * @function 0532 * 0533 * Returns nonzero if the underlying buffer is statically allocated, 0534 * and 0 otherwise. This can be useful for language bindings that wish 0535 * to avoid creating duplicate strings for these buffers. 0536 */ 0537 NGHTTP2_EXTERN int nghttp2_rcbuf_is_static(const nghttp2_rcbuf *rcbuf); 0538 0539 /** 0540 * @enum 0541 * 0542 * The flags for header field name/value pair. 0543 */ 0544 typedef enum { 0545 /** 0546 * No flag set. 0547 */ 0548 NGHTTP2_NV_FLAG_NONE = 0, 0549 /** 0550 * Indicates that this name/value pair must not be indexed ("Literal 0551 * Header Field never Indexed" representation must be used in HPACK 0552 * encoding). Other implementation calls this bit as "sensitive". 0553 */ 0554 NGHTTP2_NV_FLAG_NO_INDEX = 0x01, 0555 /** 0556 * This flag is set solely by application. If this flag is set, the 0557 * library does not make a copy of header field name. This could 0558 * improve performance. 0559 */ 0560 NGHTTP2_NV_FLAG_NO_COPY_NAME = 0x02, 0561 /** 0562 * This flag is set solely by application. If this flag is set, the 0563 * library does not make a copy of header field value. This could 0564 * improve performance. 0565 */ 0566 NGHTTP2_NV_FLAG_NO_COPY_VALUE = 0x04 0567 } nghttp2_nv_flag; 0568 0569 /** 0570 * @struct 0571 * 0572 * The name/value pair, which mainly used to represent header fields. 0573 */ 0574 typedef struct { 0575 /** 0576 * The |name| byte string. If this struct is presented from library 0577 * (e.g., :type:`nghttp2_on_frame_recv_callback`), |name| is 0578 * guaranteed to be NULL-terminated. For some callbacks 0579 * (:type:`nghttp2_before_frame_send_callback`, 0580 * :type:`nghttp2_on_frame_send_callback`, and 0581 * :type:`nghttp2_on_frame_not_send_callback`), it may not be 0582 * NULL-terminated if header field is passed from application with 0583 * the flag :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`). 0584 * When application is constructing this struct, |name| is not 0585 * required to be NULL-terminated. 0586 */ 0587 uint8_t *name; 0588 /** 0589 * The |value| byte string. If this struct is presented from 0590 * library (e.g., :type:`nghttp2_on_frame_recv_callback`), |value| 0591 * is guaranteed to be NULL-terminated. For some callbacks 0592 * (:type:`nghttp2_before_frame_send_callback`, 0593 * :type:`nghttp2_on_frame_send_callback`, and 0594 * :type:`nghttp2_on_frame_not_send_callback`), it may not be 0595 * NULL-terminated if header field is passed from application with 0596 * the flag :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE`). 0597 * When application is constructing this struct, |value| is not 0598 * required to be NULL-terminated. 0599 */ 0600 uint8_t *value; 0601 /** 0602 * The length of the |name|, excluding terminating NULL. 0603 */ 0604 size_t namelen; 0605 /** 0606 * The length of the |value|, excluding terminating NULL. 0607 */ 0608 size_t valuelen; 0609 /** 0610 * Bitwise OR of one or more of :type:`nghttp2_nv_flag`. 0611 */ 0612 uint8_t flags; 0613 } nghttp2_nv; 0614 0615 /** 0616 * @enum 0617 * 0618 * The frame types in HTTP/2 specification. 0619 */ 0620 typedef enum { 0621 /** 0622 * The DATA frame. 0623 */ 0624 NGHTTP2_DATA = 0, 0625 /** 0626 * The HEADERS frame. 0627 */ 0628 NGHTTP2_HEADERS = 0x01, 0629 /** 0630 * The PRIORITY frame. 0631 */ 0632 NGHTTP2_PRIORITY = 0x02, 0633 /** 0634 * The RST_STREAM frame. 0635 */ 0636 NGHTTP2_RST_STREAM = 0x03, 0637 /** 0638 * The SETTINGS frame. 0639 */ 0640 NGHTTP2_SETTINGS = 0x04, 0641 /** 0642 * The PUSH_PROMISE frame. 0643 */ 0644 NGHTTP2_PUSH_PROMISE = 0x05, 0645 /** 0646 * The PING frame. 0647 */ 0648 NGHTTP2_PING = 0x06, 0649 /** 0650 * The GOAWAY frame. 0651 */ 0652 NGHTTP2_GOAWAY = 0x07, 0653 /** 0654 * The WINDOW_UPDATE frame. 0655 */ 0656 NGHTTP2_WINDOW_UPDATE = 0x08, 0657 /** 0658 * The CONTINUATION frame. This frame type won't be passed to any 0659 * callbacks because the library processes this frame type and its 0660 * preceding HEADERS/PUSH_PROMISE as a single frame. 0661 */ 0662 NGHTTP2_CONTINUATION = 0x09, 0663 /** 0664 * The ALTSVC frame, which is defined in `RFC 7383 0665 * <https://tools.ietf.org/html/rfc7838#section-4>`_. 0666 */ 0667 NGHTTP2_ALTSVC = 0x0a, 0668 /** 0669 * The ORIGIN frame, which is defined by `RFC 8336 0670 * <https://tools.ietf.org/html/rfc8336>`_. 0671 */ 0672 NGHTTP2_ORIGIN = 0x0c, 0673 /** 0674 * The PRIORITY_UPDATE frame, which is defined by :rfc:`9218`. 0675 */ 0676 NGHTTP2_PRIORITY_UPDATE = 0x10 0677 } nghttp2_frame_type; 0678 0679 /** 0680 * @enum 0681 * 0682 * The flags for HTTP/2 frames. This enum defines all flags for all 0683 * frames. 0684 */ 0685 typedef enum { 0686 /** 0687 * No flag set. 0688 */ 0689 NGHTTP2_FLAG_NONE = 0, 0690 /** 0691 * The END_STREAM flag. 0692 */ 0693 NGHTTP2_FLAG_END_STREAM = 0x01, 0694 /** 0695 * The END_HEADERS flag. 0696 */ 0697 NGHTTP2_FLAG_END_HEADERS = 0x04, 0698 /** 0699 * The ACK flag. 0700 */ 0701 NGHTTP2_FLAG_ACK = 0x01, 0702 /** 0703 * The PADDED flag. 0704 */ 0705 NGHTTP2_FLAG_PADDED = 0x08, 0706 /** 0707 * The PRIORITY flag. 0708 */ 0709 NGHTTP2_FLAG_PRIORITY = 0x20 0710 } nghttp2_flag; 0711 0712 /** 0713 * @enum 0714 * The SETTINGS ID. 0715 */ 0716 typedef enum { 0717 /** 0718 * SETTINGS_HEADER_TABLE_SIZE 0719 */ 0720 NGHTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x01, 0721 /** 0722 * SETTINGS_ENABLE_PUSH 0723 */ 0724 NGHTTP2_SETTINGS_ENABLE_PUSH = 0x02, 0725 /** 0726 * SETTINGS_MAX_CONCURRENT_STREAMS 0727 */ 0728 NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x03, 0729 /** 0730 * SETTINGS_INITIAL_WINDOW_SIZE 0731 */ 0732 NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x04, 0733 /** 0734 * SETTINGS_MAX_FRAME_SIZE 0735 */ 0736 NGHTTP2_SETTINGS_MAX_FRAME_SIZE = 0x05, 0737 /** 0738 * SETTINGS_MAX_HEADER_LIST_SIZE 0739 */ 0740 NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x06, 0741 /** 0742 * SETTINGS_ENABLE_CONNECT_PROTOCOL 0743 * (`RFC 8441 <https://tools.ietf.org/html/rfc8441>`_) 0744 */ 0745 NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL = 0x08, 0746 /** 0747 * SETTINGS_NO_RFC7540_PRIORITIES (:rfc:`9218`) 0748 */ 0749 NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES = 0x09 0750 } nghttp2_settings_id; 0751 /* Note: If we add SETTINGS, update the capacity of 0752 NGHTTP2_INBOUND_NUM_IV as well */ 0753 0754 /** 0755 * @macro 0756 * 0757 * .. warning:: 0758 * 0759 * Deprecated. The initial max concurrent streams is 0xffffffffu. 0760 * 0761 * Default maximum number of incoming concurrent streams. Use 0762 * `nghttp2_submit_settings()` with 0763 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS` 0764 * to change the maximum number of incoming concurrent streams. 0765 * 0766 * .. note:: 0767 * 0768 * The maximum number of outgoing concurrent streams is 100 by 0769 * default. 0770 */ 0771 #define NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1) 0772 0773 /** 0774 * @enum 0775 * The status codes for the RST_STREAM and GOAWAY frames. 0776 */ 0777 typedef enum { 0778 /** 0779 * No errors. 0780 */ 0781 NGHTTP2_NO_ERROR = 0x00, 0782 /** 0783 * PROTOCOL_ERROR 0784 */ 0785 NGHTTP2_PROTOCOL_ERROR = 0x01, 0786 /** 0787 * INTERNAL_ERROR 0788 */ 0789 NGHTTP2_INTERNAL_ERROR = 0x02, 0790 /** 0791 * FLOW_CONTROL_ERROR 0792 */ 0793 NGHTTP2_FLOW_CONTROL_ERROR = 0x03, 0794 /** 0795 * SETTINGS_TIMEOUT 0796 */ 0797 NGHTTP2_SETTINGS_TIMEOUT = 0x04, 0798 /** 0799 * STREAM_CLOSED 0800 */ 0801 NGHTTP2_STREAM_CLOSED = 0x05, 0802 /** 0803 * FRAME_SIZE_ERROR 0804 */ 0805 NGHTTP2_FRAME_SIZE_ERROR = 0x06, 0806 /** 0807 * REFUSED_STREAM 0808 */ 0809 NGHTTP2_REFUSED_STREAM = 0x07, 0810 /** 0811 * CANCEL 0812 */ 0813 NGHTTP2_CANCEL = 0x08, 0814 /** 0815 * COMPRESSION_ERROR 0816 */ 0817 NGHTTP2_COMPRESSION_ERROR = 0x09, 0818 /** 0819 * CONNECT_ERROR 0820 */ 0821 NGHTTP2_CONNECT_ERROR = 0x0a, 0822 /** 0823 * ENHANCE_YOUR_CALM 0824 */ 0825 NGHTTP2_ENHANCE_YOUR_CALM = 0x0b, 0826 /** 0827 * INADEQUATE_SECURITY 0828 */ 0829 NGHTTP2_INADEQUATE_SECURITY = 0x0c, 0830 /** 0831 * HTTP_1_1_REQUIRED 0832 */ 0833 NGHTTP2_HTTP_1_1_REQUIRED = 0x0d 0834 } nghttp2_error_code; 0835 0836 /** 0837 * @struct 0838 * The frame header. 0839 */ 0840 typedef struct { 0841 /** 0842 * The length field of this frame, excluding frame header. 0843 */ 0844 size_t length; 0845 /** 0846 * The stream identifier (aka, stream ID) 0847 */ 0848 int32_t stream_id; 0849 /** 0850 * The type of this frame. See `nghttp2_frame_type`. 0851 */ 0852 uint8_t type; 0853 /** 0854 * The flags. 0855 */ 0856 uint8_t flags; 0857 /** 0858 * Reserved bit in frame header. Currently, this is always set to 0 0859 * and application should not expect something useful in here. 0860 */ 0861 uint8_t reserved; 0862 } nghttp2_frame_hd; 0863 0864 /** 0865 * @union 0866 * 0867 * This union represents the some kind of data source passed to 0868 * :type:`nghttp2_data_source_read_callback2`. 0869 */ 0870 typedef union { 0871 /** 0872 * The integer field, suitable for a file descriptor. 0873 */ 0874 int fd; 0875 /** 0876 * The pointer to an arbitrary object. 0877 */ 0878 void *ptr; 0879 } nghttp2_data_source; 0880 0881 /** 0882 * @enum 0883 * 0884 * The flags used to set in |data_flags| output parameter in 0885 * :type:`nghttp2_data_source_read_callback2`. 0886 */ 0887 typedef enum { 0888 /** 0889 * No flag set. 0890 */ 0891 NGHTTP2_DATA_FLAG_NONE = 0, 0892 /** 0893 * Indicates EOF was sensed. 0894 */ 0895 NGHTTP2_DATA_FLAG_EOF = 0x01, 0896 /** 0897 * Indicates that END_STREAM flag must not be set even if 0898 * NGHTTP2_DATA_FLAG_EOF is set. Usually this flag is used to send 0899 * trailer fields with `nghttp2_submit_request2()` or 0900 * `nghttp2_submit_response2()`. 0901 */ 0902 NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02, 0903 /** 0904 * Indicates that application will send complete DATA frame in 0905 * :type:`nghttp2_send_data_callback`. 0906 */ 0907 NGHTTP2_DATA_FLAG_NO_COPY = 0x04 0908 } nghttp2_data_flag; 0909 0910 #ifndef NGHTTP2_NO_SSIZE_T 0911 /** 0912 * @functypedef 0913 * 0914 * .. warning:: 0915 * 0916 * Deprecated. Use :type:`nghttp2_data_source_read_callback2` 0917 * instead. 0918 * 0919 * Callback function invoked when the library wants to read data from 0920 * the |source|. The read data is sent in the stream |stream_id|. 0921 * The implementation of this function must read at most |length| 0922 * bytes of data from |source| (or possibly other places) and store 0923 * them in |buf| and return number of data stored in |buf|. If EOF is 0924 * reached, set :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag 0925 * in |*data_flags|. 0926 * 0927 * Sometime it is desirable to avoid copying data into |buf| and let 0928 * application to send data directly. To achieve this, set 0929 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` to 0930 * |*data_flags| (and possibly other flags, just like when we do 0931 * copy), and return the number of bytes to send without copying data 0932 * into |buf|. The library, seeing 0933 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY`, will invoke 0934 * :type:`nghttp2_send_data_callback`. The application must send 0935 * complete DATA frame in that callback. 0936 * 0937 * If this callback is set by `nghttp2_submit_request()`, 0938 * `nghttp2_submit_response()` or `nghttp2_submit_headers()` and 0939 * `nghttp2_submit_data()` with flag parameter 0940 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` set, and 0941 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag is set to 0942 * |*data_flags|, DATA frame will have END_STREAM flag set. Usually, 0943 * this is expected behaviour and all are fine. One exception is send 0944 * trailer fields. You cannot send trailer fields after sending frame 0945 * with END_STREAM set. To avoid this problem, one can set 0946 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM` along 0947 * with :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` to signal the 0948 * library not to set END_STREAM in DATA frame. Then application can 0949 * use `nghttp2_submit_trailer()` to send trailer fields. 0950 * `nghttp2_submit_trailer()` can be called inside this callback. 0951 * 0952 * If the application wants to postpone DATA frames (e.g., 0953 * asynchronous I/O, or reading data blocks for long time), it is 0954 * achieved by returning :enum:`nghttp2_error.NGHTTP2_ERR_DEFERRED` 0955 * without reading any data in this invocation. The library removes 0956 * DATA frame from the outgoing queue temporarily. To move back 0957 * deferred DATA frame to outgoing queue, call 0958 * `nghttp2_session_resume_data()`. 0959 * 0960 * By default, |length| is limited to 16KiB at maximum. If peer 0961 * allows larger frames, application can enlarge transmission buffer 0962 * size. See :type:`nghttp2_data_source_read_length_callback` for 0963 * more details. 0964 * 0965 * If the application just wants to return from 0966 * `nghttp2_session_send()` or `nghttp2_session_mem_send()` without 0967 * sending anything, return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. 0968 * 0969 * In case of error, there are 2 choices. Returning 0970 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will 0971 * close the stream by issuing RST_STREAM with 0972 * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. If a different 0973 * error code is desirable, use `nghttp2_submit_rst_stream()` with a 0974 * desired error code and then return 0975 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 0976 * Returning :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will 0977 * signal the entire session failure. 0978 */ 0979 typedef ssize_t (*nghttp2_data_source_read_callback)( 0980 nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, 0981 uint32_t *data_flags, nghttp2_data_source *source, void *user_data); 0982 0983 #endif /* NGHTTP2_NO_SSIZE_T */ 0984 0985 /** 0986 * @functypedef 0987 * 0988 * Callback function invoked when the library wants to read data from 0989 * the |source|. The read data is sent in the stream |stream_id|. 0990 * The implementation of this function must read at most |length| 0991 * bytes of data from |source| (or possibly other places) and store 0992 * them in |buf| and return number of data stored in |buf|. If EOF is 0993 * reached, set :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag 0994 * in |*data_flags|. 0995 * 0996 * Sometime it is desirable to avoid copying data into |buf| and let 0997 * application to send data directly. To achieve this, set 0998 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` to 0999 * |*data_flags| (and possibly other flags, just like when we do 1000 * copy), and return the number of bytes to send without copying data 1001 * into |buf|. The library, seeing 1002 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY`, will invoke 1003 * :type:`nghttp2_send_data_callback`. The application must send 1004 * complete DATA frame in that callback. 1005 * 1006 * If this callback is set by `nghttp2_submit_request2()`, 1007 * `nghttp2_submit_response2()` or `nghttp2_submit_headers()` and 1008 * `nghttp2_submit_data2()` with flag parameter 1009 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` set, and 1010 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag is set to 1011 * |*data_flags|, DATA frame will have END_STREAM flag set. Usually, 1012 * this is expected behaviour and all are fine. One exception is send 1013 * trailer fields. You cannot send trailer fields after sending frame 1014 * with END_STREAM set. To avoid this problem, one can set 1015 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM` along 1016 * with :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` to signal the 1017 * library not to set END_STREAM in DATA frame. Then application can 1018 * use `nghttp2_submit_trailer()` to send trailer fields. 1019 * `nghttp2_submit_trailer()` can be called inside this callback. 1020 * 1021 * If the application wants to postpone DATA frames (e.g., 1022 * asynchronous I/O, or reading data blocks for long time), it is 1023 * achieved by returning :enum:`nghttp2_error.NGHTTP2_ERR_DEFERRED` 1024 * without reading any data in this invocation. The library removes 1025 * DATA frame from the outgoing queue temporarily. To move back 1026 * deferred DATA frame to outgoing queue, call 1027 * `nghttp2_session_resume_data()`. 1028 * 1029 * By default, |length| is limited to 16KiB at maximum. If peer 1030 * allows larger frames, application can enlarge transmission buffer 1031 * size. See :type:`nghttp2_data_source_read_length_callback` for 1032 * more details. 1033 * 1034 * If the application just wants to return from 1035 * `nghttp2_session_send()` or `nghttp2_session_mem_send2()` without 1036 * sending anything, return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. 1037 * 1038 * In case of error, there are 2 choices. Returning 1039 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will 1040 * close the stream by issuing RST_STREAM with 1041 * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. If a different 1042 * error code is desirable, use `nghttp2_submit_rst_stream()` with a 1043 * desired error code and then return 1044 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 1045 * Returning :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will 1046 * signal the entire session failure. 1047 */ 1048 typedef nghttp2_ssize (*nghttp2_data_source_read_callback2)( 1049 nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, 1050 uint32_t *data_flags, nghttp2_data_source *source, void *user_data); 1051 1052 #ifndef NGHTTP2_NO_SSIZE_T 1053 /** 1054 * @struct 1055 * 1056 * .. warning:: 1057 * 1058 * Deprecated. Use :type:`nghttp2_data_provider2` instead. 1059 * 1060 * This struct represents the data source and the way to read a chunk 1061 * of data from it. 1062 */ 1063 typedef struct { 1064 /** 1065 * The data source. 1066 */ 1067 nghttp2_data_source source; 1068 /** 1069 * The callback function to read a chunk of data from the |source|. 1070 */ 1071 nghttp2_data_source_read_callback read_callback; 1072 } nghttp2_data_provider; 1073 1074 #endif /* NGHTTP2_NO_SSIZE_T */ 1075 1076 /** 1077 * @struct 1078 * 1079 * This struct represents the data source and the way to read a chunk 1080 * of data from it. 1081 */ 1082 typedef struct { 1083 /** 1084 * The data source. 1085 */ 1086 nghttp2_data_source source; 1087 /** 1088 * The callback function to read a chunk of data from the |source|. 1089 */ 1090 nghttp2_data_source_read_callback2 read_callback; 1091 } nghttp2_data_provider2; 1092 1093 /** 1094 * @struct 1095 * 1096 * The DATA frame. The received data is delivered via 1097 * :type:`nghttp2_on_data_chunk_recv_callback`. 1098 */ 1099 typedef struct { 1100 nghttp2_frame_hd hd; 1101 /** 1102 * The length of the padding in this frame. This includes PAD_HIGH 1103 * and PAD_LOW. 1104 */ 1105 size_t padlen; 1106 } nghttp2_data; 1107 1108 /** 1109 * @enum 1110 * 1111 * The category of HEADERS, which indicates the role of the frame. In 1112 * HTTP/2 spec, request, response, push response and other arbitrary 1113 * headers (e.g., trailer fields) are all called just HEADERS. To 1114 * give the application the role of incoming HEADERS frame, we define 1115 * several categories. 1116 */ 1117 typedef enum { 1118 /** 1119 * The HEADERS frame is opening new stream, which is analogous to 1120 * SYN_STREAM in SPDY. 1121 */ 1122 NGHTTP2_HCAT_REQUEST = 0, 1123 /** 1124 * The HEADERS frame is the first response headers, which is 1125 * analogous to SYN_REPLY in SPDY. 1126 */ 1127 NGHTTP2_HCAT_RESPONSE = 1, 1128 /** 1129 * The HEADERS frame is the first headers sent against reserved 1130 * stream. 1131 */ 1132 NGHTTP2_HCAT_PUSH_RESPONSE = 2, 1133 /** 1134 * The HEADERS frame which does not apply for the above categories, 1135 * which is analogous to HEADERS in SPDY. If non-final response 1136 * (e.g., status 1xx) is used, final response HEADERS frame will be 1137 * categorized here. 1138 */ 1139 NGHTTP2_HCAT_HEADERS = 3 1140 } nghttp2_headers_category; 1141 1142 /** 1143 * @struct 1144 * 1145 * .. warning:: 1146 * 1147 * Deprecated. :rfc:`7540` priorities are deprecated by 1148 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 1149 * prioritization scheme. 1150 * 1151 * The structure to specify stream dependency. 1152 */ 1153 typedef struct { 1154 /** 1155 * The stream ID of the stream to depend on. Specifying 0 makes 1156 * stream not depend any other stream. 1157 */ 1158 int32_t stream_id; 1159 /** 1160 * The weight of this dependency. 1161 */ 1162 int32_t weight; 1163 /** 1164 * nonzero means exclusive dependency 1165 */ 1166 uint8_t exclusive; 1167 } nghttp2_priority_spec; 1168 1169 /** 1170 * @struct 1171 * 1172 * The HEADERS frame. It has the following members: 1173 */ 1174 typedef struct { 1175 /** 1176 * The frame header. 1177 */ 1178 nghttp2_frame_hd hd; 1179 /** 1180 * The length of the padding in this frame. This includes PAD_HIGH 1181 * and PAD_LOW. 1182 */ 1183 size_t padlen; 1184 /** 1185 * .. warning:: 1186 * 1187 * Deprecated. :rfc:`7540` priorities are deprecated by 1188 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 1189 * prioritization scheme. 1190 * 1191 * The priority specification 1192 */ 1193 nghttp2_priority_spec pri_spec; 1194 /** 1195 * The name/value pairs. 1196 */ 1197 nghttp2_nv *nva; 1198 /** 1199 * The number of name/value pairs in |nva|. 1200 */ 1201 size_t nvlen; 1202 /** 1203 * The category of this HEADERS frame. 1204 */ 1205 nghttp2_headers_category cat; 1206 } nghttp2_headers; 1207 1208 /** 1209 * @struct 1210 * 1211 * .. warning:: 1212 * 1213 * Deprecated. :rfc:`7540` priorities are deprecated by 1214 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 1215 * prioritization scheme. 1216 * 1217 * The PRIORITY frame. It has the following members: 1218 */ 1219 typedef struct { 1220 /** 1221 * The frame header. 1222 */ 1223 nghttp2_frame_hd hd; 1224 /** 1225 * The priority specification. 1226 */ 1227 nghttp2_priority_spec pri_spec; 1228 } nghttp2_priority; 1229 1230 /** 1231 * @struct 1232 * 1233 * The RST_STREAM frame. It has the following members: 1234 */ 1235 typedef struct { 1236 /** 1237 * The frame header. 1238 */ 1239 nghttp2_frame_hd hd; 1240 /** 1241 * The error code. See :type:`nghttp2_error_code`. 1242 */ 1243 uint32_t error_code; 1244 } nghttp2_rst_stream; 1245 1246 /** 1247 * @struct 1248 * 1249 * The SETTINGS ID/Value pair. It has the following members: 1250 */ 1251 typedef struct { 1252 /** 1253 * The SETTINGS ID. See :type:`nghttp2_settings_id`. 1254 */ 1255 int32_t settings_id; 1256 /** 1257 * The value of this entry. 1258 */ 1259 uint32_t value; 1260 } nghttp2_settings_entry; 1261 1262 /** 1263 * @struct 1264 * 1265 * The SETTINGS frame. It has the following members: 1266 */ 1267 typedef struct { 1268 /** 1269 * The frame header. 1270 */ 1271 nghttp2_frame_hd hd; 1272 /** 1273 * The number of SETTINGS ID/Value pairs in |iv|. 1274 */ 1275 size_t niv; 1276 /** 1277 * The pointer to the array of SETTINGS ID/Value pair. 1278 */ 1279 nghttp2_settings_entry *iv; 1280 } nghttp2_settings; 1281 1282 /** 1283 * @struct 1284 * 1285 * The PUSH_PROMISE frame. It has the following members: 1286 */ 1287 typedef struct { 1288 /** 1289 * The frame header. 1290 */ 1291 nghttp2_frame_hd hd; 1292 /** 1293 * The length of the padding in this frame. This includes PAD_HIGH 1294 * and PAD_LOW. 1295 */ 1296 size_t padlen; 1297 /** 1298 * The name/value pairs. 1299 */ 1300 nghttp2_nv *nva; 1301 /** 1302 * The number of name/value pairs in |nva|. 1303 */ 1304 size_t nvlen; 1305 /** 1306 * The promised stream ID 1307 */ 1308 int32_t promised_stream_id; 1309 /** 1310 * Reserved bit. Currently this is always set to 0 and application 1311 * should not expect something useful in here. 1312 */ 1313 uint8_t reserved; 1314 } nghttp2_push_promise; 1315 1316 /** 1317 * @struct 1318 * 1319 * The PING frame. It has the following members: 1320 */ 1321 typedef struct { 1322 /** 1323 * The frame header. 1324 */ 1325 nghttp2_frame_hd hd; 1326 /** 1327 * The opaque data 1328 */ 1329 uint8_t opaque_data[8]; 1330 } nghttp2_ping; 1331 1332 /** 1333 * @struct 1334 * 1335 * The GOAWAY frame. It has the following members: 1336 */ 1337 typedef struct { 1338 /** 1339 * The frame header. 1340 */ 1341 nghttp2_frame_hd hd; 1342 /** 1343 * The last stream stream ID. 1344 */ 1345 int32_t last_stream_id; 1346 /** 1347 * The error code. See :type:`nghttp2_error_code`. 1348 */ 1349 uint32_t error_code; 1350 /** 1351 * The additional debug data 1352 */ 1353 uint8_t *opaque_data; 1354 /** 1355 * The length of |opaque_data| member. 1356 */ 1357 size_t opaque_data_len; 1358 /** 1359 * Reserved bit. Currently this is always set to 0 and application 1360 * should not expect something useful in here. 1361 */ 1362 uint8_t reserved; 1363 } nghttp2_goaway; 1364 1365 /** 1366 * @struct 1367 * 1368 * The WINDOW_UPDATE frame. It has the following members: 1369 */ 1370 typedef struct { 1371 /** 1372 * The frame header. 1373 */ 1374 nghttp2_frame_hd hd; 1375 /** 1376 * The window size increment. 1377 */ 1378 int32_t window_size_increment; 1379 /** 1380 * Reserved bit. Currently this is always set to 0 and application 1381 * should not expect something useful in here. 1382 */ 1383 uint8_t reserved; 1384 } nghttp2_window_update; 1385 1386 /** 1387 * @struct 1388 * 1389 * The extension frame. It has following members: 1390 */ 1391 typedef struct { 1392 /** 1393 * The frame header. 1394 */ 1395 nghttp2_frame_hd hd; 1396 /** 1397 * The pointer to extension payload. The exact pointer type is 1398 * determined by hd.type. 1399 * 1400 * Currently, no extension is supported. This is a place holder for 1401 * the future extensions. 1402 */ 1403 void *payload; 1404 } nghttp2_extension; 1405 1406 /** 1407 * @union 1408 * 1409 * This union includes all frames to pass them to various function 1410 * calls as nghttp2_frame type. The CONTINUATION frame is omitted 1411 * from here because the library deals with it internally. 1412 */ 1413 typedef union { 1414 /** 1415 * The frame header, which is convenient to inspect frame header. 1416 */ 1417 nghttp2_frame_hd hd; 1418 /** 1419 * The DATA frame. 1420 */ 1421 nghttp2_data data; 1422 /** 1423 * The HEADERS frame. 1424 */ 1425 nghttp2_headers headers; 1426 /** 1427 * The PRIORITY frame. 1428 */ 1429 nghttp2_priority priority; 1430 /** 1431 * The RST_STREAM frame. 1432 */ 1433 nghttp2_rst_stream rst_stream; 1434 /** 1435 * The SETTINGS frame. 1436 */ 1437 nghttp2_settings settings; 1438 /** 1439 * The PUSH_PROMISE frame. 1440 */ 1441 nghttp2_push_promise push_promise; 1442 /** 1443 * The PING frame. 1444 */ 1445 nghttp2_ping ping; 1446 /** 1447 * The GOAWAY frame. 1448 */ 1449 nghttp2_goaway goaway; 1450 /** 1451 * The WINDOW_UPDATE frame. 1452 */ 1453 nghttp2_window_update window_update; 1454 /** 1455 * The extension frame. 1456 */ 1457 nghttp2_extension ext; 1458 } nghttp2_frame; 1459 1460 #ifndef NGHTTP2_NO_SSIZE_T 1461 /** 1462 * @functypedef 1463 * 1464 * .. warning:: 1465 * 1466 * Deprecated. Use :type:`nghttp2_send_callback2` instead. 1467 * 1468 * Callback function invoked when |session| wants to send data to the 1469 * remote peer. The implementation of this function must send at most 1470 * |length| bytes of data stored in |data|. The |flags| is currently 1471 * not used and always 0. It must return the number of bytes sent if 1472 * it succeeds. If it cannot send any single byte without blocking, 1473 * it must return :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. For 1474 * other errors, it must return 1475 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The 1476 * |user_data| pointer is the third argument passed in to the call to 1477 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1478 * 1479 * This callback is required if the application uses 1480 * `nghttp2_session_send()` to send data to the remote endpoint. If 1481 * the application uses solely `nghttp2_session_mem_send()` instead, 1482 * this callback function is unnecessary. 1483 * 1484 * To set this callback to :type:`nghttp2_session_callbacks`, use 1485 * `nghttp2_session_callbacks_set_send_callback()`. 1486 * 1487 * .. note:: 1488 * 1489 * The |length| may be very small. If that is the case, and 1490 * application disables Nagle algorithm (``TCP_NODELAY``), then just 1491 * writing |data| to the network stack leads to very small packet, 1492 * and it is very inefficient. An application should be responsible 1493 * to buffer up small chunks of data as necessary to avoid this 1494 * situation. 1495 */ 1496 typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session, 1497 const uint8_t *data, size_t length, 1498 int flags, void *user_data); 1499 1500 #endif /* NGHTTP2_NO_SSIZE_T */ 1501 1502 /** 1503 * @functypedef 1504 * 1505 * Callback function invoked when |session| wants to send data to the 1506 * remote peer. The implementation of this function must send at most 1507 * |length| bytes of data stored in |data|. The |flags| is currently 1508 * not used and always 0. It must return the number of bytes sent if 1509 * it succeeds. If it cannot send any single byte without blocking, 1510 * it must return :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. For 1511 * other errors, it must return 1512 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The 1513 * |user_data| pointer is the third argument passed in to the call to 1514 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1515 * 1516 * This callback is required if the application uses 1517 * `nghttp2_session_send()` to send data to the remote endpoint. If 1518 * the application uses solely `nghttp2_session_mem_send2()` instead, 1519 * this callback function is unnecessary. 1520 * 1521 * To set this callback to :type:`nghttp2_session_callbacks`, use 1522 * `nghttp2_session_callbacks_set_send_callback2()`. 1523 * 1524 * .. note:: 1525 * 1526 * The |length| may be very small. If that is the case, and 1527 * application disables Nagle algorithm (``TCP_NODELAY``), then just 1528 * writing |data| to the network stack leads to very small packet, 1529 * and it is very inefficient. An application should be responsible 1530 * to buffer up small chunks of data as necessary to avoid this 1531 * situation. 1532 */ 1533 typedef nghttp2_ssize (*nghttp2_send_callback2)(nghttp2_session *session, 1534 const uint8_t *data, 1535 size_t length, int flags, 1536 void *user_data); 1537 1538 /** 1539 * @functypedef 1540 * 1541 * Callback function invoked when 1542 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` is used in 1543 * :type:`nghttp2_data_source_read_callback` to send complete DATA 1544 * frame. 1545 * 1546 * The |frame| is a DATA frame to send. The |framehd| is the 1547 * serialized frame header (9 bytes). The |length| is the length of 1548 * application data to send (this does not include padding). The 1549 * |source| is the same pointer passed to 1550 * :type:`nghttp2_data_source_read_callback`. 1551 * 1552 * The application first must send frame header |framehd| of length 9 1553 * bytes. If ``frame->data.padlen > 0``, send 1 byte of value 1554 * ``frame->data.padlen - 1``. Then send exactly |length| bytes of 1555 * application data. Finally, if ``frame->data.padlen > 1``, send 1556 * ``frame->data.padlen - 1`` bytes of zero as padding. 1557 * 1558 * The application has to send complete DATA frame in this callback. 1559 * If all data were written successfully, return 0. 1560 * 1561 * If it cannot send any data at all, just return 1562 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`; the library will call 1563 * this callback with the same parameters later (It is recommended to 1564 * send complete DATA frame at once in this function to deal with 1565 * error; if partial frame data has already sent, it is impossible to 1566 * send another data in that state, and all we can do is tear down 1567 * connection). When data is fully processed, but application wants 1568 * to make `nghttp2_session_mem_send2()` or `nghttp2_session_send()` 1569 * return immediately without processing next frames, return 1570 * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. If application decided to 1571 * reset this stream, return 1572 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`, then 1573 * the library will send RST_STREAM with INTERNAL_ERROR as error code. 1574 * The application can also return 1575 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, which will 1576 * result in connection closure. Returning any other value is treated 1577 * as :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned. 1578 */ 1579 typedef int (*nghttp2_send_data_callback)(nghttp2_session *session, 1580 nghttp2_frame *frame, 1581 const uint8_t *framehd, size_t length, 1582 nghttp2_data_source *source, 1583 void *user_data); 1584 1585 #ifndef NGHTTP2_NO_SSIZE_T 1586 /** 1587 * @functypedef 1588 * 1589 * .. warning:: 1590 * 1591 * Deprecated. Use :type:`nghttp2_recv_callback2` instead. 1592 * 1593 * Callback function invoked when |session| wants to receive data from 1594 * the remote peer. The implementation of this function must read at 1595 * most |length| bytes of data and store it in |buf|. The |flags| is 1596 * currently not used and always 0. It must return the number of 1597 * bytes written in |buf| if it succeeds. If it cannot read any 1598 * single byte without blocking, it must return 1599 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF 1600 * before it reads any single byte, it must return 1601 * :enum:`nghttp2_error.NGHTTP2_ERR_EOF`. For other errors, it must 1602 * return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1603 * Returning 0 is treated as 1604 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. The |user_data| 1605 * pointer is the third argument passed in to the call to 1606 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1607 * 1608 * This callback is required if the application uses 1609 * `nghttp2_session_recv()` to receive data from the remote endpoint. 1610 * If the application uses solely `nghttp2_session_mem_recv()` 1611 * instead, this callback function is unnecessary. 1612 * 1613 * To set this callback to :type:`nghttp2_session_callbacks`, use 1614 * `nghttp2_session_callbacks_set_recv_callback()`. 1615 */ 1616 typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf, 1617 size_t length, int flags, 1618 void *user_data); 1619 1620 #endif /* NGHTTP2_NO_SSIZE_T */ 1621 1622 /** 1623 * @functypedef 1624 * 1625 * Callback function invoked when |session| wants to receive data from 1626 * the remote peer. The implementation of this function must read at 1627 * most |length| bytes of data and store it in |buf|. The |flags| is 1628 * currently not used and always 0. It must return the number of 1629 * bytes written in |buf| if it succeeds. If it cannot read any 1630 * single byte without blocking, it must return 1631 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF 1632 * before it reads any single byte, it must return 1633 * :enum:`nghttp2_error.NGHTTP2_ERR_EOF`. For other errors, it must 1634 * return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1635 * Returning 0 is treated as 1636 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. The |user_data| 1637 * pointer is the third argument passed in to the call to 1638 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1639 * 1640 * This callback is required if the application uses 1641 * `nghttp2_session_recv()` to receive data from the remote endpoint. 1642 * If the application uses solely `nghttp2_session_mem_recv2()` 1643 * instead, this callback function is unnecessary. 1644 * 1645 * To set this callback to :type:`nghttp2_session_callbacks`, use 1646 * `nghttp2_session_callbacks_set_recv_callback2()`. 1647 */ 1648 typedef nghttp2_ssize (*nghttp2_recv_callback2)(nghttp2_session *session, 1649 uint8_t *buf, size_t length, 1650 int flags, void *user_data); 1651 1652 /** 1653 * @functypedef 1654 * 1655 * Callback function invoked by `nghttp2_session_recv()` and 1656 * `nghttp2_session_mem_recv2()` when a frame is received. The 1657 * |user_data| pointer is the third argument passed in to the call to 1658 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1659 * 1660 * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen`` 1661 * member of their data structure are always ``NULL`` and 0 1662 * respectively. The header name/value pairs are emitted via 1663 * :type:`nghttp2_on_header_callback`. 1664 * 1665 * Only HEADERS and DATA frame can signal the end of incoming data. 1666 * If ``frame->hd.flags & NGHTTP2_FLAG_END_STREAM`` is nonzero, the 1667 * |frame| is the last frame from the remote peer in this stream. 1668 * 1669 * This callback won't be called for CONTINUATION frames. 1670 * HEADERS/PUSH_PROMISE + CONTINUATIONs are treated as single frame. 1671 * 1672 * The implementation of this function must return 0 if it succeeds. 1673 * If nonzero value is returned, it is treated as fatal error and 1674 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 1675 * functions immediately return 1676 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1677 * 1678 * To set this callback to :type:`nghttp2_session_callbacks`, use 1679 * `nghttp2_session_callbacks_set_on_frame_recv_callback()`. 1680 */ 1681 typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session, 1682 const nghttp2_frame *frame, 1683 void *user_data); 1684 1685 /** 1686 * @functypedef 1687 * 1688 * Callback function invoked by `nghttp2_session_recv()` and 1689 * `nghttp2_session_mem_recv2()` when an invalid non-DATA frame is 1690 * received. The error is indicated by the |lib_error_code|, which is 1691 * one of the values defined in :type:`nghttp2_error`. When this 1692 * callback function is invoked, the library automatically submits 1693 * either RST_STREAM or GOAWAY frame. The |user_data| pointer is the 1694 * third argument passed in to the call to 1695 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1696 * 1697 * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen`` 1698 * member of their data structure are always ``NULL`` and 0 1699 * respectively. 1700 * 1701 * The implementation of this function must return 0 if it succeeds. 1702 * If nonzero is returned, it is treated as fatal error and 1703 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 1704 * functions immediately return 1705 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1706 * 1707 * To set this callback to :type:`nghttp2_session_callbacks`, use 1708 * `nghttp2_session_callbacks_set_on_invalid_frame_recv_callback()`. 1709 */ 1710 typedef int (*nghttp2_on_invalid_frame_recv_callback)( 1711 nghttp2_session *session, const nghttp2_frame *frame, int lib_error_code, 1712 void *user_data); 1713 1714 /** 1715 * @functypedef 1716 * 1717 * Callback function invoked when a chunk of data in DATA frame is 1718 * received. The |stream_id| is the stream ID this DATA frame belongs 1719 * to. The |flags| is the flags of DATA frame which this data chunk 1720 * is contained. ``(flags & NGHTTP2_FLAG_END_STREAM) != 0`` does not 1721 * necessarily mean this chunk of data is the last one in the stream. 1722 * You should use :type:`nghttp2_on_frame_recv_callback` to know all 1723 * data frames are received. The |user_data| pointer is the third 1724 * argument passed in to the call to `nghttp2_session_client_new()` or 1725 * `nghttp2_session_server_new()`. 1726 * 1727 * If the application uses `nghttp2_session_mem_recv2()`, it can 1728 * return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make 1729 * `nghttp2_session_mem_recv2()` return without processing further 1730 * input bytes. The memory by pointed by the |data| is retained until 1731 * `nghttp2_session_mem_recv2()` or `nghttp2_session_recv()` is 1732 * called. The application must retain the input bytes which was used 1733 * to produce the |data| parameter, because it may refer to the memory 1734 * region included in the input bytes. 1735 * 1736 * The implementation of this function must return 0 if it succeeds. 1737 * If nonzero is returned, it is treated as fatal error, and 1738 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 1739 * functions immediately return 1740 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1741 * 1742 * To set this callback to :type:`nghttp2_session_callbacks`, use 1743 * `nghttp2_session_callbacks_set_on_data_chunk_recv_callback()`. 1744 */ 1745 typedef int (*nghttp2_on_data_chunk_recv_callback)(nghttp2_session *session, 1746 uint8_t flags, 1747 int32_t stream_id, 1748 const uint8_t *data, 1749 size_t len, void *user_data); 1750 1751 /** 1752 * @functypedef 1753 * 1754 * Callback function invoked just before the non-DATA frame |frame| is 1755 * sent. The |user_data| pointer is the third argument passed in to 1756 * the call to `nghttp2_session_client_new()` or 1757 * `nghttp2_session_server_new()`. 1758 * 1759 * The implementation of this function must return 0 if it succeeds. 1760 * It can also return :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL` to 1761 * cancel the transmission of the given frame. 1762 * 1763 * If there is a fatal error while executing this callback, the 1764 * implementation should return 1765 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, which makes 1766 * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` 1767 * functions immediately return 1768 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1769 * 1770 * If the other value is returned, it is treated as if 1771 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned. 1772 * But the implementation should not rely on this since the library 1773 * may define new return value to extend its capability. 1774 * 1775 * To set this callback to :type:`nghttp2_session_callbacks`, use 1776 * `nghttp2_session_callbacks_set_before_frame_send_callback()`. 1777 */ 1778 typedef int (*nghttp2_before_frame_send_callback)(nghttp2_session *session, 1779 const nghttp2_frame *frame, 1780 void *user_data); 1781 1782 /** 1783 * @functypedef 1784 * 1785 * Callback function invoked after the frame |frame| is sent. The 1786 * |user_data| pointer is the third argument passed in to the call to 1787 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1788 * 1789 * The implementation of this function must return 0 if it succeeds. 1790 * If nonzero is returned, it is treated as fatal error and 1791 * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` 1792 * functions immediately return 1793 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1794 * 1795 * To set this callback to :type:`nghttp2_session_callbacks`, use 1796 * `nghttp2_session_callbacks_set_on_frame_send_callback()`. 1797 */ 1798 typedef int (*nghttp2_on_frame_send_callback)(nghttp2_session *session, 1799 const nghttp2_frame *frame, 1800 void *user_data); 1801 1802 /** 1803 * @functypedef 1804 * 1805 * Callback function invoked after the non-DATA frame |frame| is not 1806 * sent because of the error. The error is indicated by the 1807 * |lib_error_code|, which is one of the values defined in 1808 * :type:`nghttp2_error`. The |user_data| pointer is the third 1809 * argument passed in to the call to `nghttp2_session_client_new()` or 1810 * `nghttp2_session_server_new()`. 1811 * 1812 * The implementation of this function must return 0 if it succeeds. 1813 * If nonzero is returned, it is treated as fatal error and 1814 * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` 1815 * functions immediately return 1816 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1817 * 1818 * `nghttp2_session_get_stream_user_data()` can be used to get 1819 * associated data. 1820 * 1821 * To set this callback to :type:`nghttp2_session_callbacks`, use 1822 * `nghttp2_session_callbacks_set_on_frame_not_send_callback()`. 1823 */ 1824 typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session, 1825 const nghttp2_frame *frame, 1826 int lib_error_code, 1827 void *user_data); 1828 1829 /** 1830 * @functypedef 1831 * 1832 * Callback function invoked when the stream |stream_id| is closed. 1833 * The reason of closure is indicated by the |error_code|. The 1834 * |error_code| is usually one of :enum:`nghttp2_error_code`, but that 1835 * is not guaranteed. The stream_user_data, which was specified in 1836 * `nghttp2_submit_request2()` or `nghttp2_submit_headers()`, is still 1837 * available in this function. The |user_data| pointer is the third 1838 * argument passed in to the call to `nghttp2_session_client_new()` or 1839 * `nghttp2_session_server_new()`. 1840 * 1841 * This function is also called for a stream in reserved state. 1842 * 1843 * The implementation of this function must return 0 if it succeeds. 1844 * If nonzero is returned, it is treated as fatal error and 1845 * `nghttp2_session_recv()`, `nghttp2_session_mem_recv2()`, 1846 * `nghttp2_session_send()`, and `nghttp2_session_mem_send2()` 1847 * functions immediately return 1848 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1849 * 1850 * To set this callback to :type:`nghttp2_session_callbacks`, use 1851 * `nghttp2_session_callbacks_set_on_stream_close_callback()`. 1852 */ 1853 typedef int (*nghttp2_on_stream_close_callback)(nghttp2_session *session, 1854 int32_t stream_id, 1855 uint32_t error_code, 1856 void *user_data); 1857 1858 /** 1859 * @functypedef 1860 * 1861 * Callback function invoked when the reception of header block in 1862 * HEADERS or PUSH_PROMISE is started. Each header name/value pair 1863 * will be emitted by :type:`nghttp2_on_header_callback`. 1864 * 1865 * The ``frame->hd.flags`` may not have 1866 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_HEADERS` flag set, which 1867 * indicates that one or more CONTINUATION frames are involved. But 1868 * the application does not need to care about that because the header 1869 * name/value pairs are emitted transparently regardless of 1870 * CONTINUATION frames. 1871 * 1872 * The server applications probably create an object to store 1873 * information about new stream if ``frame->hd.type == 1874 * NGHTTP2_HEADERS`` and ``frame->headers.cat == 1875 * NGHTTP2_HCAT_REQUEST``. If |session| is configured as server side, 1876 * ``frame->headers.cat`` is either ``NGHTTP2_HCAT_REQUEST`` 1877 * containing request headers or ``NGHTTP2_HCAT_HEADERS`` containing 1878 * trailer fields and never get PUSH_PROMISE in this callback. 1879 * 1880 * For the client applications, ``frame->hd.type`` is either 1881 * ``NGHTTP2_HEADERS`` or ``NGHTTP2_PUSH_PROMISE``. In case of 1882 * ``NGHTTP2_HEADERS``, ``frame->headers.cat == 1883 * NGHTTP2_HCAT_RESPONSE`` means that it is the first response 1884 * headers, but it may be non-final response which is indicated by 1xx 1885 * status code. In this case, there may be zero or more HEADERS frame 1886 * with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` which has 1887 * non-final response code and finally client gets exactly one HEADERS 1888 * frame with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` 1889 * containing final response headers (non-1xx status code). The 1890 * trailer fields also has ``frame->headers.cat == 1891 * NGHTTP2_HCAT_HEADERS`` which does not contain any status code. 1892 * 1893 * Returning 1894 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will 1895 * close the stream (promised stream if frame is PUSH_PROMISE) by 1896 * issuing RST_STREAM with 1897 * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. In this case, 1898 * :type:`nghttp2_on_header_callback` and 1899 * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a 1900 * different error code is desirable, use 1901 * `nghttp2_submit_rst_stream()` with a desired error code and then 1902 * return :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 1903 * Again, use ``frame->push_promise.promised_stream_id`` as stream_id 1904 * parameter in `nghttp2_submit_rst_stream()` if frame is 1905 * PUSH_PROMISE. 1906 * 1907 * The implementation of this function must return 0 if it succeeds. 1908 * It can return 1909 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` to 1910 * reset the stream (promised stream if frame is PUSH_PROMISE). For 1911 * critical errors, it must return 1912 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 1913 * value is returned, it is treated as if 1914 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned. If 1915 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned, 1916 * `nghttp2_session_mem_recv2()` function will immediately return 1917 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1918 * 1919 * To set this callback to :type:`nghttp2_session_callbacks`, use 1920 * `nghttp2_session_callbacks_set_on_begin_headers_callback()`. 1921 */ 1922 typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session, 1923 const nghttp2_frame *frame, 1924 void *user_data); 1925 1926 /** 1927 * @functypedef 1928 * 1929 * Callback function invoked when a header name/value pair is received 1930 * for the |frame|. The |name| of length |namelen| is header name. 1931 * The |value| of length |valuelen| is header value. The |flags| is 1932 * bitwise OR of one or more of :type:`nghttp2_nv_flag`. 1933 * 1934 * If :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_INDEX` is set in 1935 * |flags|, the receiver must not index this name/value pair when 1936 * forwarding it to the next hop. More specifically, "Literal Header 1937 * Field never Indexed" representation must be used in HPACK encoding. 1938 * 1939 * When this callback is invoked, ``frame->hd.type`` is either 1940 * :enum:`nghttp2_frame_type.NGHTTP2_HEADERS` or 1941 * :enum:`nghttp2_frame_type.NGHTTP2_PUSH_PROMISE`. After all header 1942 * name/value pairs are processed with this callback, and no error has 1943 * been detected, :type:`nghttp2_on_frame_recv_callback` will be 1944 * invoked. If there is an error in decompression, 1945 * :type:`nghttp2_on_frame_recv_callback` for the |frame| will not be 1946 * invoked. 1947 * 1948 * Both |name| and |value| are guaranteed to be NULL-terminated. The 1949 * |namelen| and |valuelen| do not include terminal NULL. If 1950 * `nghttp2_option_set_no_http_messaging()` is used with nonzero 1951 * value, NULL character may be included in |name| or |value| before 1952 * terminating NULL. 1953 * 1954 * Please note that unless `nghttp2_option_set_no_http_messaging()` is 1955 * used, nghttp2 library does perform validation against the |name| 1956 * and the |value| using `nghttp2_check_header_name()` and 1957 * `nghttp2_check_header_value()`. In addition to this, nghttp2 1958 * performs validation based on HTTP Messaging rule, which is briefly 1959 * explained in :ref:`http-messaging` section. 1960 * 1961 * If the application uses `nghttp2_session_mem_recv2()`, it can 1962 * return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make 1963 * `nghttp2_session_mem_recv2()` return without processing further 1964 * input bytes. The memory pointed by |frame|, |name| and |value| 1965 * parameters are retained until `nghttp2_session_mem_recv2()` or 1966 * `nghttp2_session_recv()` is called. The application must retain 1967 * the input bytes which was used to produce these parameters, because 1968 * it may refer to the memory region included in the input bytes. 1969 * 1970 * Returning 1971 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will 1972 * close the stream (promised stream if frame is PUSH_PROMISE) by 1973 * issuing RST_STREAM with 1974 * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. In this case, 1975 * :type:`nghttp2_on_header_callback` and 1976 * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a 1977 * different error code is desirable, use 1978 * `nghttp2_submit_rst_stream()` with a desired error code and then 1979 * return :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 1980 * Again, use ``frame->push_promise.promised_stream_id`` as stream_id 1981 * parameter in `nghttp2_submit_rst_stream()` if frame is 1982 * PUSH_PROMISE. 1983 * 1984 * The implementation of this function must return 0 if it succeeds. 1985 * It may return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` or 1986 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. For 1987 * other critical failures, it must return 1988 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 1989 * nonzero value is returned, it is treated as 1990 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If 1991 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned, 1992 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 1993 * functions immediately return 1994 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1995 * 1996 * To set this callback to :type:`nghttp2_session_callbacks`, use 1997 * `nghttp2_session_callbacks_set_on_header_callback()`. 1998 * 1999 * .. warning:: 2000 * 2001 * Application should properly limit the total buffer size to store 2002 * incoming header fields. Without it, peer may send large number 2003 * of header fields or large header fields to cause out of memory in 2004 * local endpoint. Due to how HPACK works, peer can do this 2005 * effectively without using much memory on their own. 2006 */ 2007 typedef int (*nghttp2_on_header_callback)(nghttp2_session *session, 2008 const nghttp2_frame *frame, 2009 const uint8_t *name, size_t namelen, 2010 const uint8_t *value, size_t valuelen, 2011 uint8_t flags, void *user_data); 2012 2013 /** 2014 * @functypedef 2015 * 2016 * Callback function invoked when a header name/value pair is received 2017 * for the |frame|. The |name| is header name. The |value| is header 2018 * value. The |flags| is bitwise OR of one or more of 2019 * :type:`nghttp2_nv_flag`. 2020 * 2021 * This callback behaves like :type:`nghttp2_on_header_callback`, 2022 * except that |name| and |value| are stored in reference counted 2023 * buffer. If application wishes to keep these references without 2024 * copying them, use `nghttp2_rcbuf_incref()` to increment their 2025 * reference count. It is the application's responsibility to call 2026 * `nghttp2_rcbuf_decref()` if they called `nghttp2_rcbuf_incref()` so 2027 * as not to leak memory. If the |session| is created by 2028 * `nghttp2_session_server_new3()` or `nghttp2_session_client_new3()`, 2029 * the function to free memory is the one belongs to the mem 2030 * parameter. As long as this free function alives, |name| and 2031 * |value| can live after |session| was destroyed. 2032 */ 2033 typedef int (*nghttp2_on_header_callback2)(nghttp2_session *session, 2034 const nghttp2_frame *frame, 2035 nghttp2_rcbuf *name, 2036 nghttp2_rcbuf *value, uint8_t flags, 2037 void *user_data); 2038 2039 /** 2040 * @functypedef 2041 * 2042 * Callback function invoked when an invalid header name/value pair is 2043 * received for the |frame|. 2044 * 2045 * The parameter and behaviour are similar to 2046 * :type:`nghttp2_on_header_callback`. The difference is that this 2047 * callback is only invoked when an invalid header name/value pair is 2048 * received which is treated as stream error if this callback returns 2049 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` and 2050 * :type:`nghttp2_on_invalid_header_callback2` is not set. Only 2051 * invalid regular header field are passed to this callback. In other 2052 * words, invalid pseudo header field is not passed to this callback. 2053 * Also header fields which includes upper cased latter are also 2054 * treated as error without passing them to this callback. 2055 * 2056 * This callback is only considered if HTTP messaging validation is 2057 * turned on (which is on by default, see 2058 * `nghttp2_option_set_no_http_messaging()`). 2059 * 2060 * With this callback, application inspects the incoming invalid 2061 * field, and it also can reset stream from this callback by returning 2062 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. By 2063 * default, the error code is 2064 * :enum:`nghttp2_error_code.NGHTTP2_PROTOCOL_ERROR`. To change the 2065 * error code, call `nghttp2_submit_rst_stream()` with the error code 2066 * of choice in addition to returning 2067 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 2068 * 2069 * If 0 is returned, the header field is ignored, and the stream is 2070 * not reset. 2071 */ 2072 typedef int (*nghttp2_on_invalid_header_callback)( 2073 nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, 2074 size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags, 2075 void *user_data); 2076 2077 /** 2078 * @functypedef 2079 * 2080 * Callback function invoked when an invalid header name/value pair is 2081 * received for the |frame|. 2082 * 2083 * The parameter and behaviour are similar to 2084 * :type:`nghttp2_on_header_callback2`. The difference is that this 2085 * callback is only invoked when an invalid header name/value pair is 2086 * received which is silently ignored if neither this callback nor 2087 * :type:`nghttp2_on_invalid_header_callback` is set. Only invalid 2088 * regular header field are passed to this callback. In other words, 2089 * invalid pseudo header field is not passed to this callback. Also 2090 * header fields which includes upper cased latter are also treated as 2091 * error without passing them to this callback. 2092 * 2093 * This callback is only considered if HTTP messaging validation is 2094 * turned on (which is on by default, see 2095 * `nghttp2_option_set_no_http_messaging()`). 2096 * 2097 * With this callback, application inspects the incoming invalid 2098 * field, and it also can reset stream from this callback by returning 2099 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. By 2100 * default, the error code is 2101 * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. To change the 2102 * error code, call `nghttp2_submit_rst_stream()` with the error code 2103 * of choice in addition to returning 2104 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 2105 */ 2106 typedef int (*nghttp2_on_invalid_header_callback2)( 2107 nghttp2_session *session, const nghttp2_frame *frame, nghttp2_rcbuf *name, 2108 nghttp2_rcbuf *value, uint8_t flags, void *user_data); 2109 2110 #ifndef NGHTTP2_NO_SSIZE_T 2111 /** 2112 * @functypedef 2113 * 2114 * .. warning:: 2115 * 2116 * Deprecated. Use :type:`nghttp2_select_padding_callback2` 2117 * instead. 2118 * 2119 * Callback function invoked when the library asks application how 2120 * many padding bytes are required for the transmission of the 2121 * |frame|. The application must choose the total length of payload 2122 * including padded bytes in range [frame->hd.length, max_payloadlen], 2123 * inclusive. Choosing number not in this range will be treated as 2124 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Returning 2125 * ``frame->hd.length`` means no padding is added. Returning 2126 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will make 2127 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions 2128 * immediately return 2129 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2130 * 2131 * To set this callback to :type:`nghttp2_session_callbacks`, use 2132 * `nghttp2_session_callbacks_set_select_padding_callback()`. 2133 */ 2134 typedef ssize_t (*nghttp2_select_padding_callback)(nghttp2_session *session, 2135 const nghttp2_frame *frame, 2136 size_t max_payloadlen, 2137 void *user_data); 2138 2139 #endif /* NGHTTP2_NO_SSIZE_T */ 2140 2141 /** 2142 * @functypedef 2143 * 2144 * Callback function invoked when the library asks application how 2145 * many padding bytes are required for the transmission of the 2146 * |frame|. The application must choose the total length of payload 2147 * including padded bytes in range [frame->hd.length, max_payloadlen], 2148 * inclusive. Choosing number not in this range will be treated as 2149 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Returning 2150 * ``frame->hd.length`` means no padding is added. Returning 2151 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will make 2152 * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` 2153 * functions immediately return 2154 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2155 * 2156 * To set this callback to :type:`nghttp2_session_callbacks`, use 2157 * `nghttp2_session_callbacks_set_select_padding_callback2()`. 2158 */ 2159 typedef nghttp2_ssize (*nghttp2_select_padding_callback2)( 2160 nghttp2_session *session, const nghttp2_frame *frame, size_t max_payloadlen, 2161 void *user_data); 2162 2163 #ifndef NGHTTP2_NO_SSIZE_T 2164 /** 2165 * @functypedef 2166 * 2167 * .. warning:: 2168 * 2169 * Deprecated. Use 2170 * :type:`nghttp2_data_source_read_length_callback2` instead. 2171 * 2172 * Callback function invoked when library wants to get max length of 2173 * data to send data to the remote peer. The implementation of this 2174 * function should return a value in the following range. [1, 2175 * min(|session_remote_window_size|, |stream_remote_window_size|, 2176 * |remote_max_frame_size|)]. If a value greater than this range is 2177 * returned than the max allow value will be used. Returning a value 2178 * smaller than this range is treated as 2179 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The 2180 * |frame_type| is provided for future extensibility and identifies 2181 * the type of frame (see :type:`nghttp2_frame_type`) for which to get 2182 * the length for. Currently supported frame types are: 2183 * :enum:`nghttp2_frame_type.NGHTTP2_DATA`. 2184 * 2185 * This callback can be used to control the length in bytes for which 2186 * :type:`nghttp2_data_source_read_callback` is allowed to send to the 2187 * remote endpoint. This callback is optional. Returning 2188 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will signal the 2189 * entire session failure. 2190 * 2191 * To set this callback to :type:`nghttp2_session_callbacks`, use 2192 * `nghttp2_session_callbacks_set_data_source_read_length_callback()`. 2193 */ 2194 typedef ssize_t (*nghttp2_data_source_read_length_callback)( 2195 nghttp2_session *session, uint8_t frame_type, int32_t stream_id, 2196 int32_t session_remote_window_size, int32_t stream_remote_window_size, 2197 uint32_t remote_max_frame_size, void *user_data); 2198 2199 #endif /* NGHTTP2_NO_SSIZE_T */ 2200 2201 /** 2202 * @functypedef 2203 * 2204 * Callback function invoked when library wants to get max length of 2205 * data to send data to the remote peer. The implementation of this 2206 * function should return a value in the following range. [1, 2207 * min(|session_remote_window_size|, |stream_remote_window_size|, 2208 * |remote_max_frame_size|)]. If a value greater than this range is 2209 * returned than the max allow value will be used. Returning a value 2210 * smaller than this range is treated as 2211 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The 2212 * |frame_type| is provided for future extensibility and identifies 2213 * the type of frame (see :type:`nghttp2_frame_type`) for which to get 2214 * the length for. Currently supported frame types are: 2215 * :enum:`nghttp2_frame_type.NGHTTP2_DATA`. 2216 * 2217 * This callback can be used to control the length in bytes for which 2218 * :type:`nghttp2_data_source_read_callback` is allowed to send to the 2219 * remote endpoint. This callback is optional. Returning 2220 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will signal the 2221 * entire session failure. 2222 * 2223 * To set this callback to :type:`nghttp2_session_callbacks`, use 2224 * `nghttp2_session_callbacks_set_data_source_read_length_callback2()`. 2225 */ 2226 typedef nghttp2_ssize (*nghttp2_data_source_read_length_callback2)( 2227 nghttp2_session *session, uint8_t frame_type, int32_t stream_id, 2228 int32_t session_remote_window_size, int32_t stream_remote_window_size, 2229 uint32_t remote_max_frame_size, void *user_data); 2230 2231 /** 2232 * @functypedef 2233 * 2234 * Callback function invoked when a frame header is received. The 2235 * |hd| points to received frame header. 2236 * 2237 * Unlike :type:`nghttp2_on_frame_recv_callback`, this callback will 2238 * also be called when frame header of CONTINUATION frame is received. 2239 * 2240 * If both :type:`nghttp2_on_begin_frame_callback` and 2241 * :type:`nghttp2_on_begin_headers_callback` are set and HEADERS or 2242 * PUSH_PROMISE is received, :type:`nghttp2_on_begin_frame_callback` 2243 * will be called first. 2244 * 2245 * The implementation of this function must return 0 if it succeeds. 2246 * If nonzero value is returned, it is treated as fatal error and 2247 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 2248 * functions immediately return 2249 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2250 * 2251 * To set this callback to :type:`nghttp2_session_callbacks`, use 2252 * `nghttp2_session_callbacks_set_on_begin_frame_callback()`. 2253 */ 2254 typedef int (*nghttp2_on_begin_frame_callback)(nghttp2_session *session, 2255 const nghttp2_frame_hd *hd, 2256 void *user_data); 2257 2258 /** 2259 * @functypedef 2260 * 2261 * Callback function invoked when chunk of extension frame payload is 2262 * received. The |hd| points to frame header. The received 2263 * chunk is |data| of length |len|. 2264 * 2265 * The implementation of this function must return 0 if it succeeds. 2266 * 2267 * To abort processing this extension frame, return 2268 * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`. 2269 * 2270 * If fatal error occurred, application should return 2271 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, 2272 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 2273 * functions immediately return 2274 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 2275 * values are returned, currently they are treated as 2276 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2277 */ 2278 typedef int (*nghttp2_on_extension_chunk_recv_callback)( 2279 nghttp2_session *session, const nghttp2_frame_hd *hd, const uint8_t *data, 2280 size_t len, void *user_data); 2281 2282 /** 2283 * @functypedef 2284 * 2285 * Callback function invoked when library asks the application to 2286 * unpack extension payload from its wire format. The extension 2287 * payload has been passed to the application using 2288 * :type:`nghttp2_on_extension_chunk_recv_callback`. The frame header 2289 * is already unpacked by the library and provided as |hd|. 2290 * 2291 * To receive extension frames, the application must tell desired 2292 * extension frame type to the library using 2293 * `nghttp2_option_set_user_recv_extension_type()`. 2294 * 2295 * The implementation of this function may store the pointer to the 2296 * created object as a result of unpacking in |*payload|, and returns 2297 * 0. The pointer stored in |*payload| is opaque to the library, and 2298 * the library does not own its pointer. |*payload| is initialized as 2299 * ``NULL``. The |*payload| is available as ``frame->ext.payload`` in 2300 * :type:`nghttp2_on_frame_recv_callback`. Therefore if application 2301 * can free that memory inside :type:`nghttp2_on_frame_recv_callback` 2302 * callback. Of course, application has a liberty not to use 2303 * |*payload|, and do its own mechanism to process extension frames. 2304 * 2305 * To abort processing this extension frame, return 2306 * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`. 2307 * 2308 * If fatal error occurred, application should return 2309 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, 2310 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 2311 * functions immediately return 2312 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 2313 * values are returned, currently they are treated as 2314 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2315 */ 2316 typedef int (*nghttp2_unpack_extension_callback)(nghttp2_session *session, 2317 void **payload, 2318 const nghttp2_frame_hd *hd, 2319 void *user_data); 2320 2321 #ifndef NGHTTP2_NO_SSIZE_T 2322 /** 2323 * @functypedef 2324 * 2325 * .. warning:: 2326 * 2327 * Deprecated. Use :type:`nghttp2_pack_extension_callback2` 2328 * instead. 2329 * 2330 * Callback function invoked when library asks the application to pack 2331 * extension payload in its wire format. The frame header will be 2332 * packed by library. Application must pack payload only. 2333 * ``frame->ext.payload`` is the object passed to 2334 * `nghttp2_submit_extension()` as payload parameter. Application 2335 * must pack extension payload to the |buf| of its capacity |len| 2336 * bytes. The |len| is at least 16KiB. 2337 * 2338 * The implementation of this function should return the number of 2339 * bytes written into |buf| when it succeeds. 2340 * 2341 * To abort processing this extension frame, return 2342 * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`, and 2343 * :type:`nghttp2_on_frame_not_send_callback` will be invoked. 2344 * 2345 * If fatal error occurred, application should return 2346 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, 2347 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions 2348 * immediately return 2349 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 2350 * values are returned, currently they are treated as 2351 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the return 2352 * value is strictly larger than |len|, it is treated as 2353 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2354 */ 2355 typedef ssize_t (*nghttp2_pack_extension_callback)(nghttp2_session *session, 2356 uint8_t *buf, size_t len, 2357 const nghttp2_frame *frame, 2358 void *user_data); 2359 2360 #endif /* NGHTTP2_NO_SSIZE_T */ 2361 2362 /** 2363 * @functypedef 2364 * 2365 * Callback function invoked when library asks the application to pack 2366 * extension payload in its wire format. The frame header will be 2367 * packed by library. Application must pack payload only. 2368 * ``frame->ext.payload`` is the object passed to 2369 * `nghttp2_submit_extension()` as payload parameter. Application 2370 * must pack extension payload to the |buf| of its capacity |len| 2371 * bytes. The |len| is at least 16KiB. 2372 * 2373 * The implementation of this function should return the number of 2374 * bytes written into |buf| when it succeeds. 2375 * 2376 * To abort processing this extension frame, return 2377 * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`, and 2378 * :type:`nghttp2_on_frame_not_send_callback` will be invoked. 2379 * 2380 * If fatal error occurred, application should return 2381 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, 2382 * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` 2383 * functions immediately return 2384 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 2385 * values are returned, currently they are treated as 2386 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the return 2387 * value is strictly larger than |len|, it is treated as 2388 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2389 */ 2390 typedef nghttp2_ssize (*nghttp2_pack_extension_callback2)( 2391 nghttp2_session *session, uint8_t *buf, size_t len, 2392 const nghttp2_frame *frame, void *user_data); 2393 2394 /** 2395 * @functypedef 2396 * 2397 * .. warning:: 2398 * 2399 * Deprecated. Use :type:`nghttp2_error_callback2` instead. 2400 * 2401 * Callback function invoked when library provides the error message 2402 * intended for human consumption. This callback is solely for 2403 * debugging purpose. The |msg| is typically NULL-terminated string 2404 * of length |len|. |len| does not include the sentinel NULL 2405 * character. 2406 * 2407 * The format of error message may change between nghttp2 library 2408 * versions. The application should not depend on the particular 2409 * format. 2410 * 2411 * Normally, application should return 0 from this callback. If fatal 2412 * error occurred while doing something in this callback, application 2413 * should return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2414 * In this case, library will return immediately with return value 2415 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if 2416 * nonzero value is returned from this callback, they are treated as 2417 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, but application 2418 * should not rely on this details. 2419 */ 2420 typedef int (*nghttp2_error_callback)(nghttp2_session *session, const char *msg, 2421 size_t len, void *user_data); 2422 2423 /** 2424 * @functypedef 2425 * 2426 * Callback function invoked when library provides the error code, and 2427 * message. This callback is solely for debugging purpose. 2428 * |lib_error_code| is one of error code defined in 2429 * :enum:`nghttp2_error`. The |msg| is typically NULL-terminated 2430 * string of length |len|, and intended for human consumption. |len| 2431 * does not include the sentinel NULL character. 2432 * 2433 * The format of error message may change between nghttp2 library 2434 * versions. The application should not depend on the particular 2435 * format. 2436 * 2437 * Normally, application should return 0 from this callback. If fatal 2438 * error occurred while doing something in this callback, application 2439 * should return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2440 * In this case, library will return immediately with return value 2441 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if 2442 * nonzero value is returned from this callback, they are treated as 2443 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, but application 2444 * should not rely on this details. 2445 */ 2446 typedef int (*nghttp2_error_callback2)(nghttp2_session *session, 2447 int lib_error_code, const char *msg, 2448 size_t len, void *user_data); 2449 2450 /** 2451 * @functypedef 2452 * 2453 * Callback function invoked when unpredictable data of |destlen| 2454 * bytes are needed. The implementation must write unpredictable data 2455 * of |destlen| bytes into the buffer pointed by |dest|. 2456 */ 2457 typedef void (*nghttp2_rand_callback)(uint8_t *dest, size_t destlen); 2458 2459 struct nghttp2_session_callbacks; 2460 2461 /** 2462 * @struct 2463 * 2464 * Callback functions for :type:`nghttp2_session`. The details of 2465 * this structure are intentionally hidden from the public API. 2466 */ 2467 typedef struct nghttp2_session_callbacks nghttp2_session_callbacks; 2468 2469 /** 2470 * @function 2471 * 2472 * Initializes |*callbacks_ptr| with NULL values. 2473 * 2474 * The initialized object can be used when initializing multiple 2475 * :type:`nghttp2_session` objects. 2476 * 2477 * When the application finished using this object, it can use 2478 * `nghttp2_session_callbacks_del()` to free its memory. 2479 * 2480 * This function returns 0 if it succeeds, or one of the following 2481 * negative error codes: 2482 * 2483 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 2484 * Out of memory. 2485 */ 2486 NGHTTP2_EXTERN int 2487 nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr); 2488 2489 /** 2490 * @function 2491 * 2492 * Frees any resources allocated for |callbacks|. If |callbacks| is 2493 * ``NULL``, this function does nothing. 2494 */ 2495 NGHTTP2_EXTERN void 2496 nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks); 2497 2498 #ifndef NGHTTP2_NO_SSIZE_T 2499 /** 2500 * @function 2501 * 2502 * .. warning:: 2503 * 2504 * Deprecated. Use `nghttp2_session_callbacks_set_send_callback2()` 2505 * with :type:`nghttp2_send_callback2` instead. 2506 * 2507 * Sets callback function invoked when a session wants to send data to 2508 * the remote peer. This callback is not necessary if the application 2509 * uses solely `nghttp2_session_mem_send()` to serialize data to 2510 * transmit. 2511 */ 2512 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback( 2513 nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback); 2514 2515 #endif /* NGHTTP2_NO_SSIZE_T */ 2516 2517 /** 2518 * @function 2519 * 2520 * Sets callback function invoked when a session wants to send data to 2521 * the remote peer. This callback is not necessary if the application 2522 * uses solely `nghttp2_session_mem_send2()` to serialize data to 2523 * transmit. 2524 */ 2525 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback2( 2526 nghttp2_session_callbacks *cbs, nghttp2_send_callback2 send_callback); 2527 2528 #ifndef NGHTTP2_NO_SSIZE_T 2529 /** 2530 * @function 2531 * 2532 * .. warning:: 2533 * 2534 * Deprecated. Use `nghttp2_session_callbacks_set_recv_callback2()` 2535 * with :type:`nghttp2_recv_callback2` instead. 2536 * 2537 * Sets callback function invoked when the a session wants to receive 2538 * data from the remote peer. This callback is not necessary if the 2539 * application uses solely `nghttp2_session_mem_recv()` to process 2540 * received data. 2541 */ 2542 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback( 2543 nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback); 2544 2545 #endif /* NGHTTP2_NO_SSIZE_T */ 2546 2547 /** 2548 * @function 2549 * 2550 * Sets callback function invoked when the a session wants to receive 2551 * data from the remote peer. This callback is not necessary if the 2552 * application uses solely `nghttp2_session_mem_recv2()` to process 2553 * received data. 2554 */ 2555 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback2( 2556 nghttp2_session_callbacks *cbs, nghttp2_recv_callback2 recv_callback); 2557 2558 /** 2559 * @function 2560 * 2561 * Sets callback function invoked by `nghttp2_session_recv()` and 2562 * `nghttp2_session_mem_recv2()` when a frame is received. 2563 */ 2564 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback( 2565 nghttp2_session_callbacks *cbs, 2566 nghttp2_on_frame_recv_callback on_frame_recv_callback); 2567 2568 /** 2569 * @function 2570 * 2571 * Sets callback function invoked by `nghttp2_session_recv()` and 2572 * `nghttp2_session_mem_recv2()` when an invalid non-DATA frame is 2573 * received. 2574 */ 2575 NGHTTP2_EXTERN void 2576 nghttp2_session_callbacks_set_on_invalid_frame_recv_callback( 2577 nghttp2_session_callbacks *cbs, 2578 nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback); 2579 2580 /** 2581 * @function 2582 * 2583 * Sets callback function invoked when a chunk of data in DATA frame 2584 * is received. 2585 */ 2586 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_data_chunk_recv_callback( 2587 nghttp2_session_callbacks *cbs, 2588 nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback); 2589 2590 /** 2591 * @function 2592 * 2593 * Sets callback function invoked before a non-DATA frame is sent. 2594 */ 2595 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_before_frame_send_callback( 2596 nghttp2_session_callbacks *cbs, 2597 nghttp2_before_frame_send_callback before_frame_send_callback); 2598 2599 /** 2600 * @function 2601 * 2602 * Sets callback function invoked after a frame is sent. 2603 */ 2604 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_send_callback( 2605 nghttp2_session_callbacks *cbs, 2606 nghttp2_on_frame_send_callback on_frame_send_callback); 2607 2608 /** 2609 * @function 2610 * 2611 * Sets callback function invoked when a non-DATA frame is not sent 2612 * because of an error. 2613 */ 2614 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_not_send_callback( 2615 nghttp2_session_callbacks *cbs, 2616 nghttp2_on_frame_not_send_callback on_frame_not_send_callback); 2617 2618 /** 2619 * @function 2620 * 2621 * Sets callback function invoked when the stream is closed. 2622 */ 2623 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_stream_close_callback( 2624 nghttp2_session_callbacks *cbs, 2625 nghttp2_on_stream_close_callback on_stream_close_callback); 2626 2627 /** 2628 * @function 2629 * 2630 * Sets callback function invoked when the reception of header block 2631 * in HEADERS or PUSH_PROMISE is started. 2632 */ 2633 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_headers_callback( 2634 nghttp2_session_callbacks *cbs, 2635 nghttp2_on_begin_headers_callback on_begin_headers_callback); 2636 2637 /** 2638 * @function 2639 * 2640 * Sets callback function invoked when a header name/value pair is 2641 * received. If both 2642 * `nghttp2_session_callbacks_set_on_header_callback()` and 2643 * `nghttp2_session_callbacks_set_on_header_callback2()` are used to 2644 * set callbacks, the latter has the precedence. 2645 */ 2646 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback( 2647 nghttp2_session_callbacks *cbs, 2648 nghttp2_on_header_callback on_header_callback); 2649 2650 /** 2651 * @function 2652 * 2653 * Sets callback function invoked when a header name/value pair is 2654 * received. 2655 */ 2656 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback2( 2657 nghttp2_session_callbacks *cbs, 2658 nghttp2_on_header_callback2 on_header_callback2); 2659 2660 /** 2661 * @function 2662 * 2663 * Sets callback function invoked when an invalid header name/value 2664 * pair is received. If both 2665 * `nghttp2_session_callbacks_set_on_invalid_header_callback()` and 2666 * `nghttp2_session_callbacks_set_on_invalid_header_callback2()` are 2667 * used to set callbacks, the latter takes the precedence. 2668 */ 2669 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback( 2670 nghttp2_session_callbacks *cbs, 2671 nghttp2_on_invalid_header_callback on_invalid_header_callback); 2672 2673 /** 2674 * @function 2675 * 2676 * Sets callback function invoked when an invalid header name/value 2677 * pair is received. 2678 */ 2679 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback2( 2680 nghttp2_session_callbacks *cbs, 2681 nghttp2_on_invalid_header_callback2 on_invalid_header_callback2); 2682 2683 #ifndef NGHTTP2_NO_SSIZE_T 2684 /** 2685 * @function 2686 * 2687 * .. warning:: 2688 * 2689 * Deprecated. Use 2690 * `nghttp2_session_callbacks_set_select_padding_callback2()` with 2691 * :type:`nghttp2_select_padding_callback2` instead. 2692 * 2693 * Sets callback function invoked when the library asks application 2694 * how many padding bytes are required for the transmission of the 2695 * given frame. 2696 */ 2697 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback( 2698 nghttp2_session_callbacks *cbs, 2699 nghttp2_select_padding_callback select_padding_callback); 2700 2701 #endif /* NGHTTP2_NO_SSIZE_T */ 2702 2703 /** 2704 * @function 2705 * 2706 * Sets callback function invoked when the library asks application 2707 * how many padding bytes are required for the transmission of the 2708 * given frame. 2709 */ 2710 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback2( 2711 nghttp2_session_callbacks *cbs, 2712 nghttp2_select_padding_callback2 select_padding_callback); 2713 2714 #ifndef NGHTTP2_NO_SSIZE_T 2715 /** 2716 * @function 2717 * 2718 * .. warning:: 2719 * 2720 * Deprecated. Use 2721 * `nghttp2_session_callbacks_set_data_source_read_length_callback2()` 2722 * with :type:`nghttp2_data_source_read_length_callback2` instead. 2723 * 2724 * Sets callback function determine the length allowed in 2725 * :type:`nghttp2_data_source_read_callback`. 2726 */ 2727 NGHTTP2_EXTERN void 2728 nghttp2_session_callbacks_set_data_source_read_length_callback( 2729 nghttp2_session_callbacks *cbs, 2730 nghttp2_data_source_read_length_callback data_source_read_length_callback); 2731 2732 #endif /* NGHTTP2_NO_SSIZE_T */ 2733 2734 /** 2735 * @function 2736 * 2737 * Sets callback function determine the length allowed in 2738 * :type:`nghttp2_data_source_read_callback2`. 2739 */ 2740 NGHTTP2_EXTERN void 2741 nghttp2_session_callbacks_set_data_source_read_length_callback2( 2742 nghttp2_session_callbacks *cbs, 2743 nghttp2_data_source_read_length_callback2 data_source_read_length_callback); 2744 2745 /** 2746 * @function 2747 * 2748 * Sets callback function invoked when a frame header is received. 2749 */ 2750 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_frame_callback( 2751 nghttp2_session_callbacks *cbs, 2752 nghttp2_on_begin_frame_callback on_begin_frame_callback); 2753 2754 /** 2755 * @function 2756 * 2757 * Sets callback function invoked when 2758 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` is used in 2759 * :type:`nghttp2_data_source_read_callback2` to avoid data copy. 2760 */ 2761 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_data_callback( 2762 nghttp2_session_callbacks *cbs, 2763 nghttp2_send_data_callback send_data_callback); 2764 2765 #ifndef NGHTTP2_NO_SSIZE_T 2766 /** 2767 * @function 2768 * 2769 * .. warning:: 2770 * 2771 * Deprecated. Use 2772 * `nghttp2_session_callbacks_set_pack_extension_callback2()` with 2773 * :type:`nghttp2_pack_extension_callback2` instead. 2774 * 2775 * Sets callback function invoked when the library asks the 2776 * application to pack extension frame payload in wire format. 2777 */ 2778 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback( 2779 nghttp2_session_callbacks *cbs, 2780 nghttp2_pack_extension_callback pack_extension_callback); 2781 2782 #endif /* NGHTTP2_NO_SSIZE_T */ 2783 2784 /** 2785 * @function 2786 * 2787 * Sets callback function invoked when the library asks the 2788 * application to pack extension frame payload in wire format. 2789 */ 2790 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback2( 2791 nghttp2_session_callbacks *cbs, 2792 nghttp2_pack_extension_callback2 pack_extension_callback); 2793 2794 /** 2795 * @function 2796 * 2797 * Sets callback function invoked when the library asks the 2798 * application to unpack extension frame payload from wire format. 2799 */ 2800 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_unpack_extension_callback( 2801 nghttp2_session_callbacks *cbs, 2802 nghttp2_unpack_extension_callback unpack_extension_callback); 2803 2804 /** 2805 * @function 2806 * 2807 * Sets callback function invoked when chunk of extension frame 2808 * payload is received. 2809 */ 2810 NGHTTP2_EXTERN void 2811 nghttp2_session_callbacks_set_on_extension_chunk_recv_callback( 2812 nghttp2_session_callbacks *cbs, 2813 nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback); 2814 2815 /** 2816 * @function 2817 * 2818 * .. warning:: 2819 * 2820 * Deprecated. Use 2821 * `nghttp2_session_callbacks_set_error_callback2()` with 2822 * :type:`nghttp2_error_callback2` instead. 2823 * 2824 * Sets callback function invoked when library tells error message to 2825 * the application. 2826 * 2827 * If both :type:`nghttp2_error_callback` and 2828 * :type:`nghttp2_error_callback2` are set, the latter takes 2829 * precedence. 2830 */ 2831 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback( 2832 nghttp2_session_callbacks *cbs, nghttp2_error_callback error_callback); 2833 2834 /** 2835 * @function 2836 * 2837 * Sets callback function invoked when library tells error code, and 2838 * message to the application. 2839 * 2840 * If both :type:`nghttp2_error_callback` and 2841 * :type:`nghttp2_error_callback2` are set, the latter takes 2842 * precedence. 2843 */ 2844 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback2( 2845 nghttp2_session_callbacks *cbs, nghttp2_error_callback2 error_callback2); 2846 2847 /** 2848 * @function 2849 * 2850 * Sets callback function invoked when unpredictable data is needed. 2851 * Although this callback is optional due to the backward 2852 * compatibility, it is recommended to specify it to harden the 2853 * runtime behavior against suspicious activities of a remote 2854 * endpoint. 2855 */ 2856 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_rand_callback( 2857 nghttp2_session_callbacks *cbs, nghttp2_rand_callback rand_callback); 2858 2859 /** 2860 * @functypedef 2861 * 2862 * Custom memory allocator to replace malloc(). The |mem_user_data| 2863 * is the mem_user_data member of :type:`nghttp2_mem` structure. 2864 */ 2865 typedef void *(*nghttp2_malloc)(size_t size, void *mem_user_data); 2866 2867 /** 2868 * @functypedef 2869 * 2870 * Custom memory allocator to replace free(). The |mem_user_data| is 2871 * the mem_user_data member of :type:`nghttp2_mem` structure. 2872 */ 2873 typedef void (*nghttp2_free)(void *ptr, void *mem_user_data); 2874 2875 /** 2876 * @functypedef 2877 * 2878 * Custom memory allocator to replace calloc(). The |mem_user_data| 2879 * is the mem_user_data member of :type:`nghttp2_mem` structure. 2880 */ 2881 typedef void *(*nghttp2_calloc)(size_t nmemb, size_t size, void *mem_user_data); 2882 2883 /** 2884 * @functypedef 2885 * 2886 * Custom memory allocator to replace realloc(). The |mem_user_data| 2887 * is the mem_user_data member of :type:`nghttp2_mem` structure. 2888 */ 2889 typedef void *(*nghttp2_realloc)(void *ptr, size_t size, void *mem_user_data); 2890 2891 /** 2892 * @struct 2893 * 2894 * Custom memory allocator functions and user defined pointer. The 2895 * |mem_user_data| member is passed to each allocator function. This 2896 * can be used, for example, to achieve per-session memory pool. 2897 * 2898 * In the following example code, ``my_malloc``, ``my_free``, 2899 * ``my_calloc`` and ``my_realloc`` are the replacement of the 2900 * standard allocators ``malloc``, ``free``, ``calloc`` and 2901 * ``realloc`` respectively:: 2902 * 2903 * void *my_malloc_cb(size_t size, void *mem_user_data) { 2904 * return my_malloc(size); 2905 * } 2906 * 2907 * void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); } 2908 * 2909 * void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) { 2910 * return my_calloc(nmemb, size); 2911 * } 2912 * 2913 * void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) { 2914 * return my_realloc(ptr, size); 2915 * } 2916 * 2917 * void session_new() { 2918 * nghttp2_session *session; 2919 * nghttp2_session_callbacks *callbacks; 2920 * nghttp2_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb, 2921 * my_realloc_cb}; 2922 * 2923 * ... 2924 * 2925 * nghttp2_session_client_new3(&session, callbacks, NULL, NULL, &mem); 2926 * 2927 * ... 2928 * } 2929 */ 2930 typedef struct { 2931 /** 2932 * An arbitrary user supplied data. This is passed to each 2933 * allocator function. 2934 */ 2935 void *mem_user_data; 2936 /** 2937 * Custom allocator function to replace malloc(). 2938 */ 2939 nghttp2_malloc malloc; 2940 /** 2941 * Custom allocator function to replace free(). 2942 */ 2943 nghttp2_free free; 2944 /** 2945 * Custom allocator function to replace calloc(). 2946 */ 2947 nghttp2_calloc calloc; 2948 /** 2949 * Custom allocator function to replace realloc(). 2950 */ 2951 nghttp2_realloc realloc; 2952 } nghttp2_mem; 2953 2954 struct nghttp2_option; 2955 2956 /** 2957 * @struct 2958 * 2959 * Configuration options for :type:`nghttp2_session`. The details of 2960 * this structure are intentionally hidden from the public API. 2961 */ 2962 typedef struct nghttp2_option nghttp2_option; 2963 2964 /** 2965 * @function 2966 * 2967 * Initializes |*option_ptr| with default values. 2968 * 2969 * When the application finished using this object, it can use 2970 * `nghttp2_option_del()` to free its memory. 2971 * 2972 * This function returns 0 if it succeeds, or one of the following 2973 * negative error codes: 2974 * 2975 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 2976 * Out of memory. 2977 */ 2978 NGHTTP2_EXTERN int nghttp2_option_new(nghttp2_option **option_ptr); 2979 2980 /** 2981 * @function 2982 * 2983 * Frees any resources allocated for |option|. If |option| is 2984 * ``NULL``, this function does nothing. 2985 */ 2986 NGHTTP2_EXTERN void nghttp2_option_del(nghttp2_option *option); 2987 2988 /** 2989 * @function 2990 * 2991 * This option prevents the library from sending WINDOW_UPDATE for a 2992 * connection automatically. If this option is set to nonzero, the 2993 * library won't send WINDOW_UPDATE for DATA until application calls 2994 * `nghttp2_session_consume()` to indicate the consumed amount of 2995 * data. Don't use `nghttp2_submit_window_update()` for this purpose. 2996 * By default, this option is set to zero. 2997 */ 2998 NGHTTP2_EXTERN void 2999 nghttp2_option_set_no_auto_window_update(nghttp2_option *option, int val); 3000 3001 /** 3002 * @function 3003 * 3004 * This option sets the SETTINGS_MAX_CONCURRENT_STREAMS value of 3005 * remote endpoint as if it is received in SETTINGS frame. Without 3006 * specifying this option, the maximum number of outgoing concurrent 3007 * streams is initially limited to 100 to avoid issues when the local 3008 * endpoint submits lots of requests before receiving initial SETTINGS 3009 * frame from the remote endpoint, since sending them at once to the 3010 * remote endpoint could lead to rejection of some of the requests. 3011 * This value will be overwritten when the local endpoint receives 3012 * initial SETTINGS frame from the remote endpoint, either to the 3013 * value advertised in SETTINGS_MAX_CONCURRENT_STREAMS or to the 3014 * default value (unlimited) if none was advertised. 3015 */ 3016 NGHTTP2_EXTERN void 3017 nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option, 3018 uint32_t val); 3019 3020 /** 3021 * @function 3022 * 3023 * By default, nghttp2 library, if configured as server, requires 3024 * first 24 bytes of client magic byte string (MAGIC). In most cases, 3025 * this will simplify the implementation of server. But sometimes 3026 * server may want to detect the application protocol based on first 3027 * few bytes on clear text communication. 3028 * 3029 * If this option is used with nonzero |val|, nghttp2 library does not 3030 * handle MAGIC. It still checks following SETTINGS frame. This 3031 * means that applications should deal with MAGIC by themselves. 3032 * 3033 * If this option is not used or used with zero value, if MAGIC does 3034 * not match :macro:`NGHTTP2_CLIENT_MAGIC`, `nghttp2_session_recv()` 3035 * and `nghttp2_session_mem_recv2()` will return error 3036 * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`, which is fatal 3037 * error. 3038 */ 3039 NGHTTP2_EXTERN void 3040 nghttp2_option_set_no_recv_client_magic(nghttp2_option *option, int val); 3041 3042 /** 3043 * @function 3044 * 3045 * By default, nghttp2 library enforces subset of HTTP Messaging rules 3046 * described in `HTTP/2 specification, section 8 3047 * <https://tools.ietf.org/html/rfc7540#section-8>`_. See 3048 * :ref:`http-messaging` section for details. For those applications 3049 * who use nghttp2 library as non-HTTP use, give nonzero to |val| to 3050 * disable this enforcement. Please note that disabling this feature 3051 * does not change the fundamental client and server model of HTTP. 3052 * That is, even if the validation is disabled, only client can send 3053 * requests. 3054 */ 3055 NGHTTP2_EXTERN void nghttp2_option_set_no_http_messaging(nghttp2_option *option, 3056 int val); 3057 3058 /** 3059 * @function 3060 * 3061 * RFC 7540 does not enforce any limit on the number of incoming 3062 * reserved streams (in RFC 7540 terms, streams in reserved (remote) 3063 * state). This only affects client side, since only server can push 3064 * streams. Malicious server can push arbitrary number of streams, 3065 * and make client's memory exhausted. This option can set the 3066 * maximum number of such incoming streams to avoid possible memory 3067 * exhaustion. If this option is set, and pushed streams are 3068 * automatically closed on reception, without calling user provided 3069 * callback, if they exceed the given limit. The default value is 3070 * 200. If session is configured as server side, this option has no 3071 * effect. Server can control the number of streams to push. 3072 */ 3073 NGHTTP2_EXTERN void 3074 nghttp2_option_set_max_reserved_remote_streams(nghttp2_option *option, 3075 uint32_t val); 3076 3077 /** 3078 * @function 3079 * 3080 * Sets extension frame type the application is willing to handle with 3081 * user defined callbacks (see 3082 * :type:`nghttp2_on_extension_chunk_recv_callback` and 3083 * :type:`nghttp2_unpack_extension_callback`). The |type| is 3084 * extension frame type, and must be strictly greater than 0x9. 3085 * Otherwise, this function does nothing. The application can call 3086 * this function multiple times to set more than one frame type to 3087 * receive. The application does not have to call this function if it 3088 * just sends extension frames. 3089 */ 3090 NGHTTP2_EXTERN void 3091 nghttp2_option_set_user_recv_extension_type(nghttp2_option *option, 3092 uint8_t type); 3093 3094 /** 3095 * @function 3096 * 3097 * Sets extension frame type the application is willing to receive 3098 * using builtin handler. The |type| is the extension frame type to 3099 * receive, and must be strictly greater than 0x9. Otherwise, this 3100 * function does nothing. The application can call this function 3101 * multiple times to set more than one frame type to receive. The 3102 * application does not have to call this function if it just sends 3103 * extension frames. 3104 * 3105 * If same frame type is passed to both 3106 * `nghttp2_option_set_builtin_recv_extension_type()` and 3107 * `nghttp2_option_set_user_recv_extension_type()`, the latter takes 3108 * precedence. 3109 */ 3110 NGHTTP2_EXTERN void 3111 nghttp2_option_set_builtin_recv_extension_type(nghttp2_option *option, 3112 uint8_t type); 3113 3114 /** 3115 * @function 3116 * 3117 * This option prevents the library from sending PING frame with ACK 3118 * flag set automatically when PING frame without ACK flag set is 3119 * received. If this option is set to nonzero, the library won't send 3120 * PING frame with ACK flag set in the response for incoming PING 3121 * frame. The application can send PING frame with ACK flag set using 3122 * `nghttp2_submit_ping()` with :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK` 3123 * as flags parameter. 3124 */ 3125 NGHTTP2_EXTERN void nghttp2_option_set_no_auto_ping_ack(nghttp2_option *option, 3126 int val); 3127 3128 /** 3129 * @function 3130 * 3131 * This option sets the maximum length of header block (a set of 3132 * header fields per one HEADERS frame) to send. The length of a 3133 * given set of header fields is calculated using 3134 * `nghttp2_hd_deflate_bound()`. The default value is 64KiB. If 3135 * application attempts to send header fields larger than this limit, 3136 * the transmission of the frame fails with error code 3137 * :enum:`nghttp2_error.NGHTTP2_ERR_FRAME_SIZE_ERROR`. 3138 */ 3139 NGHTTP2_EXTERN void 3140 nghttp2_option_set_max_send_header_block_length(nghttp2_option *option, 3141 size_t val); 3142 3143 /** 3144 * @function 3145 * 3146 * This option sets the maximum dynamic table size for deflating 3147 * header fields. The default value is 4KiB. In HTTP/2, receiver of 3148 * deflated header block can specify maximum dynamic table size. The 3149 * actual maximum size is the minimum of the size receiver specified 3150 * and this option value. 3151 */ 3152 NGHTTP2_EXTERN void 3153 nghttp2_option_set_max_deflate_dynamic_table_size(nghttp2_option *option, 3154 size_t val); 3155 3156 /** 3157 * @function 3158 * 3159 * .. warning:: 3160 * 3161 * Deprecated. Closed streams are not retained anymore. 3162 * 3163 * This function works as before, but it does not take any effect 3164 * against :type:`nghttp2_session`. 3165 */ 3166 NGHTTP2_EXTERN void nghttp2_option_set_no_closed_streams(nghttp2_option *option, 3167 int val); 3168 3169 /** 3170 * @function 3171 * 3172 * This function sets the maximum number of outgoing SETTINGS ACK and 3173 * PING ACK frames retained in :type:`nghttp2_session` object. If 3174 * more than those frames are retained, the peer is considered to be 3175 * misbehaving and session will be closed. The default value is 1000. 3176 */ 3177 NGHTTP2_EXTERN void nghttp2_option_set_max_outbound_ack(nghttp2_option *option, 3178 size_t val); 3179 3180 /** 3181 * @function 3182 * 3183 * This function sets the maximum number of SETTINGS entries per 3184 * SETTINGS frame that will be accepted. If more than those entries 3185 * are received, the peer is considered to be misbehaving and session 3186 * will be closed. The default value is 32. 3187 */ 3188 NGHTTP2_EXTERN void nghttp2_option_set_max_settings(nghttp2_option *option, 3189 size_t val); 3190 3191 /** 3192 * @function 3193 * 3194 * .. warning:: 3195 * Deprecated. :rfc:`7540` priorities have been removed. 3196 * 3197 * This function works as before, but it does not take any effect 3198 * against :type:`nghttp2_session`. 3199 */ 3200 NGHTTP2_EXTERN void 3201 nghttp2_option_set_server_fallback_rfc7540_priorities(nghttp2_option *option, 3202 int val); 3203 3204 /** 3205 * @function 3206 * 3207 * This option, if set to nonzero, turns off RFC 9113 leading and 3208 * trailing white spaces validation against HTTP field value. Some 3209 * important fields, such as HTTP/2 pseudo header fields, are 3210 * validated more strictly and this option does not apply to them. 3211 */ 3212 NGHTTP2_EXTERN void 3213 nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation( 3214 nghttp2_option *option, int val); 3215 3216 /** 3217 * @function 3218 * 3219 * This function sets the rate limit for the incoming stream reset 3220 * (RST_STREAM frame). It is server use only. It is a token-bucket 3221 * based rate limiter. |burst| specifies the number of tokens that is 3222 * initially available. The maximum number of tokens is capped to 3223 * this value. |rate| specifies the number of tokens that are 3224 * regenerated per second. An incoming RST_STREAM consumes one token. 3225 * If there is no token available, GOAWAY is sent to tear down the 3226 * connection. |burst| and |rate| default to 1000 and 33 3227 * respectively. 3228 */ 3229 NGHTTP2_EXTERN void 3230 nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option, 3231 uint64_t burst, uint64_t rate); 3232 3233 /** 3234 * @function 3235 * 3236 * This function sets the maximum number of CONTINUATION frames 3237 * following an incoming HEADER frame. If more than those frames are 3238 * received, the remote endpoint is considered to be misbehaving and 3239 * session will be closed. The default value is 8. 3240 */ 3241 NGHTTP2_EXTERN void nghttp2_option_set_max_continuations(nghttp2_option *option, 3242 size_t val); 3243 3244 /** 3245 * @function 3246 * 3247 * This function sets the rate limit for the "glitches", the 3248 * suspicious activities from a remote endpoint. It is a token-bucket 3249 * based rate limiter. |burst| specifies the number of tokens that is 3250 * initially available. The maximum number of tokens is capped to 3251 * this value. |rate| specifies the number of tokens that are 3252 * regenerated per second. When a suspicious activity is detected, 3253 * some amount of tokens are consumed. If there is no token 3254 * available, GOAWAY is sent to tear down the connection. |burst| and 3255 * |rate| default to 1000 and 33 respectively. 3256 */ 3257 NGHTTP2_EXTERN void nghttp2_option_set_glitch_rate_limit(nghttp2_option *option, 3258 uint64_t burst, 3259 uint64_t rate); 3260 3261 /** 3262 * @function 3263 * 3264 * Initializes |*session_ptr| for client use. The all members of 3265 * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr| 3266 * does not store |callbacks|. The |user_data| is an arbitrary user 3267 * supplied data, which will be passed to the callback functions. 3268 * 3269 * The :type:`nghttp2_send_callback2` must be specified. If the 3270 * application code uses `nghttp2_session_recv()`, the 3271 * :type:`nghttp2_recv_callback` must be specified. The other members 3272 * of |callbacks| can be ``NULL``. 3273 * 3274 * If this function fails, |*session_ptr| is left untouched. 3275 * 3276 * This function returns 0 if it succeeds, or one of the following 3277 * negative error codes: 3278 * 3279 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3280 * Out of memory. 3281 */ 3282 NGHTTP2_EXTERN int 3283 nghttp2_session_client_new(nghttp2_session **session_ptr, 3284 const nghttp2_session_callbacks *callbacks, 3285 void *user_data); 3286 3287 /** 3288 * @function 3289 * 3290 * Initializes |*session_ptr| for server use. The all members of 3291 * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr| 3292 * does not store |callbacks|. The |user_data| is an arbitrary user 3293 * supplied data, which will be passed to the callback functions. 3294 * 3295 * The :type:`nghttp2_send_callback2` must be specified. If the 3296 * application code uses `nghttp2_session_recv()`, the 3297 * :type:`nghttp2_recv_callback` must be specified. The other members 3298 * of |callbacks| can be ``NULL``. 3299 * 3300 * If this function fails, |*session_ptr| is left untouched. 3301 * 3302 * This function returns 0 if it succeeds, or one of the following 3303 * negative error codes: 3304 * 3305 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3306 * Out of memory. 3307 */ 3308 NGHTTP2_EXTERN int 3309 nghttp2_session_server_new(nghttp2_session **session_ptr, 3310 const nghttp2_session_callbacks *callbacks, 3311 void *user_data); 3312 3313 /** 3314 * @function 3315 * 3316 * Like `nghttp2_session_client_new()`, but with additional options 3317 * specified in the |option|. 3318 * 3319 * The |option| can be ``NULL`` and the call is equivalent to 3320 * `nghttp2_session_client_new()`. 3321 * 3322 * This function does not take ownership |option|. The application is 3323 * responsible for freeing |option| if it finishes using the object. 3324 * 3325 * The library code does not refer to |option| after this function 3326 * returns. 3327 * 3328 * This function returns 0 if it succeeds, or one of the following 3329 * negative error codes: 3330 * 3331 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3332 * Out of memory. 3333 */ 3334 NGHTTP2_EXTERN int 3335 nghttp2_session_client_new2(nghttp2_session **session_ptr, 3336 const nghttp2_session_callbacks *callbacks, 3337 void *user_data, const nghttp2_option *option); 3338 3339 /** 3340 * @function 3341 * 3342 * Like `nghttp2_session_server_new()`, but with additional options 3343 * specified in the |option|. 3344 * 3345 * The |option| can be ``NULL`` and the call is equivalent to 3346 * `nghttp2_session_server_new()`. 3347 * 3348 * This function does not take ownership |option|. The application is 3349 * responsible for freeing |option| if it finishes using the object. 3350 * 3351 * The library code does not refer to |option| after this function 3352 * returns. 3353 * 3354 * This function returns 0 if it succeeds, or one of the following 3355 * negative error codes: 3356 * 3357 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3358 * Out of memory. 3359 */ 3360 NGHTTP2_EXTERN int 3361 nghttp2_session_server_new2(nghttp2_session **session_ptr, 3362 const nghttp2_session_callbacks *callbacks, 3363 void *user_data, const nghttp2_option *option); 3364 3365 /** 3366 * @function 3367 * 3368 * Like `nghttp2_session_client_new2()`, but with additional custom 3369 * memory allocator specified in the |mem|. 3370 * 3371 * The |mem| can be ``NULL`` and the call is equivalent to 3372 * `nghttp2_session_client_new2()`. 3373 * 3374 * This function does not take ownership |mem|. The application is 3375 * responsible for freeing |mem|. 3376 * 3377 * The library code does not refer to |mem| pointer after this 3378 * function returns, so the application can safely free it. 3379 * 3380 * This function returns 0 if it succeeds, or one of the following 3381 * negative error codes: 3382 * 3383 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3384 * Out of memory. 3385 */ 3386 NGHTTP2_EXTERN int nghttp2_session_client_new3( 3387 nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks, 3388 void *user_data, const nghttp2_option *option, nghttp2_mem *mem); 3389 3390 /** 3391 * @function 3392 * 3393 * Like `nghttp2_session_server_new2()`, but with additional custom 3394 * memory allocator specified in the |mem|. 3395 * 3396 * The |mem| can be ``NULL`` and the call is equivalent to 3397 * `nghttp2_session_server_new2()`. 3398 * 3399 * This function does not take ownership |mem|. The application is 3400 * responsible for freeing |mem|. 3401 * 3402 * The library code does not refer to |mem| pointer after this 3403 * function returns, so the application can safely free it. 3404 * 3405 * This function returns 0 if it succeeds, or one of the following 3406 * negative error codes: 3407 * 3408 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3409 * Out of memory. 3410 */ 3411 NGHTTP2_EXTERN int nghttp2_session_server_new3( 3412 nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks, 3413 void *user_data, const nghttp2_option *option, nghttp2_mem *mem); 3414 3415 /** 3416 * @function 3417 * 3418 * Frees any resources allocated for |session|. If |session| is 3419 * ``NULL``, this function does nothing. 3420 */ 3421 NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session); 3422 3423 /** 3424 * @function 3425 * 3426 * Sends pending frames to the remote peer. 3427 * 3428 * This function retrieves the highest prioritized frame from the 3429 * outbound queue and sends it to the remote peer. It does this as 3430 * many times as possible until the user callback 3431 * :type:`nghttp2_send_callback2` returns 3432 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`, the outbound queue 3433 * becomes empty or flow control is triggered (remote window size 3434 * becomes depleted or maximum number of concurrent streams is 3435 * reached). This function calls several callback functions which are 3436 * passed when initializing the |session|. Here is the simple time 3437 * chart which tells when each callback is invoked: 3438 * 3439 * 1. Get the next frame to send from outbound queue. 3440 * 3441 * 2. Prepare transmission of the frame. 3442 * 3443 * 3. If the control frame cannot be sent because some preconditions 3444 * are not met (e.g., request HEADERS cannot be sent after GOAWAY), 3445 * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort 3446 * the following steps. 3447 * 3448 * 4. If the frame is HEADERS, PUSH_PROMISE or DATA, 3449 * :type:`nghttp2_select_padding_callback` is invoked. 3450 * 3451 * 5. If the frame is request HEADERS, the stream is opened here. 3452 * 3453 * 6. :type:`nghttp2_before_frame_send_callback` is invoked. 3454 * 3455 * 7. If :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL` is returned from 3456 * :type:`nghttp2_before_frame_send_callback`, the current frame 3457 * transmission is canceled, and 3458 * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort 3459 * the following steps. 3460 * 3461 * 8. :type:`nghttp2_send_callback2` is invoked one or more times to 3462 * send the frame. 3463 * 3464 * 9. :type:`nghttp2_on_frame_send_callback` is invoked. 3465 * 3466 * 10. If the transmission of the frame triggers closure of the 3467 * stream, the stream is closed and 3468 * :type:`nghttp2_on_stream_close_callback` is invoked. 3469 * 3470 * This function returns 0 if it succeeds, or one of the following 3471 * negative error codes: 3472 * 3473 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3474 * Out of memory. 3475 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` 3476 * The callback function failed. 3477 */ 3478 NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session); 3479 3480 #ifndef NGHTTP2_NO_SSIZE_T 3481 /** 3482 * @function 3483 * 3484 * .. warning:: 3485 * 3486 * Deprecated. Use `nghttp2_session_mem_send2()` instead. 3487 * 3488 * Returns the serialized data to send. 3489 * 3490 * This function behaves like `nghttp2_session_send()` except that it 3491 * does not use :type:`nghttp2_send_callback` to transmit data. 3492 * Instead, it assigns the pointer to the serialized data to the 3493 * |*data_ptr| and returns its length. The other callbacks are called 3494 * in the same way as they are in `nghttp2_session_send()`. 3495 * 3496 * If no data is available to send, this function returns 0. 3497 * 3498 * This function may not return all serialized data in one invocation. 3499 * To get all data, call this function repeatedly until it returns 0 3500 * or one of negative error codes. 3501 * 3502 * The assigned |*data_ptr| is valid until the next call of 3503 * `nghttp2_session_mem_send()` or `nghttp2_session_send()`. 3504 * 3505 * The caller must send all data before sending the next chunk of 3506 * data. 3507 * 3508 * This function returns the length of the data pointed by the 3509 * |*data_ptr| if it succeeds, or one of the following negative error 3510 * codes: 3511 * 3512 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3513 * Out of memory. 3514 * 3515 * .. note:: 3516 * 3517 * This function may produce very small byte string. If that is the 3518 * case, and application disables Nagle algorithm (``TCP_NODELAY``), 3519 * then writing this small chunk leads to very small packet, and it 3520 * is very inefficient. An application should be responsible to 3521 * buffer up small chunks of data as necessary to avoid this 3522 * situation. 3523 */ 3524 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session, 3525 const uint8_t **data_ptr); 3526 3527 #endif /* NGHTTP2_NO_SSIZE_T */ 3528 3529 /** 3530 * @function 3531 * 3532 * Returns the serialized data to send. 3533 * 3534 * This function behaves like `nghttp2_session_send()` except that it 3535 * does not use :type:`nghttp2_send_callback2` to transmit data. 3536 * Instead, it assigns the pointer to the serialized data to the 3537 * |*data_ptr| and returns its length. The other callbacks are called 3538 * in the same way as they are in `nghttp2_session_send()`. 3539 * 3540 * If no data is available to send, this function returns 0. 3541 * 3542 * This function may not return all serialized data in one invocation. 3543 * To get all data, call this function repeatedly until it returns 0 3544 * or one of negative error codes. 3545 * 3546 * The assigned |*data_ptr| is valid until the next call of 3547 * `nghttp2_session_mem_send2()` or `nghttp2_session_send()`. 3548 * 3549 * The caller must send all data before sending the next chunk of 3550 * data. 3551 * 3552 * This function returns the length of the data pointed by the 3553 * |*data_ptr| if it succeeds, or one of the following negative error 3554 * codes: 3555 * 3556 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3557 * Out of memory. 3558 * 3559 * .. note:: 3560 * 3561 * This function may produce very small byte string. If that is the 3562 * case, and application disables Nagle algorithm (``TCP_NODELAY``), 3563 * then writing this small chunk leads to very small packet, and it 3564 * is very inefficient. An application should be responsible to 3565 * buffer up small chunks of data as necessary to avoid this 3566 * situation. 3567 */ 3568 NGHTTP2_EXTERN nghttp2_ssize 3569 nghttp2_session_mem_send2(nghttp2_session *session, const uint8_t **data_ptr); 3570 3571 /** 3572 * @function 3573 * 3574 * Receives frames from the remote peer. 3575 * 3576 * This function receives as many frames as possible until the user 3577 * callback :type:`nghttp2_recv_callback` returns 3578 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. This function calls 3579 * several callback functions which are passed when initializing the 3580 * |session|. Here is the simple time chart which tells when each 3581 * callback is invoked: 3582 * 3583 * 1. :type:`nghttp2_recv_callback` is invoked one or more times to 3584 * receive frame header. 3585 * 3586 * 2. When frame header is received, 3587 * :type:`nghttp2_on_begin_frame_callback` is invoked. 3588 * 3589 * 3. If the frame is DATA frame: 3590 * 3591 * 1. :type:`nghttp2_recv_callback` is invoked to receive DATA 3592 * payload. For each chunk of data, 3593 * :type:`nghttp2_on_data_chunk_recv_callback` is invoked. 3594 * 3595 * 2. If one DATA frame is completely received, 3596 * :type:`nghttp2_on_frame_recv_callback` is invoked. If the 3597 * reception of the frame triggers the closure of the stream, 3598 * :type:`nghttp2_on_stream_close_callback` is invoked. 3599 * 3600 * 4. If the frame is the control frame: 3601 * 3602 * 1. :type:`nghttp2_recv_callback` is invoked one or more times to 3603 * receive whole frame. 3604 * 3605 * 2. If the received frame is valid, then following actions are 3606 * taken. If the frame is either HEADERS or PUSH_PROMISE, 3607 * :type:`nghttp2_on_begin_headers_callback` is invoked. Then 3608 * :type:`nghttp2_on_header_callback` is invoked for each header 3609 * name/value pair. For invalid header field, 3610 * :type:`nghttp2_on_invalid_header_callback` is called. After 3611 * all name/value pairs are emitted successfully, 3612 * :type:`nghttp2_on_frame_recv_callback` is invoked. For other 3613 * frames, :type:`nghttp2_on_frame_recv_callback` is invoked. 3614 * If the reception of the frame triggers the closure of the 3615 * stream, :type:`nghttp2_on_stream_close_callback` is invoked. 3616 * 3617 * 3. If the received frame is unpacked but is interpreted as 3618 * invalid, :type:`nghttp2_on_invalid_frame_recv_callback` is 3619 * invoked. 3620 * 3621 * This function returns 0 if it succeeds, or one of the following 3622 * negative error codes: 3623 * 3624 * :enum:`nghttp2_error.NGHTTP2_ERR_EOF` 3625 * The remote peer did shutdown on the connection. 3626 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3627 * Out of memory. 3628 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` 3629 * The callback function failed. 3630 * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC` 3631 * Invalid client magic was detected. This error only returns 3632 * when |session| was configured as server and 3633 * `nghttp2_option_set_no_recv_client_magic()` is not used with 3634 * nonzero value. 3635 * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED` 3636 * Flooding was detected in this HTTP/2 session, and it must be 3637 * closed. This is most likely caused by misbehaviour of peer. 3638 */ 3639 NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session); 3640 3641 #ifndef NGHTTP2_NO_SSIZE_T 3642 /** 3643 * @function 3644 * 3645 * .. warning:: 3646 * 3647 * Deprecated. Use `nghttp2_session_mem_recv2()` instead. 3648 * 3649 * Processes data |in| as an input from the remote endpoint. The 3650 * |inlen| indicates the number of bytes to receive in the |in|. 3651 * 3652 * This function behaves like `nghttp2_session_recv()` except that it 3653 * does not use :type:`nghttp2_recv_callback` to receive data; the 3654 * |in| is the only data for the invocation of this function. If all 3655 * bytes are processed, this function returns. The other callbacks 3656 * are called in the same way as they are in `nghttp2_session_recv()`. 3657 * 3658 * In the current implementation, this function always tries to 3659 * processes |inlen| bytes of input data unless either an error occurs or 3660 * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from 3661 * :type:`nghttp2_on_header_callback` or 3662 * :type:`nghttp2_on_data_chunk_recv_callback`. If 3663 * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value 3664 * includes the number of bytes which was used to produce the data or 3665 * frame for the callback. 3666 * 3667 * This function returns the number of processed bytes, or one of the 3668 * following negative error codes: 3669 * 3670 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3671 * Out of memory. 3672 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` 3673 * The callback function failed. 3674 * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC` 3675 * Invalid client magic was detected. This error only returns 3676 * when |session| was configured as server and 3677 * `nghttp2_option_set_no_recv_client_magic()` is not used with 3678 * nonzero value. 3679 * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED` 3680 * Flooding was detected in this HTTP/2 session, and it must be 3681 * closed. This is most likely caused by misbehaviour of peer. 3682 */ 3683 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session, 3684 const uint8_t *in, 3685 size_t inlen); 3686 3687 #endif /* NGHTTP2_NO_SSIZE_T */ 3688 3689 /** 3690 * @function 3691 * 3692 * Processes data |in| as an input from the remote endpoint. The 3693 * |inlen| indicates the number of bytes to receive in the |in|. 3694 * 3695 * This function behaves like `nghttp2_session_recv()` except that it 3696 * does not use :type:`nghttp2_recv_callback` to receive data; the 3697 * |in| is the only data for the invocation of this function. If all 3698 * bytes are processed, this function returns. The other callbacks 3699 * are called in the same way as they are in `nghttp2_session_recv()`. 3700 * 3701 * In the current implementation, this function always tries to 3702 * processes |inlen| bytes of input data unless either an error occurs or 3703 * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from 3704 * :type:`nghttp2_on_header_callback` or 3705 * :type:`nghttp2_on_data_chunk_recv_callback`. If 3706 * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value 3707 * includes the number of bytes which was used to produce the data or 3708 * frame for the callback. 3709 * 3710 * This function returns the number of processed bytes, or one of the 3711 * following negative error codes: 3712 * 3713 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3714 * Out of memory. 3715 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` 3716 * The callback function failed. 3717 * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC` 3718 * Invalid client magic was detected. This error only returns 3719 * when |session| was configured as server and 3720 * `nghttp2_option_set_no_recv_client_magic()` is not used with 3721 * nonzero value. 3722 * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED` 3723 * Flooding was detected in this HTTP/2 session, and it must be 3724 * closed. This is most likely caused by misbehaviour of peer. 3725 */ 3726 NGHTTP2_EXTERN nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, 3727 const uint8_t *in, 3728 size_t inlen); 3729 3730 /** 3731 * @function 3732 * 3733 * Puts back previously deferred DATA frame in the stream |stream_id| 3734 * to the outbound queue. 3735 * 3736 * This function returns 0 if it succeeds, or one of the following 3737 * negative error codes: 3738 * 3739 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 3740 * The stream does not exist; or no deferred data exist. 3741 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3742 * Out of memory. 3743 */ 3744 NGHTTP2_EXTERN int nghttp2_session_resume_data(nghttp2_session *session, 3745 int32_t stream_id); 3746 3747 /** 3748 * @function 3749 * 3750 * Returns nonzero value if |session| wants to receive data from the 3751 * remote peer. 3752 * 3753 * If both `nghttp2_session_want_read()` and 3754 * `nghttp2_session_want_write()` return 0, the application should 3755 * drop the connection. 3756 */ 3757 NGHTTP2_EXTERN int nghttp2_session_want_read(nghttp2_session *session); 3758 3759 /** 3760 * @function 3761 * 3762 * Returns nonzero value if |session| wants to send data to the remote 3763 * peer. 3764 * 3765 * If both `nghttp2_session_want_read()` and 3766 * `nghttp2_session_want_write()` return 0, the application should 3767 * drop the connection. 3768 */ 3769 NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session); 3770 3771 /** 3772 * @function 3773 * 3774 * Returns stream_user_data for the stream |stream_id|. The 3775 * stream_user_data is provided by `nghttp2_submit_request2()`, 3776 * `nghttp2_submit_headers()` or 3777 * `nghttp2_session_set_stream_user_data()`. Unless it is set using 3778 * `nghttp2_session_set_stream_user_data()`, if the stream is 3779 * initiated by the remote endpoint, stream_user_data is always 3780 * ``NULL``. If the stream does not exist, this function returns 3781 * ``NULL``. 3782 */ 3783 NGHTTP2_EXTERN void * 3784 nghttp2_session_get_stream_user_data(nghttp2_session *session, 3785 int32_t stream_id); 3786 3787 /** 3788 * @function 3789 * 3790 * Sets the |stream_user_data| to the stream denoted by the 3791 * |stream_id|. If a stream user data is already set to the stream, 3792 * it is replaced with the |stream_user_data|. It is valid to specify 3793 * ``NULL`` in the |stream_user_data|, which nullifies the associated 3794 * data pointer. 3795 * 3796 * It is valid to set the |stream_user_data| to the stream reserved by 3797 * PUSH_PROMISE frame. 3798 * 3799 * This function returns 0 if it succeeds, or one of following 3800 * negative error codes: 3801 * 3802 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 3803 * The stream does not exist 3804 */ 3805 NGHTTP2_EXTERN int 3806 nghttp2_session_set_stream_user_data(nghttp2_session *session, 3807 int32_t stream_id, void *stream_user_data); 3808 3809 /** 3810 * @function 3811 * 3812 * Sets |user_data| to |session|, overwriting the existing user data 3813 * specified in `nghttp2_session_client_new()`, or 3814 * `nghttp2_session_server_new()`. 3815 */ 3816 NGHTTP2_EXTERN void nghttp2_session_set_user_data(nghttp2_session *session, 3817 void *user_data); 3818 3819 /** 3820 * @function 3821 * 3822 * Returns the number of frames in the outbound queue. This does not 3823 * include the deferred DATA frames. 3824 */ 3825 NGHTTP2_EXTERN size_t 3826 nghttp2_session_get_outbound_queue_size(nghttp2_session *session); 3827 3828 /** 3829 * @function 3830 * 3831 * Returns the number of DATA payload in bytes received without 3832 * WINDOW_UPDATE transmission for the stream |stream_id|. The local 3833 * (receive) window size can be adjusted by 3834 * `nghttp2_submit_window_update()`. This function takes into account 3835 * that and returns effective data length. In particular, if the 3836 * local window size is reduced by submitting negative 3837 * window_size_increment with `nghttp2_submit_window_update()`, this 3838 * function returns the number of bytes less than actually received. 3839 * 3840 * This function returns -1 if it fails. 3841 */ 3842 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_recv_data_length( 3843 nghttp2_session *session, int32_t stream_id); 3844 3845 /** 3846 * @function 3847 * 3848 * Returns the local (receive) window size for the stream |stream_id|. 3849 * The local window size can be adjusted by 3850 * `nghttp2_submit_window_update()`. This function takes into account 3851 * that and returns effective window size. 3852 * 3853 * This function does not take into account the amount of received 3854 * data from the remote endpoint. Use 3855 * `nghttp2_session_get_stream_local_window_size()` to know the amount 3856 * of data the remote endpoint can send without receiving stream level 3857 * WINDOW_UPDATE frame. Note that each stream is still subject to the 3858 * connection level flow control. 3859 * 3860 * This function returns -1 if it fails. 3861 */ 3862 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_local_window_size( 3863 nghttp2_session *session, int32_t stream_id); 3864 3865 /** 3866 * @function 3867 * 3868 * Returns the amount of flow-controlled payload (e.g., DATA) that the 3869 * remote endpoint can send without receiving stream level 3870 * WINDOW_UPDATE frame. It is also subject to the connection level 3871 * flow control. So the actual amount of data to send is 3872 * min(`nghttp2_session_get_stream_local_window_size()`, 3873 * `nghttp2_session_get_local_window_size()`). 3874 * 3875 * This function returns -1 if it fails. 3876 */ 3877 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_local_window_size( 3878 nghttp2_session *session, int32_t stream_id); 3879 3880 /** 3881 * @function 3882 * 3883 * Returns the number of DATA payload in bytes received without 3884 * WINDOW_UPDATE transmission for a connection. The local (receive) 3885 * window size can be adjusted by `nghttp2_submit_window_update()`. 3886 * This function takes into account that and returns effective data 3887 * length. In particular, if the local window size is reduced by 3888 * submitting negative window_size_increment with 3889 * `nghttp2_submit_window_update()`, this function returns the number 3890 * of bytes less than actually received. 3891 * 3892 * This function returns -1 if it fails. 3893 */ 3894 NGHTTP2_EXTERN int32_t 3895 nghttp2_session_get_effective_recv_data_length(nghttp2_session *session); 3896 3897 /** 3898 * @function 3899 * 3900 * Returns the local (receive) window size for a connection. The 3901 * local window size can be adjusted by 3902 * `nghttp2_submit_window_update()`. This function takes into account 3903 * that and returns effective window size. 3904 * 3905 * This function does not take into account the amount of received 3906 * data from the remote endpoint. Use 3907 * `nghttp2_session_get_local_window_size()` to know the amount of 3908 * data the remote endpoint can send without receiving 3909 * connection-level WINDOW_UPDATE frame. Note that each stream is 3910 * still subject to the stream level flow control. 3911 * 3912 * This function returns -1 if it fails. 3913 */ 3914 NGHTTP2_EXTERN int32_t 3915 nghttp2_session_get_effective_local_window_size(nghttp2_session *session); 3916 3917 /** 3918 * @function 3919 * 3920 * Returns the amount of flow-controlled payload (e.g., DATA) that the 3921 * remote endpoint can send without receiving connection level 3922 * WINDOW_UPDATE frame. Note that each stream is still subject to the 3923 * stream level flow control (see 3924 * `nghttp2_session_get_stream_local_window_size()`). 3925 * 3926 * This function returns -1 if it fails. 3927 */ 3928 NGHTTP2_EXTERN int32_t 3929 nghttp2_session_get_local_window_size(nghttp2_session *session); 3930 3931 /** 3932 * @function 3933 * 3934 * Returns the remote window size for a given stream |stream_id|. 3935 * 3936 * This is the amount of flow-controlled payload (e.g., DATA) that the 3937 * local endpoint can send without stream level WINDOW_UPDATE. There 3938 * is also connection level flow control, so the effective size of 3939 * payload that the local endpoint can actually send is 3940 * min(`nghttp2_session_get_stream_remote_window_size()`, 3941 * `nghttp2_session_get_remote_window_size()`). 3942 * 3943 * This function returns -1 if it fails. 3944 */ 3945 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_remote_window_size( 3946 nghttp2_session *session, int32_t stream_id); 3947 3948 /** 3949 * @function 3950 * 3951 * Returns the remote window size for a connection. 3952 * 3953 * This function always succeeds. 3954 */ 3955 NGHTTP2_EXTERN int32_t 3956 nghttp2_session_get_remote_window_size(nghttp2_session *session); 3957 3958 /** 3959 * @function 3960 * 3961 * Returns 1 if local peer half closed the given stream |stream_id|. 3962 * Returns 0 if it did not. Returns -1 if no such stream exists. 3963 */ 3964 NGHTTP2_EXTERN int 3965 nghttp2_session_get_stream_local_close(nghttp2_session *session, 3966 int32_t stream_id); 3967 3968 /** 3969 * @function 3970 * 3971 * Returns 1 if remote peer half closed the given stream |stream_id|. 3972 * Returns 0 if it did not. Returns -1 if no such stream exists. 3973 */ 3974 NGHTTP2_EXTERN int 3975 nghttp2_session_get_stream_remote_close(nghttp2_session *session, 3976 int32_t stream_id); 3977 3978 /** 3979 * @function 3980 * 3981 * Returns the current dynamic table size of HPACK inflater, including 3982 * the overhead 32 bytes per entry described in RFC 7541. 3983 */ 3984 NGHTTP2_EXTERN size_t 3985 nghttp2_session_get_hd_inflate_dynamic_table_size(nghttp2_session *session); 3986 3987 /** 3988 * @function 3989 * 3990 * Returns the current dynamic table size of HPACK deflater including 3991 * the overhead 32 bytes per entry described in RFC 7541. 3992 */ 3993 NGHTTP2_EXTERN size_t 3994 nghttp2_session_get_hd_deflate_dynamic_table_size(nghttp2_session *session); 3995 3996 /** 3997 * @function 3998 * 3999 * Signals the session so that the connection should be terminated. 4000 * 4001 * The last stream ID is the minimum value between the stream ID of a 4002 * stream for which :type:`nghttp2_on_frame_recv_callback` was called 4003 * most recently and the last stream ID we have sent to the peer 4004 * previously. 4005 * 4006 * The |error_code| is the error code of this GOAWAY frame. The 4007 * pre-defined error code is one of :enum:`nghttp2_error_code`. 4008 * 4009 * After the transmission, both `nghttp2_session_want_read()` and 4010 * `nghttp2_session_want_write()` return 0. 4011 * 4012 * This function should be called when the connection should be 4013 * terminated after sending GOAWAY. If the remaining streams should 4014 * be processed after GOAWAY, use `nghttp2_submit_goaway()` instead. 4015 * 4016 * This function returns 0 if it succeeds, or one of the following 4017 * negative error codes: 4018 * 4019 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4020 * Out of memory. 4021 */ 4022 NGHTTP2_EXTERN int nghttp2_session_terminate_session(nghttp2_session *session, 4023 uint32_t error_code); 4024 4025 /** 4026 * @function 4027 * 4028 * Signals the session so that the connection should be terminated. 4029 * 4030 * This function behaves like `nghttp2_session_terminate_session()`, 4031 * but the last stream ID can be specified by the application for fine 4032 * grained control of stream. The HTTP/2 specification does not allow 4033 * last_stream_id to be increased. So the actual value sent as 4034 * last_stream_id is the minimum value between the given 4035 * |last_stream_id| and the last_stream_id we have previously sent to 4036 * the peer. 4037 * 4038 * The |last_stream_id| is peer's stream ID or 0. So if |session| is 4039 * initialized as client, |last_stream_id| must be even or 0. If 4040 * |session| is initialized as server, |last_stream_id| must be odd or 4041 * 0. 4042 * 4043 * This function returns 0 if it succeeds, or one of the following 4044 * negative error codes: 4045 * 4046 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4047 * Out of memory. 4048 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4049 * The |last_stream_id| is invalid. 4050 */ 4051 NGHTTP2_EXTERN int nghttp2_session_terminate_session2(nghttp2_session *session, 4052 int32_t last_stream_id, 4053 uint32_t error_code); 4054 4055 /** 4056 * @function 4057 * 4058 * Signals to the client that the server started graceful shutdown 4059 * procedure. 4060 * 4061 * This function is only usable for server. If this function is 4062 * called with client side session, this function returns 4063 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. 4064 * 4065 * To gracefully shutdown HTTP/2 session, server should call this 4066 * function to send GOAWAY with last_stream_id (1u << 31) - 1. And 4067 * after some delay (e.g., 1 RTT), send another GOAWAY with the stream 4068 * ID that the server has some processing using 4069 * `nghttp2_submit_goaway()`. See also 4070 * `nghttp2_session_get_last_proc_stream_id()`. 4071 * 4072 * Unlike `nghttp2_submit_goaway()`, this function just sends GOAWAY 4073 * and does nothing more. This is a mere indication to the client 4074 * that session shutdown is imminent. The application should call 4075 * `nghttp2_submit_goaway()` with appropriate last_stream_id after 4076 * this call. 4077 * 4078 * If one or more GOAWAY frame have been already sent by either 4079 * `nghttp2_submit_goaway()` or `nghttp2_session_terminate_session()`, 4080 * this function has no effect. 4081 * 4082 * This function returns 0 if it succeeds, or one of the following 4083 * negative error codes: 4084 * 4085 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4086 * Out of memory. 4087 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 4088 * The |session| is initialized as client. 4089 */ 4090 NGHTTP2_EXTERN int nghttp2_submit_shutdown_notice(nghttp2_session *session); 4091 4092 /** 4093 * @function 4094 * 4095 * Returns the value of SETTINGS |id| notified by a remote endpoint. 4096 * The |id| must be one of values defined in 4097 * :enum:`nghttp2_settings_id`. 4098 */ 4099 NGHTTP2_EXTERN uint32_t nghttp2_session_get_remote_settings( 4100 nghttp2_session *session, nghttp2_settings_id id); 4101 4102 /** 4103 * @function 4104 * 4105 * Returns the value of SETTINGS |id| of local endpoint acknowledged 4106 * by the remote endpoint. The |id| must be one of the values defined 4107 * in :enum:`nghttp2_settings_id`. 4108 */ 4109 NGHTTP2_EXTERN uint32_t nghttp2_session_get_local_settings( 4110 nghttp2_session *session, nghttp2_settings_id id); 4111 4112 /** 4113 * @function 4114 * 4115 * Tells the |session| that next stream ID is |next_stream_id|. The 4116 * |next_stream_id| must be equal or greater than the value returned 4117 * by `nghttp2_session_get_next_stream_id()`. 4118 * 4119 * This function returns 0 if it succeeds, or one of the following 4120 * negative error codes: 4121 * 4122 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4123 * The |next_stream_id| is strictly less than the value 4124 * `nghttp2_session_get_next_stream_id()` returns; or 4125 * |next_stream_id| is invalid (e.g., even integer for client, or 4126 * odd integer for server). 4127 */ 4128 NGHTTP2_EXTERN int nghttp2_session_set_next_stream_id(nghttp2_session *session, 4129 int32_t next_stream_id); 4130 4131 /** 4132 * @function 4133 * 4134 * Returns the next outgoing stream ID. Notice that return type is 4135 * uint32_t. If we run out of stream ID for this session, this 4136 * function returns 1 << 31. 4137 */ 4138 NGHTTP2_EXTERN uint32_t 4139 nghttp2_session_get_next_stream_id(nghttp2_session *session); 4140 4141 /** 4142 * @function 4143 * 4144 * Tells the |session| that |size| bytes for a stream denoted by 4145 * |stream_id| were consumed by application and are ready to 4146 * WINDOW_UPDATE. The consumed bytes are counted towards both 4147 * connection and stream level WINDOW_UPDATE (see 4148 * `nghttp2_session_consume_connection()` and 4149 * `nghttp2_session_consume_stream()` to update consumption 4150 * independently). This function is intended to be used without 4151 * automatic window update (see 4152 * `nghttp2_option_set_no_auto_window_update()`). 4153 * 4154 * This function returns 0 if it succeeds, or one of the following 4155 * negative error codes: 4156 * 4157 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4158 * Out of memory. 4159 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4160 * The |stream_id| is 0. 4161 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 4162 * Automatic WINDOW_UPDATE is not disabled. 4163 */ 4164 NGHTTP2_EXTERN int nghttp2_session_consume(nghttp2_session *session, 4165 int32_t stream_id, size_t size); 4166 4167 /** 4168 * @function 4169 * 4170 * Like `nghttp2_session_consume()`, but this only tells library that 4171 * |size| bytes were consumed only for connection level. Note that 4172 * HTTP/2 maintains connection and stream level flow control windows 4173 * independently. 4174 * 4175 * This function returns 0 if it succeeds, or one of the following 4176 * negative error codes: 4177 * 4178 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4179 * Out of memory. 4180 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 4181 * Automatic WINDOW_UPDATE is not disabled. 4182 */ 4183 NGHTTP2_EXTERN int nghttp2_session_consume_connection(nghttp2_session *session, 4184 size_t size); 4185 4186 /** 4187 * @function 4188 * 4189 * Like `nghttp2_session_consume()`, but this only tells library that 4190 * |size| bytes were consumed only for stream denoted by |stream_id|. 4191 * Note that HTTP/2 maintains connection and stream level flow control 4192 * windows independently. 4193 * 4194 * This function returns 0 if it succeeds, or one of the following 4195 * negative error codes: 4196 * 4197 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4198 * Out of memory. 4199 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4200 * The |stream_id| is 0. 4201 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 4202 * Automatic WINDOW_UPDATE is not disabled. 4203 */ 4204 NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session, 4205 int32_t stream_id, 4206 size_t size); 4207 4208 /** 4209 * @function 4210 * 4211 * .. warning:: 4212 * 4213 * Deprecated. :rfc:`7540` priorities are deprecated by 4214 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4215 * prioritization scheme. 4216 * 4217 * This function is noop. It always returns 0. 4218 */ 4219 NGHTTP2_EXTERN int 4220 nghttp2_session_change_stream_priority(nghttp2_session *session, 4221 int32_t stream_id, 4222 const nghttp2_priority_spec *pri_spec); 4223 4224 /** 4225 * @function 4226 * 4227 * .. warning:: 4228 * 4229 * Deprecated. :rfc:`7540` priorities are deprecated by 4230 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4231 * prioritization scheme. 4232 * 4233 * This function is noop. It always returns 0. 4234 */ 4235 NGHTTP2_EXTERN int 4236 nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id, 4237 const nghttp2_priority_spec *pri_spec); 4238 4239 /** 4240 * @function 4241 * 4242 * .. warning:: 4243 * 4244 * This function is deprecated in favor of 4245 * `nghttp2_session_upgrade2()`, because this function lacks the 4246 * parameter to tell the library the request method used in the 4247 * original HTTP request. This information is required for client 4248 * to validate actual response body length against content-length 4249 * header field (see `nghttp2_option_set_no_http_messaging()`). If 4250 * HEAD is used in request, the length of response body must be 0 4251 * regardless of value included in content-length header field. 4252 * 4253 * Performs post-process of HTTP Upgrade request. This function can 4254 * be called from both client and server, but the behavior is very 4255 * different in each other. 4256 * 4257 * If called from client side, the |settings_payload| must be the 4258 * value sent in ``HTTP2-Settings`` header field and must be decoded 4259 * by base64url decoder. The |settings_payloadlen| is the length of 4260 * |settings_payload|. The |settings_payload| is unpacked and its 4261 * setting values will be submitted using `nghttp2_submit_settings()`. 4262 * This means that the client application code does not need to submit 4263 * SETTINGS by itself. The stream with stream ID=1 is opened and the 4264 * |stream_user_data| is used for its stream_user_data. The opened 4265 * stream becomes half-closed (local) state. 4266 * 4267 * If called from server side, the |settings_payload| must be the 4268 * value received in ``HTTP2-Settings`` header field and must be 4269 * decoded by base64url decoder. The |settings_payloadlen| is the 4270 * length of |settings_payload|. It is treated as if the SETTINGS 4271 * frame with that payload is received. Thus, callback functions for 4272 * the reception of SETTINGS frame will be invoked. The stream with 4273 * stream ID=1 is opened. The |stream_user_data| is ignored. The 4274 * opened stream becomes half-closed (remote). 4275 * 4276 * This function returns 0 if it succeeds, or one of the following 4277 * negative error codes: 4278 * 4279 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4280 * Out of memory. 4281 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4282 * The |settings_payload| is badly formed. 4283 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4284 * The stream ID 1 is already used or closed; or is not available. 4285 */ 4286 NGHTTP2_EXTERN int nghttp2_session_upgrade(nghttp2_session *session, 4287 const uint8_t *settings_payload, 4288 size_t settings_payloadlen, 4289 void *stream_user_data); 4290 4291 /** 4292 * @function 4293 * 4294 * Performs post-process of HTTP Upgrade request. This function can 4295 * be called from both client and server, but the behavior is very 4296 * different in each other. 4297 * 4298 * If called from client side, the |settings_payload| must be the 4299 * value sent in ``HTTP2-Settings`` header field and must be decoded 4300 * by base64url decoder. The |settings_payloadlen| is the length of 4301 * |settings_payload|. The |settings_payload| is unpacked and its 4302 * setting values will be submitted using `nghttp2_submit_settings()`. 4303 * This means that the client application code does not need to submit 4304 * SETTINGS by itself. The stream with stream ID=1 is opened and the 4305 * |stream_user_data| is used for its stream_user_data. The opened 4306 * stream becomes half-closed (local) state. 4307 * 4308 * If called from server side, the |settings_payload| must be the 4309 * value received in ``HTTP2-Settings`` header field and must be 4310 * decoded by base64url decoder. The |settings_payloadlen| is the 4311 * length of |settings_payload|. It is treated as if the SETTINGS 4312 * frame with that payload is received. Thus, callback functions for 4313 * the reception of SETTINGS frame will be invoked. The stream with 4314 * stream ID=1 is opened. The |stream_user_data| is ignored. The 4315 * opened stream becomes half-closed (remote). 4316 * 4317 * If the request method is HEAD, pass nonzero value to 4318 * |head_request|. Otherwise, pass 0. 4319 * 4320 * This function returns 0 if it succeeds, or one of the following 4321 * negative error codes: 4322 * 4323 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4324 * Out of memory. 4325 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4326 * The |settings_payload| is badly formed. 4327 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4328 * The stream ID 1 is already used or closed; or is not available. 4329 */ 4330 NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session, 4331 const uint8_t *settings_payload, 4332 size_t settings_payloadlen, 4333 int head_request, 4334 void *stream_user_data); 4335 4336 #ifndef NGHTTP2_NO_SSIZE_T 4337 /** 4338 * @function 4339 * 4340 * .. warning:: 4341 * 4342 * Deprecated. Use `nghttp2_pack_settings_payload2()` instead. 4343 * 4344 * Serializes the SETTINGS values |iv| in the |buf|. The size of the 4345 * |buf| is specified by |buflen|. The number of entries in the |iv| 4346 * array is given by |niv|. The required space in |buf| for the |niv| 4347 * entries is ``6*niv`` bytes and if the given buffer is too small, an 4348 * error is returned. This function is used mainly for creating a 4349 * SETTINGS payload to be sent with the ``HTTP2-Settings`` header 4350 * field in an HTTP Upgrade request. The data written in |buf| is NOT 4351 * base64url encoded and the application is responsible for encoding. 4352 * 4353 * This function returns the number of bytes written in |buf|, or one 4354 * of the following negative error codes: 4355 * 4356 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4357 * The |iv| contains duplicate settings ID or invalid value. 4358 * 4359 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 4360 * The provided |buflen| size is too small to hold the output. 4361 */ 4362 NGHTTP2_EXTERN ssize_t nghttp2_pack_settings_payload( 4363 uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv); 4364 4365 #endif /* NGHTTP2_NO_SSIZE_T */ 4366 4367 /** 4368 * @function 4369 * 4370 * Serializes the SETTINGS values |iv| in the |buf|. The size of the 4371 * |buf| is specified by |buflen|. The number of entries in the |iv| 4372 * array is given by |niv|. The required space in |buf| for the |niv| 4373 * entries is ``6*niv`` bytes and if the given buffer is too small, an 4374 * error is returned. This function is used mainly for creating a 4375 * SETTINGS payload to be sent with the ``HTTP2-Settings`` header 4376 * field in an HTTP Upgrade request. The data written in |buf| is NOT 4377 * base64url encoded and the application is responsible for encoding. 4378 * 4379 * This function returns the number of bytes written in |buf|, or one 4380 * of the following negative error codes: 4381 * 4382 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4383 * The |iv| contains duplicate settings ID or invalid value. 4384 * 4385 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 4386 * The provided |buflen| size is too small to hold the output. 4387 */ 4388 NGHTTP2_EXTERN nghttp2_ssize nghttp2_pack_settings_payload2( 4389 uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv); 4390 4391 /** 4392 * @function 4393 * 4394 * Returns string describing the |lib_error_code|. The 4395 * |lib_error_code| must be one of the :enum:`nghttp2_error`. 4396 */ 4397 NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code); 4398 4399 /** 4400 * @function 4401 * 4402 * Returns string representation of HTTP/2 error code |error_code| 4403 * (e.g., ``PROTOCOL_ERROR`` is returned if ``error_code == 4404 * NGHTTP2_PROTOCOL_ERROR``). If string representation is unknown for 4405 * given |error_code|, this function returns string ``unknown``. 4406 */ 4407 NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code); 4408 4409 /** 4410 * @function 4411 * 4412 * .. warning:: 4413 * 4414 * Deprecated. :rfc:`7540` priorities are deprecated by 4415 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4416 * prioritization scheme. 4417 * 4418 * Initializes |pri_spec| with the |stream_id| of the stream to depend 4419 * on with |weight| and its exclusive flag. If |exclusive| is 4420 * nonzero, exclusive flag is set. 4421 * 4422 * The |weight| must be in [:macro:`NGHTTP2_MIN_WEIGHT`, 4423 * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. 4424 */ 4425 NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec, 4426 int32_t stream_id, 4427 int32_t weight, int exclusive); 4428 4429 /** 4430 * @function 4431 * 4432 * .. warning:: 4433 * 4434 * Deprecated. :rfc:`7540` priorities are deprecated by 4435 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4436 * prioritization scheme. 4437 * 4438 * Initializes |pri_spec| with the default values. The default values 4439 * are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and 4440 * exclusive = 0. 4441 */ 4442 NGHTTP2_EXTERN void 4443 nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec); 4444 4445 /** 4446 * @function 4447 * 4448 * .. warning:: 4449 * 4450 * Deprecated. :rfc:`7540` priorities are deprecated by 4451 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4452 * prioritization scheme. 4453 * 4454 * Returns nonzero if the |pri_spec| is filled with default values. 4455 */ 4456 NGHTTP2_EXTERN int 4457 nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec); 4458 4459 #ifndef NGHTTP2_NO_SSIZE_T 4460 /** 4461 * @function 4462 * 4463 * .. warning:: 4464 * 4465 * Deprecated. Use `nghttp2_submit_request2()` instead. 4466 * 4467 * Submits HEADERS frame and optionally one or more DATA frames. 4468 * 4469 * The |pri_spec| is ignored. 4470 * 4471 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4472 * |nvlen| elements. The application is responsible to include 4473 * required pseudo-header fields (header field whose name starts with 4474 * ":") in |nva| and must place pseudo-headers before regular header 4475 * fields. 4476 * 4477 * This function creates copies of all name/value pairs in |nva|. It 4478 * also lower-cases all names in |nva|. The order of elements in 4479 * |nva| is preserved. For header fields with 4480 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 4481 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 4482 * header field name and value are not copied respectively. With 4483 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 4484 * is responsible to pass header field name in lowercase. The 4485 * application should maintain the references to them until 4486 * :type:`nghttp2_on_frame_send_callback` or 4487 * :type:`nghttp2_on_frame_not_send_callback` is called. 4488 * 4489 * HTTP/2 specification has requirement about header fields in the 4490 * request HEADERS. See the specification for more details. 4491 * 4492 * If |data_prd| is not ``NULL``, it provides data which will be sent 4493 * in subsequent DATA frames. In this case, a method that allows 4494 * request message bodies 4495 * (https://tools.ietf.org/html/rfc7231#section-4) must be specified 4496 * with ``:method`` key in |nva| (e.g. ``POST``). This function does 4497 * not take ownership of the |data_prd|. The function copies the 4498 * members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have 4499 * END_STREAM set. The |stream_user_data| is data associated to the 4500 * stream opened by this request and can be an arbitrary pointer, 4501 * which can be retrieved later by 4502 * `nghttp2_session_get_stream_user_data()`. 4503 * 4504 * This function returns assigned stream ID if it succeeds, or one of 4505 * the following negative error codes: 4506 * 4507 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4508 * Out of memory. 4509 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` 4510 * No stream ID is available because maximum stream ID was 4511 * reached. 4512 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4513 * The |session| is server session. 4514 * 4515 * .. warning:: 4516 * 4517 * This function returns assigned stream ID if it succeeds. But 4518 * that stream is not created yet. The application must not submit 4519 * frame to that stream ID before 4520 * :type:`nghttp2_before_frame_send_callback` is called for this 4521 * frame. This means `nghttp2_session_get_stream_user_data()` does 4522 * not work before the callback. But 4523 * `nghttp2_session_set_stream_user_data()` handles this situation 4524 * specially, and it can set data to a stream during this period. 4525 * 4526 */ 4527 NGHTTP2_EXTERN int32_t nghttp2_submit_request( 4528 nghttp2_session *session, const nghttp2_priority_spec *pri_spec, 4529 const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd, 4530 void *stream_user_data); 4531 4532 #endif /* NGHTTP2_NO_SSIZE_T */ 4533 4534 /** 4535 * @function 4536 * 4537 * Submits HEADERS frame and optionally one or more DATA frames. 4538 * 4539 * The |pri_spec| is ignored. 4540 * 4541 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4542 * |nvlen| elements. The application is responsible to include 4543 * required pseudo-header fields (header field whose name starts with 4544 * ":") in |nva| and must place pseudo-headers before regular header 4545 * fields. 4546 * 4547 * This function creates copies of all name/value pairs in |nva|. It 4548 * also lower-cases all names in |nva|. The order of elements in 4549 * |nva| is preserved. For header fields with 4550 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 4551 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 4552 * header field name and value are not copied respectively. With 4553 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 4554 * is responsible to pass header field name in lowercase. The 4555 * application should maintain the references to them until 4556 * :type:`nghttp2_on_frame_send_callback` or 4557 * :type:`nghttp2_on_frame_not_send_callback` is called. 4558 * 4559 * HTTP/2 specification has requirement about header fields in the 4560 * request HEADERS. See the specification for more details. 4561 * 4562 * If |data_prd| is not ``NULL``, it provides data which will be sent 4563 * in subsequent DATA frames. In this case, a method that allows 4564 * request message bodies 4565 * (https://tools.ietf.org/html/rfc7231#section-4) must be specified 4566 * with ``:method`` key in |nva| (e.g. ``POST``). This function does 4567 * not take ownership of the |data_prd|. The function copies the 4568 * members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have 4569 * END_STREAM set. The |stream_user_data| is data associated to the 4570 * stream opened by this request and can be an arbitrary pointer, 4571 * which can be retrieved later by 4572 * `nghttp2_session_get_stream_user_data()`. 4573 * 4574 * This function returns assigned stream ID if it succeeds, or one of 4575 * the following negative error codes: 4576 * 4577 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4578 * Out of memory. 4579 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` 4580 * No stream ID is available because maximum stream ID was 4581 * reached. 4582 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4583 * The |session| is server session. 4584 * 4585 * .. warning:: 4586 * 4587 * This function returns assigned stream ID if it succeeds. But 4588 * that stream is not created yet. The application must not submit 4589 * frame to that stream ID before 4590 * :type:`nghttp2_before_frame_send_callback` is called for this 4591 * frame. This means `nghttp2_session_get_stream_user_data()` does 4592 * not work before the callback. But 4593 * `nghttp2_session_set_stream_user_data()` handles this situation 4594 * specially, and it can set data to a stream during this period. 4595 * 4596 */ 4597 NGHTTP2_EXTERN int32_t nghttp2_submit_request2( 4598 nghttp2_session *session, const nghttp2_priority_spec *pri_spec, 4599 const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider2 *data_prd, 4600 void *stream_user_data); 4601 4602 #ifndef NGHTTP2_NO_SSIZE_T 4603 /** 4604 * @function 4605 * 4606 * .. warning:: 4607 * 4608 * Deprecated. Use `nghttp2_submit_response2()` instead. 4609 * 4610 * Submits response HEADERS frame and optionally one or more DATA 4611 * frames against the stream |stream_id|. 4612 * 4613 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4614 * |nvlen| elements. The application is responsible to include 4615 * required pseudo-header fields (header field whose name starts with 4616 * ":") in |nva| and must place pseudo-headers before regular header 4617 * fields. 4618 * 4619 * This function creates copies of all name/value pairs in |nva|. It 4620 * also lower-cases all names in |nva|. The order of elements in 4621 * |nva| is preserved. For header fields with 4622 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 4623 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 4624 * header field name and value are not copied respectively. With 4625 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 4626 * is responsible to pass header field name in lowercase. The 4627 * application should maintain the references to them until 4628 * :type:`nghttp2_on_frame_send_callback` or 4629 * :type:`nghttp2_on_frame_not_send_callback` is called. 4630 * 4631 * HTTP/2 specification has requirement about header fields in the 4632 * response HEADERS. See the specification for more details. 4633 * 4634 * If |data_prd| is not ``NULL``, it provides data which will be sent 4635 * in subsequent DATA frames. This function does not take ownership 4636 * of the |data_prd|. The function copies the members of the 4637 * |data_prd|. If |data_prd| is ``NULL``, HEADERS will have 4638 * END_STREAM flag set. 4639 * 4640 * This method can be used as normal HTTP response and push response. 4641 * When pushing a resource using this function, the |session| must be 4642 * configured using `nghttp2_session_server_new()` or its variants and 4643 * the target stream denoted by the |stream_id| must be reserved using 4644 * `nghttp2_submit_push_promise()`. 4645 * 4646 * To send non-final response headers (e.g., HTTP status 101), don't 4647 * use this function because this function half-closes the outbound 4648 * stream. Instead, use `nghttp2_submit_headers()` for this purpose. 4649 * 4650 * This function returns 0 if it succeeds, or one of the following 4651 * negative error codes: 4652 * 4653 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4654 * Out of memory. 4655 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4656 * The |stream_id| is 0. 4657 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` 4658 * DATA or HEADERS has been already submitted and not fully 4659 * processed yet. Normally, this does not happen, but when 4660 * application wrongly calls `nghttp2_submit_response()` twice, 4661 * this may happen. 4662 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4663 * The |session| is client session. 4664 * 4665 * .. warning:: 4666 * 4667 * Calling this function twice for the same stream ID may lead to 4668 * program crash. It is generally considered to a programming error 4669 * to commit response twice. 4670 */ 4671 NGHTTP2_EXTERN int 4672 nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, 4673 const nghttp2_nv *nva, size_t nvlen, 4674 const nghttp2_data_provider *data_prd); 4675 4676 #endif /* NGHTTP2_NO_SSIZE_T */ 4677 4678 /** 4679 * @function 4680 * 4681 * Submits response HEADERS frame and optionally one or more DATA 4682 * frames against the stream |stream_id|. 4683 * 4684 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4685 * |nvlen| elements. The application is responsible to include 4686 * required pseudo-header fields (header field whose name starts with 4687 * ":") in |nva| and must place pseudo-headers before regular header 4688 * fields. 4689 * 4690 * This function creates copies of all name/value pairs in |nva|. It 4691 * also lower-cases all names in |nva|. The order of elements in 4692 * |nva| is preserved. For header fields with 4693 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 4694 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 4695 * header field name and value are not copied respectively. With 4696 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 4697 * is responsible to pass header field name in lowercase. The 4698 * application should maintain the references to them until 4699 * :type:`nghttp2_on_frame_send_callback` or 4700 * :type:`nghttp2_on_frame_not_send_callback` is called. 4701 * 4702 * HTTP/2 specification has requirement about header fields in the 4703 * response HEADERS. See the specification for more details. 4704 * 4705 * If |data_prd| is not ``NULL``, it provides data which will be sent 4706 * in subsequent DATA frames. This function does not take ownership 4707 * of the |data_prd|. The function copies the members of the 4708 * |data_prd|. If |data_prd| is ``NULL``, HEADERS will have 4709 * END_STREAM flag set. 4710 * 4711 * This method can be used as normal HTTP response and push response. 4712 * When pushing a resource using this function, the |session| must be 4713 * configured using `nghttp2_session_server_new()` or its variants and 4714 * the target stream denoted by the |stream_id| must be reserved using 4715 * `nghttp2_submit_push_promise()`. 4716 * 4717 * To send non-final response headers (e.g., HTTP status 101), don't 4718 * use this function because this function half-closes the outbound 4719 * stream. Instead, use `nghttp2_submit_headers()` for this purpose. 4720 * 4721 * This function returns 0 if it succeeds, or one of the following 4722 * negative error codes: 4723 * 4724 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4725 * Out of memory. 4726 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4727 * The |stream_id| is 0. 4728 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` 4729 * DATA or HEADERS has been already submitted and not fully 4730 * processed yet. Normally, this does not happen, but when 4731 * application wrongly calls `nghttp2_submit_response2()` twice, 4732 * this may happen. 4733 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4734 * The |session| is client session. 4735 * 4736 * .. warning:: 4737 * 4738 * Calling this function twice for the same stream ID may lead to 4739 * program crash. It is generally considered to a programming error 4740 * to commit response twice. 4741 */ 4742 NGHTTP2_EXTERN int 4743 nghttp2_submit_response2(nghttp2_session *session, int32_t stream_id, 4744 const nghttp2_nv *nva, size_t nvlen, 4745 const nghttp2_data_provider2 *data_prd); 4746 4747 /** 4748 * @function 4749 * 4750 * Submits trailer fields HEADERS against the stream |stream_id|. 4751 * 4752 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4753 * |nvlen| elements. The application must not include pseudo-header 4754 * fields (headers whose names starts with ":") in |nva|. 4755 * 4756 * This function creates copies of all name/value pairs in |nva|. It 4757 * also lower-cases all names in |nva|. The order of elements in 4758 * |nva| is preserved. For header fields with 4759 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 4760 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 4761 * header field name and value are not copied respectively. With 4762 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 4763 * is responsible to pass header field name in lowercase. The 4764 * application should maintain the references to them until 4765 * :type:`nghttp2_on_frame_send_callback` or 4766 * :type:`nghttp2_on_frame_not_send_callback` is called. 4767 * 4768 * For server, trailer fields must follow response HEADERS or response 4769 * DATA without END_STREAM flat set. The library does not enforce 4770 * this requirement, and applications should do this for themselves. 4771 * If `nghttp2_submit_trailer()` is called before any response HEADERS 4772 * submission (usually by `nghttp2_submit_response2()`), the content 4773 * of |nva| will be sent as response headers, which will result in 4774 * error. 4775 * 4776 * This function has the same effect with `nghttp2_submit_headers()`, 4777 * with flags = :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` and both 4778 * pri_spec and stream_user_data to NULL. 4779 * 4780 * To submit trailer fields after `nghttp2_submit_response2()` is 4781 * called, the application has to specify 4782 * :type:`nghttp2_data_provider2` to `nghttp2_submit_response2()`. 4783 * Inside of :type:`nghttp2_data_source_read_callback2`, when setting 4784 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF`, also set 4785 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM`. After 4786 * that, the application can send trailer fields using 4787 * `nghttp2_submit_trailer()`. `nghttp2_submit_trailer()` can be used 4788 * inside :type:`nghttp2_data_source_read_callback2`. 4789 * 4790 * This function returns 0 if it succeeds and |stream_id| is -1. 4791 * Otherwise, this function returns 0 if it succeeds, or one of the 4792 * following negative error codes: 4793 * 4794 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4795 * Out of memory. 4796 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4797 * The |stream_id| is 0. 4798 */ 4799 NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session, 4800 int32_t stream_id, 4801 const nghttp2_nv *nva, size_t nvlen); 4802 4803 /** 4804 * @function 4805 * 4806 * Submits HEADERS frame. The |flags| is bitwise OR of the 4807 * following values: 4808 * 4809 * * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` 4810 * 4811 * If |flags| includes :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, 4812 * this frame has END_STREAM flag set. 4813 * 4814 * The library handles the CONTINUATION frame internally and it 4815 * correctly sets END_HEADERS to the last sequence of the PUSH_PROMISE 4816 * or CONTINUATION frame. 4817 * 4818 * If the |stream_id| is -1, this frame is assumed as request (i.e., 4819 * request HEADERS frame which opens new stream). In this case, the 4820 * assigned stream ID will be returned. Otherwise, specify stream ID 4821 * in |stream_id|. 4822 * 4823 * The |pri_spec| is ignored. 4824 * 4825 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4826 * |nvlen| elements. The application is responsible to include 4827 * required pseudo-header fields (header field whose name starts with 4828 * ":") in |nva| and must place pseudo-headers before regular header 4829 * fields. 4830 * 4831 * This function creates copies of all name/value pairs in |nva|. It 4832 * also lower-cases all names in |nva|. The order of elements in 4833 * |nva| is preserved. For header fields with 4834 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 4835 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 4836 * header field name and value are not copied respectively. With 4837 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 4838 * is responsible to pass header field name in lowercase. The 4839 * application should maintain the references to them until 4840 * :type:`nghttp2_on_frame_send_callback` or 4841 * :type:`nghttp2_on_frame_not_send_callback` is called. 4842 * 4843 * The |stream_user_data| is a pointer to an arbitrary data which is 4844 * associated to the stream this frame will open. Therefore it is 4845 * only used if this frame opens streams, in other words, it changes 4846 * stream state from idle or reserved to open. 4847 * 4848 * This function is low-level in a sense that the application code can 4849 * specify flags directly. For usual HTTP request, 4850 * `nghttp2_submit_request2()` is useful. Likewise, for HTTP 4851 * response, prefer `nghttp2_submit_response2()`. 4852 * 4853 * This function returns newly assigned stream ID if it succeeds and 4854 * |stream_id| is -1. Otherwise, this function returns 0 if it 4855 * succeeds, or one of the following negative error codes: 4856 * 4857 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4858 * Out of memory. 4859 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` 4860 * No stream ID is available because maximum stream ID was 4861 * reached. 4862 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4863 * The |stream_id| is 0. 4864 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` 4865 * DATA or HEADERS has been already submitted and not fully 4866 * processed yet. This happens if stream denoted by |stream_id| 4867 * is in reserved state. 4868 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4869 * The |stream_id| is -1, and |session| is server session. 4870 * 4871 * .. warning:: 4872 * 4873 * This function returns assigned stream ID if it succeeds and 4874 * |stream_id| is -1. But that stream is not opened yet. The 4875 * application must not submit frame to that stream ID before 4876 * :type:`nghttp2_before_frame_send_callback` is called for this 4877 * frame. 4878 * 4879 */ 4880 NGHTTP2_EXTERN int32_t nghttp2_submit_headers( 4881 nghttp2_session *session, uint8_t flags, int32_t stream_id, 4882 const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen, 4883 void *stream_user_data); 4884 4885 #ifndef NGHTTP2_NO_SSIZE_T 4886 /** 4887 * @function 4888 * 4889 * .. warning:: 4890 * 4891 * Deprecated. Use `nghttp2_submit_data2()` instead. 4892 * 4893 * Submits one or more DATA frames to the stream |stream_id|. The 4894 * data to be sent are provided by |data_prd|. If |flags| contains 4895 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame 4896 * has END_STREAM flag set. 4897 * 4898 * This function does not take ownership of the |data_prd|. The 4899 * function copies the members of the |data_prd|. 4900 * 4901 * This function returns 0 if it succeeds, or one of the following 4902 * negative error codes: 4903 * 4904 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4905 * Out of memory. 4906 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` 4907 * DATA or HEADERS has been already submitted and not fully 4908 * processed yet. 4909 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4910 * The |stream_id| is 0. 4911 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED` 4912 * The stream was already closed; or the |stream_id| is invalid. 4913 * 4914 * .. note:: 4915 * 4916 * Currently, only one DATA or HEADERS is allowed for a stream at a 4917 * time. Submitting these frames more than once before first DATA 4918 * or HEADERS is finished results in 4919 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code. The 4920 * earliest callback which tells that previous frame is done is 4921 * :type:`nghttp2_on_frame_send_callback`. In side that callback, 4922 * new data can be submitted using `nghttp2_submit_data()`. Of 4923 * course, all data except for last one must not have 4924 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|. 4925 * This sounds a bit complicated, and we recommend to use 4926 * `nghttp2_submit_request()` and `nghttp2_submit_response()` to 4927 * avoid this cascading issue. The experience shows that for HTTP 4928 * use, these two functions are enough to implement both client and 4929 * server. 4930 */ 4931 NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, 4932 int32_t stream_id, 4933 const nghttp2_data_provider *data_prd); 4934 4935 #endif /* NGHTTP2_NO_SSIZE_T */ 4936 4937 /** 4938 * @function 4939 * 4940 * Submits one or more DATA frames to the stream |stream_id|. The 4941 * data to be sent are provided by |data_prd|. If |flags| contains 4942 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame 4943 * has END_STREAM flag set. 4944 * 4945 * This function does not take ownership of the |data_prd|. The 4946 * function copies the members of the |data_prd|. 4947 * 4948 * This function returns 0 if it succeeds, or one of the following 4949 * negative error codes: 4950 * 4951 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4952 * Out of memory. 4953 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` 4954 * DATA or HEADERS has been already submitted and not fully 4955 * processed yet. 4956 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4957 * The |stream_id| is 0. 4958 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED` 4959 * The stream was already closed; or the |stream_id| is invalid. 4960 * 4961 * .. note:: 4962 * 4963 * Currently, only one DATA or HEADERS is allowed for a stream at a 4964 * time. Submitting these frames more than once before first DATA 4965 * or HEADERS is finished results in 4966 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code. The 4967 * earliest callback which tells that previous frame is done is 4968 * :type:`nghttp2_on_frame_send_callback`. In side that callback, 4969 * new data can be submitted using `nghttp2_submit_data2()`. Of 4970 * course, all data except for last one must not have 4971 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|. 4972 * This sounds a bit complicated, and we recommend to use 4973 * `nghttp2_submit_request2()` and `nghttp2_submit_response2()` to 4974 * avoid this cascading issue. The experience shows that for HTTP 4975 * use, these two functions are enough to implement both client and 4976 * server. 4977 */ 4978 NGHTTP2_EXTERN int nghttp2_submit_data2(nghttp2_session *session, uint8_t flags, 4979 int32_t stream_id, 4980 const nghttp2_data_provider2 *data_prd); 4981 4982 /** 4983 * @function 4984 * 4985 * .. warning:: 4986 * 4987 * Deprecated. :rfc:`7540` priorities are deprecated by 4988 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4989 * prioritization scheme. 4990 * 4991 * This function is noop. It always returns 0. 4992 */ 4993 NGHTTP2_EXTERN int 4994 nghttp2_submit_priority(nghttp2_session *session, uint8_t flags, 4995 int32_t stream_id, 4996 const nghttp2_priority_spec *pri_spec); 4997 4998 /** 4999 * @macro 5000 * 5001 * :macro:`NGHTTP2_EXTPRI_DEFAULT_URGENCY` is the default urgency 5002 * level for :rfc:`9218` extensible priorities. 5003 */ 5004 #define NGHTTP2_EXTPRI_DEFAULT_URGENCY 3 5005 5006 /** 5007 * @macro 5008 * 5009 * :macro:`NGHTTP2_EXTPRI_URGENCY_HIGH` is the highest urgency level 5010 * for :rfc:`9218` extensible priorities. 5011 */ 5012 #define NGHTTP2_EXTPRI_URGENCY_HIGH 0 5013 5014 /** 5015 * @macro 5016 * 5017 * :macro:`NGHTTP2_EXTPRI_URGENCY_LOW` is the lowest urgency level for 5018 * :rfc:`9218` extensible priorities. 5019 */ 5020 #define NGHTTP2_EXTPRI_URGENCY_LOW 7 5021 5022 /** 5023 * @macro 5024 * 5025 * :macro:`NGHTTP2_EXTPRI_URGENCY_LEVELS` is the number of urgency 5026 * levels for :rfc:`9218` extensible priorities. 5027 */ 5028 #define NGHTTP2_EXTPRI_URGENCY_LEVELS (NGHTTP2_EXTPRI_URGENCY_LOW + 1) 5029 5030 /** 5031 * @struct 5032 * 5033 * :type:`nghttp2_extpri` is :rfc:`9218` extensible priorities 5034 * specification for a stream. 5035 */ 5036 typedef struct nghttp2_extpri { 5037 /** 5038 * :member:`urgency` is the urgency of a stream, it must be in 5039 * [:macro:`NGHTTP2_EXTPRI_URGENCY_HIGH`, 5040 * :macro:`NGHTTP2_EXTPRI_URGENCY_LOW`], inclusive, and 0 is the 5041 * highest urgency. 5042 */ 5043 uint32_t urgency; 5044 /** 5045 * :member:`inc` indicates that a content can be processed 5046 * incrementally or not. If inc is 0, it cannot be processed 5047 * incrementally. If inc is 1, it can be processed incrementally. 5048 * Other value is not permitted. 5049 */ 5050 int inc; 5051 } nghttp2_extpri; 5052 5053 /** 5054 * @function 5055 * 5056 * Submits RST_STREAM frame to cancel/reject the stream |stream_id| 5057 * with the error code |error_code|. 5058 * 5059 * The pre-defined error code is one of :enum:`nghttp2_error_code`. 5060 * 5061 * The |flags| is currently ignored and should be 5062 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5063 * 5064 * This function returns 0 if it succeeds, or one of the following 5065 * negative error codes: 5066 * 5067 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5068 * Out of memory. 5069 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5070 * The |stream_id| is 0. 5071 */ 5072 NGHTTP2_EXTERN int nghttp2_submit_rst_stream(nghttp2_session *session, 5073 uint8_t flags, int32_t stream_id, 5074 uint32_t error_code); 5075 5076 /** 5077 * @function 5078 * 5079 * Stores local settings and submits SETTINGS frame. The |iv| is the 5080 * pointer to the array of :type:`nghttp2_settings_entry`. The |niv| 5081 * indicates the number of :type:`nghttp2_settings_entry`. 5082 * 5083 * The |flags| is currently ignored and should be 5084 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5085 * 5086 * This function does not take ownership of the |iv|. This function 5087 * copies all the elements in the |iv|. 5088 * 5089 * While updating individual stream's local window size, if the window 5090 * size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE, 5091 * RST_STREAM is issued against such a stream. 5092 * 5093 * SETTINGS with :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK` is 5094 * automatically submitted by the library and application could not 5095 * send it at its will. 5096 * 5097 * This function returns 0 if it succeeds, or one of the following 5098 * negative error codes: 5099 * 5100 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5101 * The |iv| contains invalid value (e.g., initial window size 5102 * strictly greater than (1 << 31) - 1. 5103 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5104 * Out of memory. 5105 */ 5106 NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session, 5107 uint8_t flags, 5108 const nghttp2_settings_entry *iv, 5109 size_t niv); 5110 5111 /** 5112 * @function 5113 * 5114 * Submits PUSH_PROMISE frame. 5115 * 5116 * The |flags| is currently ignored. The library handles the 5117 * CONTINUATION frame internally and it correctly sets END_HEADERS to 5118 * the last sequence of the PUSH_PROMISE or CONTINUATION frame. 5119 * 5120 * The |stream_id| must be client initiated stream ID. 5121 * 5122 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 5123 * |nvlen| elements. The application is responsible to include 5124 * required pseudo-header fields (header field whose name starts with 5125 * ":") in |nva| and must place pseudo-headers before regular header 5126 * fields. 5127 * 5128 * This function creates copies of all name/value pairs in |nva|. It 5129 * also lower-cases all names in |nva|. The order of elements in 5130 * |nva| is preserved. For header fields with 5131 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 5132 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 5133 * header field name and value are not copied respectively. With 5134 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 5135 * is responsible to pass header field name in lowercase. The 5136 * application should maintain the references to them until 5137 * :type:`nghttp2_on_frame_send_callback` or 5138 * :type:`nghttp2_on_frame_not_send_callback` is called. 5139 * 5140 * The |promised_stream_user_data| is a pointer to an arbitrary data 5141 * which is associated to the promised stream this frame will open and 5142 * make it in reserved state. It is available using 5143 * `nghttp2_session_get_stream_user_data()`. The application can 5144 * access it in :type:`nghttp2_before_frame_send_callback` and 5145 * :type:`nghttp2_on_frame_send_callback` of this frame. 5146 * 5147 * The client side is not allowed to use this function. 5148 * 5149 * To submit response headers and data, use 5150 * `nghttp2_submit_response2()`. 5151 * 5152 * This function returns assigned promised stream ID if it succeeds, 5153 * or one of the following negative error codes: 5154 * 5155 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5156 * Out of memory. 5157 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 5158 * This function was invoked when |session| is initialized as 5159 * client. 5160 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` 5161 * No stream ID is available because maximum stream ID was 5162 * reached. 5163 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5164 * The |stream_id| is 0; The |stream_id| does not designate stream 5165 * that peer initiated. 5166 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED` 5167 * The stream was already closed; or the |stream_id| is invalid. 5168 * 5169 * .. warning:: 5170 * 5171 * This function returns assigned promised stream ID if it succeeds. 5172 * As of 1.16.0, stream object for pushed resource is created when 5173 * this function succeeds. In that case, the application can submit 5174 * push response for the promised frame. 5175 * 5176 * In 1.15.0 or prior versions, pushed stream is not opened yet when 5177 * this function succeeds. The application must not submit frame to 5178 * that stream ID before :type:`nghttp2_before_frame_send_callback` 5179 * is called for this frame. 5180 * 5181 */ 5182 NGHTTP2_EXTERN int32_t nghttp2_submit_push_promise( 5183 nghttp2_session *session, uint8_t flags, int32_t stream_id, 5184 const nghttp2_nv *nva, size_t nvlen, void *promised_stream_user_data); 5185 5186 /** 5187 * @function 5188 * 5189 * Submits PING frame. You don't have to send PING back when you 5190 * received PING frame. The library automatically submits PING frame 5191 * in this case. 5192 * 5193 * The |flags| is bitwise OR of 0 or more of the following value. 5194 * 5195 * * :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK` 5196 * 5197 * Unless `nghttp2_option_set_no_auto_ping_ack()` is used, the |flags| 5198 * should be :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5199 * 5200 * If the |opaque_data| is non ``NULL``, then it should point to the 8 5201 * bytes array of memory to specify opaque data to send with PING 5202 * frame. If the |opaque_data| is ``NULL``, zero-cleared 8 bytes will 5203 * be sent as opaque data. 5204 * 5205 * This function returns 0 if it succeeds, or one of the following 5206 * negative error codes: 5207 * 5208 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5209 * Out of memory. 5210 */ 5211 NGHTTP2_EXTERN int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags, 5212 const uint8_t *opaque_data); 5213 5214 /** 5215 * @function 5216 * 5217 * Submits GOAWAY frame with the last stream ID |last_stream_id| and 5218 * the error code |error_code|. 5219 * 5220 * The pre-defined error code is one of :enum:`nghttp2_error_code`. 5221 * 5222 * The |flags| is currently ignored and should be 5223 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5224 * 5225 * The |last_stream_id| is peer's stream ID or 0. So if |session| is 5226 * initialized as client, |last_stream_id| must be even or 0. If 5227 * |session| is initialized as server, |last_stream_id| must be odd or 5228 * 0. 5229 * 5230 * The HTTP/2 specification says last_stream_id must not be increased 5231 * from the value previously sent. So the actual value sent as 5232 * last_stream_id is the minimum value between the given 5233 * |last_stream_id| and the last_stream_id previously sent to the 5234 * peer. 5235 * 5236 * If the |opaque_data| is not ``NULL`` and |opaque_data_len| is not 5237 * zero, those data will be sent as additional debug data. The 5238 * library makes a copy of the memory region pointed by |opaque_data| 5239 * with the length |opaque_data_len|, so the caller does not need to 5240 * keep this memory after the return of this function. If the 5241 * |opaque_data_len| is 0, the |opaque_data| could be ``NULL``. 5242 * 5243 * After successful transmission of GOAWAY, following things happen. 5244 * All incoming streams having strictly more than |last_stream_id| are 5245 * closed. All incoming HEADERS which starts new stream are simply 5246 * ignored. After all active streams are handled, both 5247 * `nghttp2_session_want_read()` and `nghttp2_session_want_write()` 5248 * return 0 and the application can close session. 5249 * 5250 * This function returns 0 if it succeeds, or one of the following 5251 * negative error codes: 5252 * 5253 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5254 * Out of memory. 5255 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5256 * The |opaque_data_len| is too large; the |last_stream_id| is 5257 * invalid. 5258 */ 5259 NGHTTP2_EXTERN int nghttp2_submit_goaway(nghttp2_session *session, 5260 uint8_t flags, int32_t last_stream_id, 5261 uint32_t error_code, 5262 const uint8_t *opaque_data, 5263 size_t opaque_data_len); 5264 5265 /** 5266 * @function 5267 * 5268 * Returns the last stream ID of a stream for which 5269 * :type:`nghttp2_on_frame_recv_callback` was invoked most recently. 5270 * The returned value can be used as last_stream_id parameter for 5271 * `nghttp2_submit_goaway()` and 5272 * `nghttp2_session_terminate_session2()`. 5273 * 5274 * This function always succeeds. 5275 */ 5276 NGHTTP2_EXTERN int32_t 5277 nghttp2_session_get_last_proc_stream_id(nghttp2_session *session); 5278 5279 /** 5280 * @function 5281 * 5282 * Returns nonzero if new request can be sent from local endpoint. 5283 * 5284 * This function return 0 if request is not allowed for this session. 5285 * There are several reasons why request is not allowed. Some of the 5286 * reasons are: session is server; stream ID has been spent; GOAWAY 5287 * has been sent or received. 5288 * 5289 * The application can call `nghttp2_submit_request2()` without 5290 * consulting this function. In that case, 5291 * `nghttp2_submit_request2()` may return error. Or, request is 5292 * failed to sent, and :type:`nghttp2_on_stream_close_callback` is 5293 * called. 5294 */ 5295 NGHTTP2_EXTERN int 5296 nghttp2_session_check_request_allowed(nghttp2_session *session); 5297 5298 /** 5299 * @function 5300 * 5301 * Returns nonzero if |session| is initialized as server side session. 5302 */ 5303 NGHTTP2_EXTERN int 5304 nghttp2_session_check_server_session(nghttp2_session *session); 5305 5306 /** 5307 * @function 5308 * 5309 * Submits WINDOW_UPDATE frame. 5310 * 5311 * The |flags| is currently ignored and should be 5312 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5313 * 5314 * The |stream_id| is the stream ID to send this WINDOW_UPDATE. To 5315 * send connection level WINDOW_UPDATE, specify 0 to |stream_id|. 5316 * 5317 * If the |window_size_increment| is positive, the WINDOW_UPDATE with 5318 * that value as window_size_increment is queued. If the 5319 * |window_size_increment| is larger than the received bytes from the 5320 * remote endpoint, the local window size is increased by that 5321 * difference. If the sole purpose is to increase the local window 5322 * size, consider to use `nghttp2_session_set_local_window_size()`. 5323 * 5324 * If the |window_size_increment| is negative, the local window size 5325 * is decreased by -|window_size_increment|. If automatic 5326 * WINDOW_UPDATE is enabled 5327 * (`nghttp2_option_set_no_auto_window_update()`), and the library 5328 * decided that the WINDOW_UPDATE should be submitted, then 5329 * WINDOW_UPDATE is queued with the current received bytes count. If 5330 * the sole purpose is to decrease the local window size, consider to 5331 * use `nghttp2_session_set_local_window_size()`. 5332 * 5333 * If the |window_size_increment| is 0, the function does nothing and 5334 * returns 0. 5335 * 5336 * This function returns 0 if it succeeds, or one of the following 5337 * negative error codes: 5338 * 5339 * :enum:`nghttp2_error.NGHTTP2_ERR_FLOW_CONTROL` 5340 * The local window size overflow or gets negative. 5341 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5342 * Out of memory. 5343 */ 5344 NGHTTP2_EXTERN int nghttp2_submit_window_update(nghttp2_session *session, 5345 uint8_t flags, 5346 int32_t stream_id, 5347 int32_t window_size_increment); 5348 5349 /** 5350 * @function 5351 * 5352 * Set local window size (local endpoints's window size) to the given 5353 * |window_size| for the given stream denoted by |stream_id|. To 5354 * change connection level window size, specify 0 to |stream_id|. To 5355 * increase window size, this function may submit WINDOW_UPDATE frame 5356 * to transmission queue. 5357 * 5358 * The |flags| is currently ignored and should be 5359 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5360 * 5361 * This sounds similar to `nghttp2_submit_window_update()`, but there 5362 * are 2 differences. The first difference is that this function 5363 * takes the absolute value of window size to set, rather than the 5364 * delta. To change the window size, this may be easier to use since 5365 * the application just declares the intended window size, rather than 5366 * calculating delta. The second difference is that 5367 * `nghttp2_submit_window_update()` affects the received bytes count 5368 * which has not acked yet. By the specification of 5369 * `nghttp2_submit_window_update()`, to strictly increase the local 5370 * window size, we have to submit delta including all received bytes 5371 * count, which might not be desirable in some cases. On the other 5372 * hand, this function does not affect the received bytes count. It 5373 * just sets the local window size to the given value. 5374 * 5375 * This function returns 0 if it succeeds, or one of the following 5376 * negative error codes: 5377 * 5378 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5379 * The |stream_id| is negative. 5380 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5381 * Out of memory. 5382 */ 5383 NGHTTP2_EXTERN int 5384 nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags, 5385 int32_t stream_id, int32_t window_size); 5386 5387 /** 5388 * @function 5389 * 5390 * Submits extension frame. 5391 * 5392 * Application can pass arbitrary frame flags and stream ID in |flags| 5393 * and |stream_id| respectively. The |payload| is opaque pointer, and 5394 * it can be accessible though ``frame->ext.payload`` in 5395 * :type:`nghttp2_pack_extension_callback2`. The library will not own 5396 * passed |payload| pointer. 5397 * 5398 * The application must set :type:`nghttp2_pack_extension_callback2` 5399 * using `nghttp2_session_callbacks_set_pack_extension_callback2()`. 5400 * 5401 * The application should retain the memory pointed by |payload| until 5402 * the transmission of extension frame is done (which is indicated by 5403 * :type:`nghttp2_on_frame_send_callback`), or transmission fails 5404 * (which is indicated by :type:`nghttp2_on_frame_not_send_callback`). 5405 * If application does not touch this memory region after packing it 5406 * into a wire format, application can free it inside 5407 * :type:`nghttp2_pack_extension_callback2`. 5408 * 5409 * The standard HTTP/2 frame cannot be sent with this function, so 5410 * |type| must be strictly grater than 0x9. Otherwise, this function 5411 * will fail with error code 5412 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`. 5413 * 5414 * This function returns 0 if it succeeds, or one of the following 5415 * negative error codes: 5416 * 5417 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5418 * If :type:`nghttp2_pack_extension_callback2` is not set. 5419 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5420 * If |type| specifies standard HTTP/2 frame type. The frame 5421 * types in the rage [0x0, 0x9], both inclusive, are standard 5422 * HTTP/2 frame type, and cannot be sent using this function. 5423 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5424 * Out of memory 5425 */ 5426 NGHTTP2_EXTERN int nghttp2_submit_extension(nghttp2_session *session, 5427 uint8_t type, uint8_t flags, 5428 int32_t stream_id, void *payload); 5429 5430 /** 5431 * @struct 5432 * 5433 * The payload of ALTSVC frame. ALTSVC frame is a non-critical 5434 * extension to HTTP/2. If this frame is received, and 5435 * `nghttp2_option_set_user_recv_extension_type()` is not set, and 5436 * `nghttp2_option_set_builtin_recv_extension_type()` is set for 5437 * :enum:`nghttp2_frame_type.NGHTTP2_ALTSVC`, 5438 * ``nghttp2_extension.payload`` will point to this struct. 5439 * 5440 * It has the following members: 5441 */ 5442 typedef struct { 5443 /** 5444 * The pointer to origin which this alternative service is 5445 * associated with. This is not necessarily NULL-terminated. 5446 */ 5447 uint8_t *origin; 5448 /** 5449 * The length of the |origin|. 5450 */ 5451 size_t origin_len; 5452 /** 5453 * The pointer to Alt-Svc field value contained in ALTSVC frame. 5454 * This is not necessarily NULL-terminated. 5455 */ 5456 uint8_t *field_value; 5457 /** 5458 * The length of the |field_value|. 5459 */ 5460 size_t field_value_len; 5461 } nghttp2_ext_altsvc; 5462 5463 /** 5464 * @function 5465 * 5466 * Submits ALTSVC frame. 5467 * 5468 * ALTSVC frame is a non-critical extension to HTTP/2, and defined in 5469 * `RFC 7383 <https://tools.ietf.org/html/rfc7838#section-4>`_. 5470 * 5471 * The |flags| is currently ignored and should be 5472 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5473 * 5474 * The |origin| points to the origin this alternative service is 5475 * associated with. The |origin_len| is the length of the origin. If 5476 * |stream_id| is 0, the origin must be specified. If |stream_id| is 5477 * not zero, the origin must be empty (in other words, |origin_len| 5478 * must be 0). 5479 * 5480 * The ALTSVC frame is only usable from server side. If this function 5481 * is invoked with client side session, this function returns 5482 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. 5483 * 5484 * This function returns 0 if it succeeds, or one of the following 5485 * negative error codes: 5486 * 5487 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5488 * Out of memory 5489 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5490 * The function is called from client side session 5491 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5492 * The sum of |origin_len| and |field_value_len| is larger than 5493 * 16382; or |origin_len| is 0 while |stream_id| is 0; or 5494 * |origin_len| is not 0 while |stream_id| is not 0. 5495 */ 5496 NGHTTP2_EXTERN int nghttp2_submit_altsvc(nghttp2_session *session, 5497 uint8_t flags, int32_t stream_id, 5498 const uint8_t *origin, 5499 size_t origin_len, 5500 const uint8_t *field_value, 5501 size_t field_value_len); 5502 5503 /** 5504 * @struct 5505 * 5506 * The single entry of an origin. 5507 */ 5508 typedef struct { 5509 /** 5510 * The pointer to origin. No validation is made against this field 5511 * by the library. This is not necessarily NULL-terminated. 5512 */ 5513 uint8_t *origin; 5514 /** 5515 * The length of the |origin|. 5516 */ 5517 size_t origin_len; 5518 } nghttp2_origin_entry; 5519 5520 /** 5521 * @struct 5522 * 5523 * The payload of ORIGIN frame. ORIGIN frame is a non-critical 5524 * extension to HTTP/2 and defined by `RFC 8336 5525 * <https://tools.ietf.org/html/rfc8336>`_. 5526 * 5527 * If this frame is received, and 5528 * `nghttp2_option_set_user_recv_extension_type()` is not set, and 5529 * `nghttp2_option_set_builtin_recv_extension_type()` is set for 5530 * :enum:`nghttp2_frame_type.NGHTTP2_ORIGIN`, 5531 * ``nghttp2_extension.payload`` will point to this struct. 5532 * 5533 * It has the following members: 5534 */ 5535 typedef struct { 5536 /** 5537 * The number of origins contained in |ov|. 5538 */ 5539 size_t nov; 5540 /** 5541 * The pointer to the array of origins contained in ORIGIN frame. 5542 */ 5543 nghttp2_origin_entry *ov; 5544 } nghttp2_ext_origin; 5545 5546 /** 5547 * @function 5548 * 5549 * Submits ORIGIN frame. 5550 * 5551 * ORIGIN frame is a non-critical extension to HTTP/2 and defined by 5552 * `RFC 8336 <https://tools.ietf.org/html/rfc8336>`_. 5553 * 5554 * The |flags| is currently ignored and should be 5555 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5556 * 5557 * The |ov| points to the array of origins. The |nov| specifies the 5558 * number of origins included in |ov|. This function creates copies 5559 * of all elements in |ov|. 5560 * 5561 * The ORIGIN frame is only usable by a server. If this function is 5562 * invoked with client side session, this function returns 5563 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. 5564 * 5565 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5566 * Out of memory 5567 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5568 * The function is called from client side session. 5569 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5570 * There are too many origins, or an origin is too large to fit 5571 * into a default frame payload. 5572 */ 5573 NGHTTP2_EXTERN int nghttp2_submit_origin(nghttp2_session *session, 5574 uint8_t flags, 5575 const nghttp2_origin_entry *ov, 5576 size_t nov); 5577 5578 /** 5579 * @struct 5580 * 5581 * The payload of PRIORITY_UPDATE frame. PRIORITY_UPDATE frame is a 5582 * non-critical extension to HTTP/2. If this frame is received, and 5583 * `nghttp2_option_set_user_recv_extension_type()` is not set, and 5584 * `nghttp2_option_set_builtin_recv_extension_type()` is set for 5585 * :enum:`nghttp2_frame_type.NGHTTP2_PRIORITY_UPDATE`, 5586 * ``nghttp2_extension.payload`` will point to this struct. 5587 * 5588 * It has the following members: 5589 */ 5590 typedef struct { 5591 /** 5592 * The stream ID of the stream whose priority is updated. 5593 */ 5594 int32_t stream_id; 5595 /** 5596 * The pointer to Priority field value. It is not necessarily 5597 * NULL-terminated. 5598 */ 5599 uint8_t *field_value; 5600 /** 5601 * The length of the :member:`field_value`. 5602 */ 5603 size_t field_value_len; 5604 } nghttp2_ext_priority_update; 5605 5606 /** 5607 * @function 5608 * 5609 * Submits PRIORITY_UPDATE frame. 5610 * 5611 * PRIORITY_UPDATE frame is a non-critical extension to HTTP/2, and 5612 * defined in :rfc:`9218#section-7.1`. 5613 * 5614 * The |flags| is currently ignored and should be 5615 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5616 * 5617 * The |stream_id| is the ID of stream which is prioritized. The 5618 * |field_value| points to the Priority field value. The 5619 * |field_value_len| is the length of the Priority field value. 5620 * 5621 * If this function is called by server, 5622 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` is returned. 5623 * 5624 * If 5625 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 5626 * of value of 0 is received by a remote endpoint (or it is omitted), 5627 * this function does nothing and returns 0. 5628 * 5629 * This function returns 0 if it succeeds, or one of the following 5630 * negative error codes: 5631 * 5632 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5633 * Out of memory 5634 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5635 * The function is called from server side session 5636 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5637 * The |field_value_len| is larger than 16380; or |stream_id| is 5638 * 0. 5639 */ 5640 NGHTTP2_EXTERN int nghttp2_submit_priority_update(nghttp2_session *session, 5641 uint8_t flags, 5642 int32_t stream_id, 5643 const uint8_t *field_value, 5644 size_t field_value_len); 5645 5646 /** 5647 * @function 5648 * 5649 * Changes the priority of the existing stream denoted by |stream_id|. 5650 * The new priority is |extpri|. This function is meant to be used by 5651 * server for :rfc:`9218` extensible prioritization scheme. 5652 * 5653 * If |session| is initialized as client, this function returns 5654 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. For client, use 5655 * `nghttp2_submit_priority_update()` instead. 5656 * 5657 * If :member:`extpri->urgency <nghttp2_extpri.urgency>` is out of 5658 * bound, it is set to :macro:`NGHTTP2_EXTPRI_URGENCY_LOW`. 5659 * 5660 * If |ignore_client_signal| is nonzero, server starts to ignore 5661 * client priority signals for this stream. 5662 * 5663 * If 5664 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 5665 * of value of 1 is not submitted via `nghttp2_submit_settings()`, 5666 * this function does nothing and returns 0. 5667 * 5668 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5669 * Out of memory. 5670 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5671 * The |session| is initialized as client. 5672 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5673 * |stream_id| is zero; or a stream denoted by |stream_id| is not 5674 * found. 5675 */ 5676 NGHTTP2_EXTERN int nghttp2_session_change_extpri_stream_priority( 5677 nghttp2_session *session, int32_t stream_id, const nghttp2_extpri *extpri, 5678 int ignore_client_signal); 5679 5680 /** 5681 * @function 5682 * 5683 * Stores the stream priority of the existing stream denoted by 5684 * |stream_id| in the object pointed by |extpri|. This function is 5685 * meant to be used by server for :rfc:`9218` extensible 5686 * prioritization scheme. 5687 * 5688 * If |session| is initialized as client, this function returns 5689 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. 5690 * 5691 * If 5692 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 5693 * of value of 1 is not submitted via `nghttp2_submit_settings()`, 5694 * this function does nothing and returns 0. 5695 * 5696 * This function returns 0 if it succeeds, or one of the following 5697 * negative error codes: 5698 * 5699 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5700 * The |session| is initialized as client. 5701 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5702 * |stream_id| is zero; or a stream denoted by |stream_id| is not 5703 * found. 5704 */ 5705 NGHTTP2_EXTERN int nghttp2_session_get_extpri_stream_priority( 5706 nghttp2_session *session, nghttp2_extpri *extpri, int32_t stream_id); 5707 5708 /** 5709 * @function 5710 * 5711 * Parses Priority header field value pointed by |value| of length 5712 * |len|, and stores the result in the object pointed by |extpri|. 5713 * Priority header field is defined in :rfc:`9218`. 5714 * 5715 * This function does not initialize the object pointed by |extpri| 5716 * before storing the result. It only assigns the values that the 5717 * parser correctly extracted to fields. 5718 * 5719 * This function returns 0 if it succeeds, or one of the following 5720 * negative error codes: 5721 * 5722 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5723 * Failed to parse the header field value. 5724 */ 5725 NGHTTP2_EXTERN int nghttp2_extpri_parse_priority(nghttp2_extpri *extpri, 5726 const uint8_t *value, 5727 size_t len); 5728 5729 /** 5730 * @function 5731 * 5732 * Compares ``lhs->name`` of length ``lhs->namelen`` bytes and 5733 * ``rhs->name`` of length ``rhs->namelen`` bytes. Returns negative 5734 * integer if ``lhs->name`` is found to be less than ``rhs->name``; or 5735 * returns positive integer if ``lhs->name`` is found to be greater 5736 * than ``rhs->name``; or returns 0 otherwise. 5737 */ 5738 NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs, 5739 const nghttp2_nv *rhs); 5740 5741 /** 5742 * @function 5743 * 5744 * .. warning:: 5745 * 5746 * Deprecated. Use `nghttp2_select_alpn` instead. 5747 * 5748 * A helper function for dealing with ALPN in server side. The |in| 5749 * contains peer's protocol list in preferable order. The format of 5750 * |in| is length-prefixed and not null-terminated. For example, 5751 * ``h2`` and ``http/1.1`` stored in |in| like this:: 5752 * 5753 * in[0] = 2 5754 * in[1..2] = "h2" 5755 * in[3] = 8 5756 * in[4..11] = "http/1.1" 5757 * inlen = 12 5758 * 5759 * The selection algorithm is as follows: 5760 * 5761 * 1. If peer's list contains HTTP/2 protocol the library supports, 5762 * it is selected and returns 1. The following step is not taken. 5763 * 5764 * 2. If peer's list contains ``http/1.1``, this function selects 5765 * ``http/1.1`` and returns 0. The following step is not taken. 5766 * 5767 * 3. This function selects nothing and returns -1 (So called 5768 * non-overlap case). In this case, |out| and |outlen| are left 5769 * untouched. 5770 * 5771 * Selecting ``h2`` means that ``h2`` is written into |*out| and its 5772 * length (which is 2) is assigned to |*outlen|. 5773 * 5774 * For ALPN, refer to https://tools.ietf.org/html/rfc7301 5775 * 5776 * To use this method you should do something like:: 5777 * 5778 * static int alpn_select_proto_cb(SSL* ssl, 5779 * const unsigned char **out, 5780 * unsigned char *outlen, 5781 * const unsigned char *in, 5782 * unsigned int inlen, 5783 * void *arg) 5784 * { 5785 * int rv; 5786 * rv = nghttp2_select_next_protocol((unsigned char**)out, outlen, 5787 * in, inlen); 5788 * if (rv == -1) { 5789 * return SSL_TLSEXT_ERR_NOACK; 5790 * } 5791 * if (rv == 1) { 5792 * ((MyType*)arg)->http2_selected = 1; 5793 * } 5794 * return SSL_TLSEXT_ERR_OK; 5795 * } 5796 * ... 5797 * SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, my_obj); 5798 * 5799 */ 5800 NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out, 5801 unsigned char *outlen, 5802 const unsigned char *in, 5803 unsigned int inlen); 5804 5805 /** 5806 * @function 5807 * 5808 * A helper function for dealing with ALPN in server side. The |in| 5809 * contains peer's protocol list in preferable order. The format of 5810 * |in| is length-prefixed and not null-terminated. For example, 5811 * ``h2`` and ``http/1.1`` stored in |in| like this:: 5812 * 5813 * in[0] = 2 5814 * in[1..2] = "h2" 5815 * in[3] = 8 5816 * in[4..11] = "http/1.1" 5817 * inlen = 12 5818 * 5819 * The selection algorithm is as follows: 5820 * 5821 * 1. If peer's list contains HTTP/2 protocol the library supports, 5822 * it is selected and returns 1. The following step is not taken. 5823 * 5824 * 2. If peer's list contains ``http/1.1``, this function selects 5825 * ``http/1.1`` and returns 0. The following step is not taken. 5826 * 5827 * 3. This function selects nothing and returns -1 (So called 5828 * non-overlap case). In this case, |out| and |outlen| are left 5829 * untouched. 5830 * 5831 * Selecting ``h2`` means that ``h2`` is written into |*out| and its 5832 * length (which is 2) is assigned to |*outlen|. 5833 * 5834 * For ALPN, refer to https://tools.ietf.org/html/rfc7301 5835 * 5836 * To use this method you should do something like:: 5837 * 5838 * static int alpn_select_proto_cb(SSL* ssl, 5839 * const unsigned char **out, 5840 * unsigned char *outlen, 5841 * const unsigned char *in, 5842 * unsigned int inlen, 5843 * void *arg) 5844 * { 5845 * int rv; 5846 * rv = nghttp2_select_alpn(out, outlen, in, inlen); 5847 * if (rv == -1) { 5848 * return SSL_TLSEXT_ERR_NOACK; 5849 * } 5850 * if (rv == 1) { 5851 * ((MyType*)arg)->http2_selected = 1; 5852 * } 5853 * return SSL_TLSEXT_ERR_OK; 5854 * } 5855 * ... 5856 * SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, my_obj); 5857 * 5858 */ 5859 NGHTTP2_EXTERN int nghttp2_select_alpn(const unsigned char **out, 5860 unsigned char *outlen, 5861 const unsigned char *in, 5862 unsigned int inlen); 5863 5864 /** 5865 * @function 5866 * 5867 * Returns a pointer to a nghttp2_info struct with version information 5868 * about the run-time library in use. The |least_version| argument 5869 * can be set to a 24 bit numerical value for the least accepted 5870 * version number and if the condition is not met, this function will 5871 * return a ``NULL``. Pass in 0 to skip the version checking. 5872 */ 5873 NGHTTP2_EXTERN nghttp2_info *nghttp2_version(int least_version); 5874 5875 /** 5876 * @function 5877 * 5878 * Returns nonzero if the :type:`nghttp2_error` library error code 5879 * |lib_error| is fatal. 5880 */ 5881 NGHTTP2_EXTERN int nghttp2_is_fatal(int lib_error_code); 5882 5883 /** 5884 * @function 5885 * 5886 * Returns nonzero if HTTP header field name |name| of length |len| is 5887 * valid according to http://tools.ietf.org/html/rfc7230#section-3.2 5888 * 5889 * Because this is a header field name in HTTP2, the upper cased alphabet 5890 * is treated as error. 5891 */ 5892 NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len); 5893 5894 /** 5895 * @function 5896 * 5897 * Returns nonzero if HTTP header field value |value| of length |len| 5898 * is valid according to 5899 * http://tools.ietf.org/html/rfc7230#section-3.2 5900 * 5901 * This function is considered obsolete, and application should 5902 * consider to use `nghttp2_check_header_value_rfc9113()` instead. 5903 */ 5904 NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len); 5905 5906 /** 5907 * @function 5908 * 5909 * Returns nonzero if HTTP header field value |value| of length |len| 5910 * is valid according to 5911 * http://tools.ietf.org/html/rfc7230#section-3.2, plus 5912 * https://datatracker.ietf.org/doc/html/rfc9113#section-8.2.1 5913 */ 5914 NGHTTP2_EXTERN int nghttp2_check_header_value_rfc9113(const uint8_t *value, 5915 size_t len); 5916 5917 /** 5918 * @function 5919 * 5920 * Returns nonzero if the |value| which is supposed to be the value of 5921 * the :method header field is valid according to 5922 * https://datatracker.ietf.org/doc/html/rfc7231#section-4 and 5923 * https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6 5924 */ 5925 NGHTTP2_EXTERN int nghttp2_check_method(const uint8_t *value, size_t len); 5926 5927 /** 5928 * @function 5929 * 5930 * Returns nonzero if the |value| which is supposed to be the value of 5931 * the :path header field is valid according to 5932 * https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3 5933 * 5934 * |value| is valid if it merely consists of the allowed characters. 5935 * In particular, it does not check whether |value| follows the syntax 5936 * of path. The allowed characters are all characters valid by 5937 * `nghttp2_check_header_value` minus SPC and HT. 5938 */ 5939 NGHTTP2_EXTERN int nghttp2_check_path(const uint8_t *value, size_t len); 5940 5941 /** 5942 * @function 5943 * 5944 * Returns nonzero if the |value| which is supposed to be the value of the 5945 * :authority or host header field is valid according to 5946 * https://tools.ietf.org/html/rfc3986#section-3.2 5947 * 5948 * Note that :authority and host field values are not authority. They 5949 * do not include userinfo in RFC 3986, see 5950 * https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2, that 5951 * is, it does not include '@'. This function treats '@' as a valid 5952 * character. 5953 * 5954 * |value| is valid if it merely consists of the allowed characters. 5955 * In particular, it does not check whether |value| follows the syntax 5956 * of authority. 5957 */ 5958 NGHTTP2_EXTERN int nghttp2_check_authority(const uint8_t *value, size_t len); 5959 5960 /* HPACK API */ 5961 5962 struct nghttp2_hd_deflater; 5963 5964 /** 5965 * @struct 5966 * 5967 * HPACK deflater object. 5968 */ 5969 typedef struct nghttp2_hd_deflater nghttp2_hd_deflater; 5970 5971 /** 5972 * @function 5973 * 5974 * Initializes |*deflater_ptr| for deflating name/values pairs. 5975 * 5976 * The |max_deflate_dynamic_table_size| is the upper bound of header 5977 * table size the deflater will use. 5978 * 5979 * If this function fails, |*deflater_ptr| is left untouched. 5980 * 5981 * This function returns 0 if it succeeds, or one of the following 5982 * negative error codes: 5983 * 5984 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5985 * Out of memory. 5986 */ 5987 NGHTTP2_EXTERN int 5988 nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr, 5989 size_t max_deflate_dynamic_table_size); 5990 5991 /** 5992 * @function 5993 * 5994 * Like `nghttp2_hd_deflate_new()`, but with additional custom memory 5995 * allocator specified in the |mem|. 5996 * 5997 * The |mem| can be ``NULL`` and the call is equivalent to 5998 * `nghttp2_hd_deflate_new()`. 5999 * 6000 * This function does not take ownership |mem|. The application is 6001 * responsible for freeing |mem|. 6002 * 6003 * The library code does not refer to |mem| pointer after this 6004 * function returns, so the application can safely free it. 6005 */ 6006 NGHTTP2_EXTERN int 6007 nghttp2_hd_deflate_new2(nghttp2_hd_deflater **deflater_ptr, 6008 size_t max_deflate_dynamic_table_size, 6009 nghttp2_mem *mem); 6010 6011 /** 6012 * @function 6013 * 6014 * Deallocates any resources allocated for |deflater|. 6015 */ 6016 NGHTTP2_EXTERN void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater); 6017 6018 /** 6019 * @function 6020 * 6021 * Changes header table size of the |deflater| to 6022 * |settings_max_dynamic_table_size| bytes. This may trigger eviction 6023 * in the dynamic table. 6024 * 6025 * The |settings_max_dynamic_table_size| should be the value received 6026 * in SETTINGS_HEADER_TABLE_SIZE. 6027 * 6028 * The deflater never uses more memory than 6029 * ``max_deflate_dynamic_table_size`` bytes specified in 6030 * `nghttp2_hd_deflate_new()`. Therefore, if 6031 * |settings_max_dynamic_table_size| > 6032 * ``max_deflate_dynamic_table_size``, resulting maximum table size 6033 * becomes ``max_deflate_dynamic_table_size``. 6034 * 6035 * This function returns 0 if it succeeds, or one of the following 6036 * negative error codes: 6037 * 6038 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6039 * Out of memory. 6040 */ 6041 NGHTTP2_EXTERN int 6042 nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater, 6043 size_t settings_max_dynamic_table_size); 6044 6045 #ifndef NGHTTP2_NO_SSIZE_T 6046 /** 6047 * @function 6048 * 6049 * .. warning:: 6050 * 6051 * Deprecated. Use `nghttp2_hd_deflate_hd2()` instead. 6052 * 6053 * Deflates the |nva|, which has the |nvlen| name/value pairs, into 6054 * the |buf| of length |buflen|. 6055 * 6056 * If |buf| is not large enough to store the deflated header block, 6057 * this function fails with 6058 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller 6059 * should use `nghttp2_hd_deflate_bound()` to know the upper bound of 6060 * buffer size required to deflate given header name/value pairs. 6061 * 6062 * Once this function fails, subsequent call of this function always 6063 * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. 6064 * 6065 * After this function returns, it is safe to delete the |nva|. 6066 * 6067 * This function returns the number of bytes written to |buf| if it 6068 * succeeds, or one of the following negative error codes: 6069 * 6070 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6071 * Out of memory. 6072 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6073 * Deflation process has failed. 6074 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 6075 * The provided |buflen| size is too small to hold the output. 6076 */ 6077 NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, 6078 uint8_t *buf, size_t buflen, 6079 const nghttp2_nv *nva, 6080 size_t nvlen); 6081 6082 #endif /* NGHTTP2_NO_SSIZE_T */ 6083 6084 /** 6085 * @function 6086 * 6087 * Deflates the |nva|, which has the |nvlen| name/value pairs, into 6088 * the |buf| of length |buflen|. 6089 * 6090 * If |buf| is not large enough to store the deflated header block, 6091 * this function fails with 6092 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller 6093 * should use `nghttp2_hd_deflate_bound()` to know the upper bound of 6094 * buffer size required to deflate given header name/value pairs. 6095 * 6096 * Once this function fails, subsequent call of this function always 6097 * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. 6098 * 6099 * After this function returns, it is safe to delete the |nva|. 6100 * 6101 * This function returns the number of bytes written to |buf| if it 6102 * succeeds, or one of the following negative error codes: 6103 * 6104 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6105 * Out of memory. 6106 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6107 * Deflation process has failed. 6108 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 6109 * The provided |buflen| size is too small to hold the output. 6110 */ 6111 NGHTTP2_EXTERN nghttp2_ssize 6112 nghttp2_hd_deflate_hd2(nghttp2_hd_deflater *deflater, uint8_t *buf, 6113 size_t buflen, const nghttp2_nv *nva, size_t nvlen); 6114 6115 #ifndef NGHTTP2_NO_SSIZE_T 6116 /** 6117 * @function 6118 * 6119 * .. warning:: 6120 * 6121 * Deprecated. Use `nghttp2_hd_deflate_hd_vec2()` instead. 6122 * 6123 * Deflates the |nva|, which has the |nvlen| name/value pairs, into 6124 * the |veclen| size of buf vector |vec|. The each size of buffer 6125 * must be set in len field of :type:`nghttp2_vec`. If and only if 6126 * one chunk is filled up completely, next chunk will be used. If 6127 * |vec| is not large enough to store the deflated header block, this 6128 * function fails with 6129 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller 6130 * should use `nghttp2_hd_deflate_bound()` to know the upper bound of 6131 * buffer size required to deflate given header name/value pairs. 6132 * 6133 * Once this function fails, subsequent call of this function always 6134 * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. 6135 * 6136 * After this function returns, it is safe to delete the |nva|. 6137 * 6138 * This function returns the number of bytes written to |vec| if it 6139 * succeeds, or one of the following negative error codes: 6140 * 6141 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6142 * Out of memory. 6143 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6144 * Deflation process has failed. 6145 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 6146 * The provided |buflen| size is too small to hold the output. 6147 */ 6148 NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater, 6149 const nghttp2_vec *vec, 6150 size_t veclen, 6151 const nghttp2_nv *nva, 6152 size_t nvlen); 6153 6154 #endif /* NGHTTP2_NO_SSIZE_T */ 6155 6156 /** 6157 * @function 6158 * 6159 * Deflates the |nva|, which has the |nvlen| name/value pairs, into 6160 * the |veclen| size of buf vector |vec|. The each size of buffer 6161 * must be set in len field of :type:`nghttp2_vec`. If and only if 6162 * one chunk is filled up completely, next chunk will be used. If 6163 * |vec| is not large enough to store the deflated header block, this 6164 * function fails with 6165 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller 6166 * should use `nghttp2_hd_deflate_bound()` to know the upper bound of 6167 * buffer size required to deflate given header name/value pairs. 6168 * 6169 * Once this function fails, subsequent call of this function always 6170 * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. 6171 * 6172 * After this function returns, it is safe to delete the |nva|. 6173 * 6174 * This function returns the number of bytes written to |vec| if it 6175 * succeeds, or one of the following negative error codes: 6176 * 6177 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6178 * Out of memory. 6179 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6180 * Deflation process has failed. 6181 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 6182 * The provided |buflen| size is too small to hold the output. 6183 */ 6184 NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_deflate_hd_vec2( 6185 nghttp2_hd_deflater *deflater, const nghttp2_vec *vec, size_t veclen, 6186 const nghttp2_nv *nva, size_t nvlen); 6187 6188 /** 6189 * @function 6190 * 6191 * Returns an upper bound on the compressed size after deflation of 6192 * |nva| of length |nvlen|. 6193 */ 6194 NGHTTP2_EXTERN size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater, 6195 const nghttp2_nv *nva, 6196 size_t nvlen); 6197 6198 /** 6199 * @function 6200 * 6201 * Returns the number of entries that header table of |deflater| 6202 * contains. This is the sum of the number of static table and 6203 * dynamic table, so the return value is at least 61. 6204 */ 6205 NGHTTP2_EXTERN 6206 size_t nghttp2_hd_deflate_get_num_table_entries(nghttp2_hd_deflater *deflater); 6207 6208 /** 6209 * @function 6210 * 6211 * Returns the table entry denoted by |idx| from header table of 6212 * |deflater|. The |idx| is 1-based, and idx=1 returns first entry of 6213 * static table. idx=62 returns first entry of dynamic table if it 6214 * exists. Specifying idx=0 is error, and this function returns NULL. 6215 * If |idx| is strictly greater than the number of entries the tables 6216 * contain, this function returns NULL. 6217 */ 6218 NGHTTP2_EXTERN 6219 const nghttp2_nv * 6220 nghttp2_hd_deflate_get_table_entry(nghttp2_hd_deflater *deflater, size_t idx); 6221 6222 /** 6223 * @function 6224 * 6225 * Returns the used dynamic table size, including the overhead 32 6226 * bytes per entry described in RFC 7541. 6227 */ 6228 NGHTTP2_EXTERN 6229 size_t nghttp2_hd_deflate_get_dynamic_table_size(nghttp2_hd_deflater *deflater); 6230 6231 /** 6232 * @function 6233 * 6234 * Returns the maximum dynamic table size. 6235 */ 6236 NGHTTP2_EXTERN 6237 size_t 6238 nghttp2_hd_deflate_get_max_dynamic_table_size(nghttp2_hd_deflater *deflater); 6239 6240 struct nghttp2_hd_inflater; 6241 6242 /** 6243 * @struct 6244 * 6245 * HPACK inflater object. 6246 */ 6247 typedef struct nghttp2_hd_inflater nghttp2_hd_inflater; 6248 6249 /** 6250 * @function 6251 * 6252 * Initializes |*inflater_ptr| for inflating name/values pairs. 6253 * 6254 * If this function fails, |*inflater_ptr| is left untouched. 6255 * 6256 * This function returns 0 if it succeeds, or one of the following 6257 * negative error codes: 6258 * 6259 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6260 * Out of memory. 6261 */ 6262 NGHTTP2_EXTERN int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr); 6263 6264 /** 6265 * @function 6266 * 6267 * Like `nghttp2_hd_inflate_new()`, but with additional custom memory 6268 * allocator specified in the |mem|. 6269 * 6270 * The |mem| can be ``NULL`` and the call is equivalent to 6271 * `nghttp2_hd_inflate_new()`. 6272 * 6273 * This function does not take ownership |mem|. The application is 6274 * responsible for freeing |mem|. 6275 * 6276 * The library code does not refer to |mem| pointer after this 6277 * function returns, so the application can safely free it. 6278 */ 6279 NGHTTP2_EXTERN int nghttp2_hd_inflate_new2(nghttp2_hd_inflater **inflater_ptr, 6280 nghttp2_mem *mem); 6281 6282 /** 6283 * @function 6284 * 6285 * Deallocates any resources allocated for |inflater|. 6286 */ 6287 NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater); 6288 6289 /** 6290 * @function 6291 * 6292 * Changes header table size in the |inflater|. This may trigger 6293 * eviction in the dynamic table. 6294 * 6295 * The |settings_max_dynamic_table_size| should be the value 6296 * transmitted in SETTINGS_HEADER_TABLE_SIZE. 6297 * 6298 * This function must not be called while header block is being 6299 * inflated. In other words, this function must be called after 6300 * initialization of |inflater|, but before calling 6301 * `nghttp2_hd_inflate_hd3()`, or after 6302 * `nghttp2_hd_inflate_end_headers()`. Otherwise, 6303 * `NGHTTP2_ERR_INVALID_STATE` was returned. 6304 * 6305 * This function returns 0 if it succeeds, or one of the following 6306 * negative error codes: 6307 * 6308 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6309 * Out of memory. 6310 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 6311 * The function is called while header block is being inflated. 6312 * Probably, application missed to call 6313 * `nghttp2_hd_inflate_end_headers()`. 6314 */ 6315 NGHTTP2_EXTERN int 6316 nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater, 6317 size_t settings_max_dynamic_table_size); 6318 6319 /** 6320 * @enum 6321 * 6322 * The flags for header inflation. 6323 */ 6324 typedef enum { 6325 /** 6326 * No flag set. 6327 */ 6328 NGHTTP2_HD_INFLATE_NONE = 0, 6329 /** 6330 * Indicates all headers were inflated. 6331 */ 6332 NGHTTP2_HD_INFLATE_FINAL = 0x01, 6333 /** 6334 * Indicates a header was emitted. 6335 */ 6336 NGHTTP2_HD_INFLATE_EMIT = 0x02 6337 } nghttp2_hd_inflate_flag; 6338 6339 #ifndef NGHTTP2_NO_SSIZE_T 6340 /** 6341 * @function 6342 * 6343 * .. warning:: 6344 * 6345 * Deprecated. Use `nghttp2_hd_inflate_hd2()` instead. 6346 * 6347 * Inflates name/value block stored in |in| with length |inlen|. This 6348 * function performs decompression. For each successful emission of 6349 * header name/value pair, 6350 * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in 6351 * |*inflate_flags| and name/value pair is assigned to the |nv_out| 6352 * and the function returns. The caller must not free the members of 6353 * |nv_out|. 6354 * 6355 * The |nv_out| may include pointers to the memory region in the |in|. 6356 * The caller must retain the |in| while the |nv_out| is used. 6357 * 6358 * The application should call this function repeatedly until the 6359 * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and 6360 * return value is non-negative. This means the all input values are 6361 * processed successfully. Then the application must call 6362 * `nghttp2_hd_inflate_end_headers()` to prepare for the next header 6363 * block input. 6364 * 6365 * The caller can feed complete compressed header block. It also can 6366 * feed it in several chunks. The caller must set |in_final| to 6367 * nonzero if the given input is the last block of the compressed 6368 * header. 6369 * 6370 * This function returns the number of bytes processed if it succeeds, 6371 * or one of the following negative error codes: 6372 * 6373 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6374 * Out of memory. 6375 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6376 * Inflation process has failed. 6377 * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR` 6378 * The header field name or value is too large. 6379 * 6380 * Example follows:: 6381 * 6382 * int inflate_header_block(nghttp2_hd_inflater *hd_inflater, 6383 * uint8_t *in, size_t inlen, int final) 6384 * { 6385 * ssize_t rv; 6386 * 6387 * for(;;) { 6388 * nghttp2_nv nv; 6389 * int inflate_flags = 0; 6390 * 6391 * rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags, 6392 * in, inlen, final); 6393 * 6394 * if(rv < 0) { 6395 * fprintf(stderr, "inflate failed with error code %zd", rv); 6396 * return -1; 6397 * } 6398 * 6399 * in += rv; 6400 * inlen -= rv; 6401 * 6402 * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { 6403 * fwrite(nv.name, nv.namelen, 1, stderr); 6404 * fprintf(stderr, ": "); 6405 * fwrite(nv.value, nv.valuelen, 1, stderr); 6406 * fprintf(stderr, "\n"); 6407 * } 6408 * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { 6409 * nghttp2_hd_inflate_end_headers(hd_inflater); 6410 * break; 6411 * } 6412 * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 && 6413 * inlen == 0) { 6414 * break; 6415 * } 6416 * } 6417 * 6418 * return 0; 6419 * } 6420 * 6421 */ 6422 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, 6423 nghttp2_nv *nv_out, 6424 int *inflate_flags, uint8_t *in, 6425 size_t inlen, int in_final); 6426 6427 #endif /* NGHTTP2_NO_SSIZE_T */ 6428 6429 #ifndef NGHTTP2_NO_SSIZE_T 6430 /** 6431 * @function 6432 * 6433 * .. warning:: 6434 * 6435 * Deprecated. Use `nghttp2_hd_inflate_hd3()` instead. 6436 * 6437 * Inflates name/value block stored in |in| with length |inlen|. This 6438 * function performs decompression. For each successful emission of 6439 * header name/value pair, 6440 * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in 6441 * |*inflate_flags| and name/value pair is assigned to the |nv_out| 6442 * and the function returns. The caller must not free the members of 6443 * |nv_out|. 6444 * 6445 * The |nv_out| may include pointers to the memory region in the |in|. 6446 * The caller must retain the |in| while the |nv_out| is used. 6447 * 6448 * The application should call this function repeatedly until the 6449 * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and 6450 * return value is non-negative. If that happens, all given input 6451 * data (|inlen| bytes) are processed successfully. Then the 6452 * application must call `nghttp2_hd_inflate_end_headers()` to prepare 6453 * for the next header block input. 6454 * 6455 * In other words, if |in_final| is nonzero, and this function returns 6456 * |inlen|, you can assert that 6457 * :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in 6458 * |*inflate_flags|. 6459 * 6460 * The caller can feed complete compressed header block. It also can 6461 * feed it in several chunks. The caller must set |in_final| to 6462 * nonzero if the given input is the last block of the compressed 6463 * header. 6464 * 6465 * This function returns the number of bytes processed if it succeeds, 6466 * or one of the following negative error codes: 6467 * 6468 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6469 * Out of memory. 6470 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6471 * Inflation process has failed. 6472 * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR` 6473 * The header field name or value is too large. 6474 * 6475 * Example follows:: 6476 * 6477 * int inflate_header_block(nghttp2_hd_inflater *hd_inflater, 6478 * uint8_t *in, size_t inlen, int final) 6479 * { 6480 * ssize_t rv; 6481 * 6482 * for(;;) { 6483 * nghttp2_nv nv; 6484 * int inflate_flags = 0; 6485 * 6486 * rv = nghttp2_hd_inflate_hd2(hd_inflater, &nv, &inflate_flags, 6487 * in, inlen, final); 6488 * 6489 * if(rv < 0) { 6490 * fprintf(stderr, "inflate failed with error code %zd", rv); 6491 * return -1; 6492 * } 6493 * 6494 * in += rv; 6495 * inlen -= rv; 6496 * 6497 * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { 6498 * fwrite(nv.name, nv.namelen, 1, stderr); 6499 * fprintf(stderr, ": "); 6500 * fwrite(nv.value, nv.valuelen, 1, stderr); 6501 * fprintf(stderr, "\n"); 6502 * } 6503 * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { 6504 * nghttp2_hd_inflate_end_headers(hd_inflater); 6505 * break; 6506 * } 6507 * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 && 6508 * inlen == 0) { 6509 * break; 6510 * } 6511 * } 6512 * 6513 * return 0; 6514 * } 6515 * 6516 */ 6517 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, 6518 nghttp2_nv *nv_out, 6519 int *inflate_flags, 6520 const uint8_t *in, size_t inlen, 6521 int in_final); 6522 6523 #endif /* NGHTTP2_NO_SSIZE_T */ 6524 6525 /** 6526 * @function 6527 * 6528 * Inflates name/value block stored in |in| with length |inlen|. This 6529 * function performs decompression. For each successful emission of 6530 * header name/value pair, 6531 * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in 6532 * |*inflate_flags| and name/value pair is assigned to the |nv_out| 6533 * and the function returns. The caller must not free the members of 6534 * |nv_out|. 6535 * 6536 * The |nv_out| may include pointers to the memory region in the |in|. 6537 * The caller must retain the |in| while the |nv_out| is used. 6538 * 6539 * The application should call this function repeatedly until the 6540 * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and 6541 * return value is non-negative. If that happens, all given input 6542 * data (|inlen| bytes) are processed successfully. Then the 6543 * application must call `nghttp2_hd_inflate_end_headers()` to prepare 6544 * for the next header block input. 6545 * 6546 * In other words, if |in_final| is nonzero, and this function returns 6547 * |inlen|, you can assert that 6548 * :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in 6549 * |*inflate_flags|. 6550 * 6551 * The caller can feed complete compressed header block. It also can 6552 * feed it in several chunks. The caller must set |in_final| to 6553 * nonzero if the given input is the last block of the compressed 6554 * header. 6555 * 6556 * This function returns the number of bytes processed if it succeeds, 6557 * or one of the following negative error codes: 6558 * 6559 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6560 * Out of memory. 6561 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6562 * Inflation process has failed. 6563 * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR` 6564 * The header field name or value is too large. 6565 * 6566 * Example follows:: 6567 * 6568 * int inflate_header_block(nghttp2_hd_inflater *hd_inflater, 6569 * uint8_t *in, size_t inlen, int final) 6570 * { 6571 * nghttp2_ssize rv; 6572 * 6573 * for(;;) { 6574 * nghttp2_nv nv; 6575 * int inflate_flags = 0; 6576 * 6577 * rv = nghttp2_hd_inflate_hd3(hd_inflater, &nv, &inflate_flags, 6578 * in, inlen, final); 6579 * 6580 * if(rv < 0) { 6581 * fprintf(stderr, "inflate failed with error code %td", rv); 6582 * return -1; 6583 * } 6584 * 6585 * in += rv; 6586 * inlen -= rv; 6587 * 6588 * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { 6589 * fwrite(nv.name, nv.namelen, 1, stderr); 6590 * fprintf(stderr, ": "); 6591 * fwrite(nv.value, nv.valuelen, 1, stderr); 6592 * fprintf(stderr, "\n"); 6593 * } 6594 * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { 6595 * nghttp2_hd_inflate_end_headers(hd_inflater); 6596 * break; 6597 * } 6598 * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 && 6599 * inlen == 0) { 6600 * break; 6601 * } 6602 * } 6603 * 6604 * return 0; 6605 * } 6606 * 6607 */ 6608 NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_inflate_hd3( 6609 nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags, 6610 const uint8_t *in, size_t inlen, int in_final); 6611 6612 /** 6613 * @function 6614 * 6615 * Signals the end of decompression for one header block. 6616 * 6617 * This function returns 0 if it succeeds. Currently this function 6618 * always succeeds. 6619 */ 6620 NGHTTP2_EXTERN int 6621 nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater); 6622 6623 /** 6624 * @function 6625 * 6626 * Returns the number of entries that header table of |inflater| 6627 * contains. This is the sum of the number of static table and 6628 * dynamic table, so the return value is at least 61. 6629 */ 6630 NGHTTP2_EXTERN 6631 size_t nghttp2_hd_inflate_get_num_table_entries(nghttp2_hd_inflater *inflater); 6632 6633 /** 6634 * @function 6635 * 6636 * Returns the table entry denoted by |idx| from header table of 6637 * |inflater|. The |idx| is 1-based, and idx=1 returns first entry of 6638 * static table. idx=62 returns first entry of dynamic table if it 6639 * exists. Specifying idx=0 is error, and this function returns NULL. 6640 * If |idx| is strictly greater than the number of entries the tables 6641 * contain, this function returns NULL. 6642 */ 6643 NGHTTP2_EXTERN 6644 const nghttp2_nv * 6645 nghttp2_hd_inflate_get_table_entry(nghttp2_hd_inflater *inflater, size_t idx); 6646 6647 /** 6648 * @function 6649 * 6650 * Returns the used dynamic table size, including the overhead 32 6651 * bytes per entry described in RFC 7541. 6652 */ 6653 NGHTTP2_EXTERN 6654 size_t nghttp2_hd_inflate_get_dynamic_table_size(nghttp2_hd_inflater *inflater); 6655 6656 /** 6657 * @function 6658 * 6659 * Returns the maximum dynamic table size. 6660 */ 6661 NGHTTP2_EXTERN 6662 size_t 6663 nghttp2_hd_inflate_get_max_dynamic_table_size(nghttp2_hd_inflater *inflater); 6664 6665 struct nghttp2_stream; 6666 6667 /** 6668 * @struct 6669 * 6670 * The structure to represent HTTP/2 stream. The details of this 6671 * structure are intentionally hidden from the public API. 6672 */ 6673 typedef struct nghttp2_stream nghttp2_stream; 6674 6675 /** 6676 * @function 6677 * 6678 * Returns pointer to :type:`nghttp2_stream` object denoted by 6679 * |stream_id|. If stream was not found, returns NULL. 6680 * 6681 * Returns imaginary root stream (see 6682 * `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|. 6683 * 6684 * Unless |stream_id| == 0, the returned pointer is valid until next 6685 * call of `nghttp2_session_send()`, `nghttp2_session_mem_send2()`, 6686 * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv2()`. 6687 */ 6688 NGHTTP2_EXTERN nghttp2_stream * 6689 nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id); 6690 6691 /** 6692 * @enum 6693 * 6694 * State of stream as described in RFC 7540. 6695 */ 6696 typedef enum { 6697 /** 6698 * idle state. 6699 */ 6700 NGHTTP2_STREAM_STATE_IDLE = 1, 6701 /** 6702 * open state. 6703 */ 6704 NGHTTP2_STREAM_STATE_OPEN, 6705 /** 6706 * reserved (local) state. 6707 */ 6708 NGHTTP2_STREAM_STATE_RESERVED_LOCAL, 6709 /** 6710 * reserved (remote) state. 6711 */ 6712 NGHTTP2_STREAM_STATE_RESERVED_REMOTE, 6713 /** 6714 * half closed (local) state. 6715 */ 6716 NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL, 6717 /** 6718 * half closed (remote) state. 6719 */ 6720 NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE, 6721 /** 6722 * closed state. 6723 */ 6724 NGHTTP2_STREAM_STATE_CLOSED 6725 } nghttp2_stream_proto_state; 6726 6727 /** 6728 * @function 6729 * 6730 * Returns state of |stream|. The root stream retrieved by 6731 * `nghttp2_session_get_root_stream()` will have stream state 6732 * :enum:`nghttp2_stream_proto_state.NGHTTP2_STREAM_STATE_IDLE`. 6733 */ 6734 NGHTTP2_EXTERN nghttp2_stream_proto_state 6735 nghttp2_stream_get_state(nghttp2_stream *stream); 6736 6737 /** 6738 * @function 6739 * 6740 * .. warning:: 6741 * 6742 * Deprecated. :rfc:`7540` priorities are deprecated by 6743 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6744 * prioritization scheme. 6745 * 6746 * Returns root of dependency tree, which is imaginary stream with 6747 * stream ID 0. The returned pointer is valid until |session| is 6748 * freed by `nghttp2_session_del()`. 6749 */ 6750 NGHTTP2_EXTERN nghttp2_stream * 6751 nghttp2_session_get_root_stream(nghttp2_session *session); 6752 6753 /** 6754 * @function 6755 * 6756 * .. warning:: 6757 * 6758 * Deprecated. :rfc:`7540` priorities are deprecated by 6759 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6760 * prioritization scheme. 6761 * 6762 * This function always returns NULL. 6763 */ 6764 NGHTTP2_EXTERN nghttp2_stream * 6765 nghttp2_stream_get_parent(nghttp2_stream *stream); 6766 6767 NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream); 6768 6769 /** 6770 * @function 6771 * 6772 * .. warning:: 6773 * 6774 * Deprecated. :rfc:`7540` priorities are deprecated by 6775 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6776 * prioritization scheme. 6777 * 6778 * This function always returns NULL. 6779 */ 6780 NGHTTP2_EXTERN nghttp2_stream * 6781 nghttp2_stream_get_next_sibling(nghttp2_stream *stream); 6782 6783 /** 6784 * @function 6785 * 6786 * .. warning:: 6787 * 6788 * Deprecated. :rfc:`7540` priorities are deprecated by 6789 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6790 * prioritization scheme. 6791 * 6792 * This function always returns NULL. 6793 */ 6794 NGHTTP2_EXTERN nghttp2_stream * 6795 nghttp2_stream_get_previous_sibling(nghttp2_stream *stream); 6796 6797 /** 6798 * @function 6799 * 6800 * .. warning:: 6801 * 6802 * Deprecated. :rfc:`7540` priorities are deprecated by 6803 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6804 * prioritization scheme. 6805 * 6806 * This function always returns NULL. 6807 */ 6808 NGHTTP2_EXTERN nghttp2_stream * 6809 nghttp2_stream_get_first_child(nghttp2_stream *stream); 6810 6811 /** 6812 * @function 6813 * 6814 * .. warning:: 6815 * 6816 * Deprecated. :rfc:`7540` priorities are deprecated by 6817 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6818 * prioritization scheme. 6819 * 6820 * This function always returns :macro:`NGHTTP2_DEFAULT_WEIGHT`. 6821 */ 6822 NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream); 6823 6824 /** 6825 * @function 6826 * 6827 * .. warning:: 6828 * 6829 * Deprecated. :rfc:`7540` priorities are deprecated by 6830 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6831 * prioritization scheme. 6832 * 6833 * This function always returns 0. 6834 */ 6835 NGHTTP2_EXTERN int32_t 6836 nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream); 6837 6838 /** 6839 * @functypedef 6840 * 6841 * Callback function invoked when the library outputs debug logging. 6842 * The function is called with arguments suitable for ``vfprintf(3)`` 6843 * 6844 * The debug output is only enabled if the library is built with 6845 * ``DEBUGBUILD`` macro defined. 6846 */ 6847 typedef void (*nghttp2_debug_vprintf_callback)(const char *format, 6848 va_list args); 6849 6850 /** 6851 * @function 6852 * 6853 * Sets a debug output callback called by the library when built with 6854 * ``DEBUGBUILD`` macro defined. If this option is not used, debug 6855 * log is written into standard error output. 6856 * 6857 * For builds without ``DEBUGBUILD`` macro defined, this function is 6858 * noop. 6859 * 6860 * Note that building with ``DEBUGBUILD`` may cause significant 6861 * performance penalty to libnghttp2 because of extra processing. It 6862 * should be used for debugging purpose only. 6863 * 6864 * .. Warning:: 6865 * 6866 * Building with ``DEBUGBUILD`` may cause significant performance 6867 * penalty to libnghttp2 because of extra processing. It should be 6868 * used for debugging purpose only. We write this two times because 6869 * this is important. 6870 */ 6871 NGHTTP2_EXTERN void nghttp2_set_debug_vprintf_callback( 6872 nghttp2_debug_vprintf_callback debug_vprintf_callback); 6873 6874 #ifdef __cplusplus 6875 } 6876 #endif 6877 6878 #endif /* NGHTTP2_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|