1 /* 2 * nghttp2 - HTTP/2 C Library 3 * 4 * Copyright (c) 2013, 2014 Tatsuhiro Tsujikawa 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sublicense, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be 15 * included in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 #ifndef NGHTTP2_H 26 #define NGHTTP2_H 27 28 /* Define WIN32 when build target is Win32 API (borrowed from 29 libcurl) */ 30 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) 31 # define WIN32 32 #endif 33 34 /* Compatibility for non-Clang compilers */ 35 #ifndef __has_declspec_attribute 36 # define __has_declspec_attribute(x) 0 37 #endif 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 #include <stdlib.h> 44 #if defined(_MSC_VER) && (_MSC_VER < 1800) 45 /* MSVC < 2013 does not have inttypes.h because it is not C99 46 compliant. See compiler macros and version number in 47 https://sourceforge.net/p/predef/wiki/Compilers/ */ 48 # include <stdint.h> 49 #else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ 50 # include <inttypes.h> 51 #endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ 52 #include <sys/types.h> 53 #include <stdarg.h> 54 #include <stddef.h> 55 56 #include <nghttp2/nghttp2ver.h> 57 58 #ifdef NGHTTP2_STATICLIB 59 # define NGHTTP2_EXTERN 60 #elif defined(WIN32) || (__has_declspec_attribute(dllexport) && \ 61 __has_declspec_attribute(dllimport)) 62 # ifdef BUILDING_NGHTTP2 63 # define NGHTTP2_EXTERN __declspec(dllexport) 64 # else /* !BUILDING_NGHTTP2 */ 65 # define NGHTTP2_EXTERN __declspec(dllimport) 66 # endif /* !BUILDING_NGHTTP2 */ 67 #else /* !defined(WIN32) */ 68 # ifdef BUILDING_NGHTTP2 69 # define NGHTTP2_EXTERN __attribute__((visibility("default"))) 70 # else /* !BUILDING_NGHTTP2 */ 71 # define NGHTTP2_EXTERN 72 # endif /* !BUILDING_NGHTTP2 */ 73 #endif /* !defined(WIN32) */ 74 75 /** 76 * @typedef 77 * 78 * :type:`nghttp2_ssize` is a signed counterpart of size_t. 79 */ 80 typedef ptrdiff_t nghttp2_ssize; 81 82 /** 83 * @macro 84 * 85 * The protocol version identification string of this library 86 * supports. This identifier is used if HTTP/2 is used over TLS. 87 */ 88 #define NGHTTP2_PROTO_VERSION_ID "h2" 89 /** 90 * @macro 91 * 92 * The length of :macro:`NGHTTP2_PROTO_VERSION_ID`. 93 */ 94 #define NGHTTP2_PROTO_VERSION_ID_LEN 2 95 96 /** 97 * @macro 98 * 99 * The serialized form of ALPN protocol identifier this library 100 * supports. Notice that first byte is the length of following 101 * protocol identifier. This is the same wire format of `TLS ALPN 102 * extension <https://tools.ietf.org/html/rfc7301>`_. This is useful 103 * to process incoming ALPN tokens in wire format. 104 */ 105 #define NGHTTP2_PROTO_ALPN "\x2h2" 106 107 /** 108 * @macro 109 * 110 * The length of :macro:`NGHTTP2_PROTO_ALPN`. 111 */ 112 #define NGHTTP2_PROTO_ALPN_LEN (sizeof(NGHTTP2_PROTO_ALPN) - 1) 113 114 /** 115 * @macro 116 * 117 * The protocol version identification string of this library 118 * supports. This identifier is used if HTTP/2 is used over cleartext 119 * TCP. 120 */ 121 #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c" 122 123 /** 124 * @macro 125 * 126 * The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`. 127 */ 128 #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 3 129 130 struct nghttp2_session; 131 /** 132 * @struct 133 * 134 * The primary structure to hold the resources needed for a HTTP/2 135 * session. The details of this structure are intentionally hidden 136 * from the public API. 137 */ 138 typedef struct nghttp2_session nghttp2_session; 139 140 /** 141 * @macro 142 * 143 * The age of :type:`nghttp2_info` 144 */ 145 #define NGHTTP2_VERSION_AGE 1 146 147 /** 148 * @struct 149 * 150 * This struct is what `nghttp2_version()` returns. It holds 151 * information about the particular nghttp2 version. 152 */ 153 typedef struct { 154 /** 155 * Age of this struct. This instance of nghttp2 sets it to 156 * :macro:`NGHTTP2_VERSION_AGE` but a future version may bump it and 157 * add more struct fields at the bottom 158 */ 159 int age; 160 /** 161 * the :macro:`NGHTTP2_VERSION_NUM` number (since age ==1) 162 */ 163 int version_num; 164 /** 165 * points to the :macro:`NGHTTP2_VERSION` string (since age ==1) 166 */ 167 const char *version_str; 168 /** 169 * points to the :macro:`NGHTTP2_PROTO_VERSION_ID` string this 170 * instance implements (since age ==1) 171 */ 172 const char *proto_str; 173 /* -------- the above fields all exist when age == 1 */ 174 } nghttp2_info; 175 176 /** 177 * @macro 178 * 179 * .. warning:: 180 * 181 * Deprecated. :rfc:`7540` priorities are deprecated by 182 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 183 * prioritization scheme. 184 * 185 * The default weight of stream dependency. 186 */ 187 #define NGHTTP2_DEFAULT_WEIGHT 16 188 189 /** 190 * @macro 191 * 192 * .. warning:: 193 * 194 * Deprecated. :rfc:`7540` priorities are deprecated by 195 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 196 * prioritization scheme. 197 * 198 * The maximum weight of stream dependency. 199 */ 200 #define NGHTTP2_MAX_WEIGHT 256 201 202 /** 203 * @macro 204 * 205 * .. warning:: 206 * 207 * Deprecated. :rfc:`7540` priorities are deprecated by 208 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 209 * prioritization scheme. 210 * 211 * The minimum weight of stream dependency. 212 */ 213 #define NGHTTP2_MIN_WEIGHT 1 214 215 /** 216 * @macro 217 * 218 * The maximum window size 219 */ 220 #define NGHTTP2_MAX_WINDOW_SIZE ((int32_t)((1U << 31) - 1)) 221 222 /** 223 * @macro 224 * 225 * The initial window size for stream level flow control. 226 */ 227 #define NGHTTP2_INITIAL_WINDOW_SIZE ((1 << 16) - 1) 228 /** 229 * @macro 230 * 231 * The initial window size for connection level flow control. 232 */ 233 #define NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE ((1 << 16) - 1) 234 235 /** 236 * @macro 237 * 238 * The default header table size. 239 */ 240 #define NGHTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12) 241 242 /** 243 * @macro 244 * 245 * The client magic string, which is the first 24 bytes byte string of 246 * client connection preface. 247 */ 248 #define NGHTTP2_CLIENT_MAGIC "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" 249 250 /** 251 * @macro 252 * 253 * The length of :macro:`NGHTTP2_CLIENT_MAGIC`. 254 */ 255 #define NGHTTP2_CLIENT_MAGIC_LEN 24 256 257 /** 258 * @macro 259 * 260 * The default max number of settings per SETTINGS frame 261 */ 262 #define NGHTTP2_DEFAULT_MAX_SETTINGS 32 263 264 /** 265 * @enum 266 * 267 * Error codes used in this library. The code range is [-999, -500], 268 * inclusive. The following values are defined: 269 */ 270 typedef enum { 271 /** 272 * Invalid argument passed. 273 */ 274 NGHTTP2_ERR_INVALID_ARGUMENT = -501, 275 /** 276 * Out of buffer space. 277 */ 278 NGHTTP2_ERR_BUFFER_ERROR = -502, 279 /** 280 * The specified protocol version is not supported. 281 */ 282 NGHTTP2_ERR_UNSUPPORTED_VERSION = -503, 283 /** 284 * Used as a return value from :type:`nghttp2_send_callback2`, 285 * :type:`nghttp2_recv_callback` and 286 * :type:`nghttp2_send_data_callback` to indicate that the operation 287 * would block. 288 */ 289 NGHTTP2_ERR_WOULDBLOCK = -504, 290 /** 291 * General protocol error 292 */ 293 NGHTTP2_ERR_PROTO = -505, 294 /** 295 * The frame is invalid. 296 */ 297 NGHTTP2_ERR_INVALID_FRAME = -506, 298 /** 299 * The peer performed a shutdown on the connection. 300 */ 301 NGHTTP2_ERR_EOF = -507, 302 /** 303 * Used as a return value from 304 * :func:`nghttp2_data_source_read_callback2` to indicate that data 305 * transfer is postponed. See 306 * :func:`nghttp2_data_source_read_callback2` for details. 307 */ 308 NGHTTP2_ERR_DEFERRED = -508, 309 /** 310 * Stream ID has reached the maximum value. Therefore no stream ID 311 * is available. 312 */ 313 NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509, 314 /** 315 * The stream is already closed; or the stream ID is invalid. 316 */ 317 NGHTTP2_ERR_STREAM_CLOSED = -510, 318 /** 319 * RST_STREAM has been added to the outbound queue. The stream is 320 * in closing state. 321 */ 322 NGHTTP2_ERR_STREAM_CLOSING = -511, 323 /** 324 * The transmission is not allowed for this stream (e.g., a frame 325 * with END_STREAM flag set has already sent). 326 */ 327 NGHTTP2_ERR_STREAM_SHUT_WR = -512, 328 /** 329 * The stream ID is invalid. 330 */ 331 NGHTTP2_ERR_INVALID_STREAM_ID = -513, 332 /** 333 * The state of the stream is not valid (e.g., DATA cannot be sent 334 * to the stream if response HEADERS has not been sent). 335 */ 336 NGHTTP2_ERR_INVALID_STREAM_STATE = -514, 337 /** 338 * Another DATA frame has already been deferred. 339 */ 340 NGHTTP2_ERR_DEFERRED_DATA_EXIST = -515, 341 /** 342 * Starting new stream is not allowed (e.g., GOAWAY has been sent 343 * and/or received). 344 */ 345 NGHTTP2_ERR_START_STREAM_NOT_ALLOWED = -516, 346 /** 347 * GOAWAY has already been sent. 348 */ 349 NGHTTP2_ERR_GOAWAY_ALREADY_SENT = -517, 350 /** 351 * The received frame contains the invalid header block (e.g., There 352 * are duplicate header names; or the header names are not encoded 353 * in US-ASCII character set and not lower cased; or the header name 354 * is zero-length string; or the header value contains multiple 355 * in-sequence NUL bytes). 356 */ 357 NGHTTP2_ERR_INVALID_HEADER_BLOCK = -518, 358 /** 359 * Indicates that the context is not suitable to perform the 360 * requested operation. 361 */ 362 NGHTTP2_ERR_INVALID_STATE = -519, 363 /** 364 * The user callback function failed due to the temporal error. 365 */ 366 NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE = -521, 367 /** 368 * The length of the frame is invalid, either too large or too small. 369 */ 370 NGHTTP2_ERR_FRAME_SIZE_ERROR = -522, 371 /** 372 * Header block inflate/deflate error. 373 */ 374 NGHTTP2_ERR_HEADER_COMP = -523, 375 /** 376 * Flow control error 377 */ 378 NGHTTP2_ERR_FLOW_CONTROL = -524, 379 /** 380 * Insufficient buffer size given to function. 381 */ 382 NGHTTP2_ERR_INSUFF_BUFSIZE = -525, 383 /** 384 * Callback was paused by the application 385 */ 386 NGHTTP2_ERR_PAUSE = -526, 387 /** 388 * There are too many in-flight SETTING frame and no more 389 * transmission of SETTINGS is allowed. 390 */ 391 NGHTTP2_ERR_TOO_MANY_INFLIGHT_SETTINGS = -527, 392 /** 393 * The server push is disabled. 394 */ 395 NGHTTP2_ERR_PUSH_DISABLED = -528, 396 /** 397 * DATA or HEADERS frame for a given stream has been already 398 * submitted and has not been fully processed yet. Application 399 * should wait for the transmission of the previously submitted 400 * frame before submitting another. 401 */ 402 NGHTTP2_ERR_DATA_EXIST = -529, 403 /** 404 * The current session is closing due to a connection error or 405 * `nghttp2_session_terminate_session()` is called. 406 */ 407 NGHTTP2_ERR_SESSION_CLOSING = -530, 408 /** 409 * Invalid HTTP header field was received and stream is going to be 410 * closed. 411 */ 412 NGHTTP2_ERR_HTTP_HEADER = -531, 413 /** 414 * Violation in HTTP messaging rule. 415 */ 416 NGHTTP2_ERR_HTTP_MESSAGING = -532, 417 /** 418 * Stream was refused. 419 */ 420 NGHTTP2_ERR_REFUSED_STREAM = -533, 421 /** 422 * Unexpected internal error, but recovered. 423 */ 424 NGHTTP2_ERR_INTERNAL = -534, 425 /** 426 * Indicates that a processing was canceled. 427 */ 428 NGHTTP2_ERR_CANCEL = -535, 429 /** 430 * When a local endpoint expects to receive SETTINGS frame, it 431 * receives an other type of frame. 432 */ 433 NGHTTP2_ERR_SETTINGS_EXPECTED = -536, 434 /** 435 * When a local endpoint receives too many settings entries 436 * in a single SETTINGS frame. 437 */ 438 NGHTTP2_ERR_TOO_MANY_SETTINGS = -537, 439 /** 440 * The errors < :enum:`nghttp2_error.NGHTTP2_ERR_FATAL` mean that 441 * the library is under unexpected condition and processing was 442 * terminated (e.g., out of memory). If application receives this 443 * error code, it must stop using that :type:`nghttp2_session` 444 * object and only allowed operation for that object is deallocate 445 * it using `nghttp2_session_del()`. 446 */ 447 NGHTTP2_ERR_FATAL = -900, 448 /** 449 * Out of memory. This is a fatal error. 450 */ 451 NGHTTP2_ERR_NOMEM = -901, 452 /** 453 * The user callback function failed. This is a fatal error. 454 */ 455 NGHTTP2_ERR_CALLBACK_FAILURE = -902, 456 /** 457 * Invalid client magic (see :macro:`NGHTTP2_CLIENT_MAGIC`) was 458 * received and further processing is not possible. 459 */ 460 NGHTTP2_ERR_BAD_CLIENT_MAGIC = -903, 461 /** 462 * Possible flooding by peer was detected in this HTTP/2 session. 463 * Flooding is measured by how many PING and SETTINGS frames with 464 * ACK flag set are queued for transmission. These frames are 465 * response for the peer initiated frames, and peer can cause memory 466 * exhaustion on server side to send these frames forever and does 467 * not read network. 468 */ 469 NGHTTP2_ERR_FLOODED = -904, 470 /** 471 * When a local endpoint receives too many CONTINUATION frames 472 * following a HEADER frame. 473 */ 474 NGHTTP2_ERR_TOO_MANY_CONTINUATIONS = -905, 475 } nghttp2_error; 476 477 /** 478 * @struct 479 * 480 * The object representing single contiguous buffer. 481 */ 482 typedef struct { 483 /** 484 * The pointer to the buffer. 485 */ 486 uint8_t *base; 487 /** 488 * The length of the buffer. 489 */ 490 size_t len; 491 } nghttp2_vec; 492 493 struct nghttp2_rcbuf; 494 495 /** 496 * @struct 497 * 498 * The object representing reference counted buffer. The details of 499 * this structure are intentionally hidden from the public API. 500 */ 501 typedef struct nghttp2_rcbuf nghttp2_rcbuf; 502 503 /** 504 * @function 505 * 506 * Increments the reference count of |rcbuf| by 1. 507 */ 508 NGHTTP2_EXTERN void nghttp2_rcbuf_incref(nghttp2_rcbuf *rcbuf); 509 510 /** 511 * @function 512 * 513 * Decrements the reference count of |rcbuf| by 1. If the reference 514 * count becomes zero, the object pointed by |rcbuf| will be freed. 515 * In this case, application must not use |rcbuf| again. 516 */ 517 NGHTTP2_EXTERN void nghttp2_rcbuf_decref(nghttp2_rcbuf *rcbuf); 518 519 /** 520 * @function 521 * 522 * Returns the underlying buffer managed by |rcbuf|. 523 */ 524 NGHTTP2_EXTERN nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf); 525 526 /** 527 * @function 528 * 529 * Returns nonzero if the underlying buffer is statically allocated, 530 * and 0 otherwise. This can be useful for language bindings that wish 531 * to avoid creating duplicate strings for these buffers. 532 */ 533 NGHTTP2_EXTERN int nghttp2_rcbuf_is_static(const nghttp2_rcbuf *rcbuf); 534 535 /** 536 * @enum 537 * 538 * The flags for header field name/value pair. 539 */ 540 typedef enum { 541 /** 542 * No flag set. 543 */ 544 NGHTTP2_NV_FLAG_NONE = 0, 545 /** 546 * Indicates that this name/value pair must not be indexed ("Literal 547 * Header Field never Indexed" representation must be used in HPACK 548 * encoding). Other implementation calls this bit as "sensitive". 549 */ 550 NGHTTP2_NV_FLAG_NO_INDEX = 0x01, 551 /** 552 * This flag is set solely by application. If this flag is set, the 553 * library does not make a copy of header field name. This could 554 * improve performance. 555 */ 556 NGHTTP2_NV_FLAG_NO_COPY_NAME = 0x02, 557 /** 558 * This flag is set solely by application. If this flag is set, the 559 * library does not make a copy of header field value. This could 560 * improve performance. 561 */ 562 NGHTTP2_NV_FLAG_NO_COPY_VALUE = 0x04 563 } nghttp2_nv_flag; 564 565 /** 566 * @struct 567 * 568 * The name/value pair, which mainly used to represent header fields. 569 */ 570 typedef struct { 571 /** 572 * The |name| byte string. If this struct is presented from library 573 * (e.g., :type:`nghttp2_on_frame_recv_callback`), |name| is 574 * guaranteed to be NULL-terminated. For some callbacks 575 * (:type:`nghttp2_before_frame_send_callback`, 576 * :type:`nghttp2_on_frame_send_callback`, and 577 * :type:`nghttp2_on_frame_not_send_callback`), it may not be 578 * NULL-terminated if header field is passed from application with 579 * the flag :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`). 580 * When application is constructing this struct, |name| is not 581 * required to be NULL-terminated. 582 */ 583 uint8_t *name; 584 /** 585 * The |value| byte string. If this struct is presented from 586 * library (e.g., :type:`nghttp2_on_frame_recv_callback`), |value| 587 * is guaranteed to be NULL-terminated. For some callbacks 588 * (:type:`nghttp2_before_frame_send_callback`, 589 * :type:`nghttp2_on_frame_send_callback`, and 590 * :type:`nghttp2_on_frame_not_send_callback`), it may not be 591 * NULL-terminated if header field is passed from application with 592 * the flag :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE`). 593 * When application is constructing this struct, |value| is not 594 * required to be NULL-terminated. 595 */ 596 uint8_t *value; 597 /** 598 * The length of the |name|, excluding terminating NULL. 599 */ 600 size_t namelen; 601 /** 602 * The length of the |value|, excluding terminating NULL. 603 */ 604 size_t valuelen; 605 /** 606 * Bitwise OR of one or more of :type:`nghttp2_nv_flag`. 607 */ 608 uint8_t flags; 609 } nghttp2_nv; 610 611 /** 612 * @enum 613 * 614 * The frame types in HTTP/2 specification. 615 */ 616 typedef enum { 617 /** 618 * The DATA frame. 619 */ 620 NGHTTP2_DATA = 0, 621 /** 622 * The HEADERS frame. 623 */ 624 NGHTTP2_HEADERS = 0x01, 625 /** 626 * The PRIORITY frame. 627 */ 628 NGHTTP2_PRIORITY = 0x02, 629 /** 630 * The RST_STREAM frame. 631 */ 632 NGHTTP2_RST_STREAM = 0x03, 633 /** 634 * The SETTINGS frame. 635 */ 636 NGHTTP2_SETTINGS = 0x04, 637 /** 638 * The PUSH_PROMISE frame. 639 */ 640 NGHTTP2_PUSH_PROMISE = 0x05, 641 /** 642 * The PING frame. 643 */ 644 NGHTTP2_PING = 0x06, 645 /** 646 * The GOAWAY frame. 647 */ 648 NGHTTP2_GOAWAY = 0x07, 649 /** 650 * The WINDOW_UPDATE frame. 651 */ 652 NGHTTP2_WINDOW_UPDATE = 0x08, 653 /** 654 * The CONTINUATION frame. This frame type won't be passed to any 655 * callbacks because the library processes this frame type and its 656 * preceding HEADERS/PUSH_PROMISE as a single frame. 657 */ 658 NGHTTP2_CONTINUATION = 0x09, 659 /** 660 * The ALTSVC frame, which is defined in `RFC 7383 661 * <https://tools.ietf.org/html/rfc7838#section-4>`_. 662 */ 663 NGHTTP2_ALTSVC = 0x0a, 664 /** 665 * The ORIGIN frame, which is defined by `RFC 8336 666 * <https://tools.ietf.org/html/rfc8336>`_. 667 */ 668 NGHTTP2_ORIGIN = 0x0c, 669 /** 670 * The PRIORITY_UPDATE frame, which is defined by :rfc:`9218`. 671 */ 672 NGHTTP2_PRIORITY_UPDATE = 0x10 673 } nghttp2_frame_type; 674 675 /** 676 * @enum 677 * 678 * The flags for HTTP/2 frames. This enum defines all flags for all 679 * frames. 680 */ 681 typedef enum { 682 /** 683 * No flag set. 684 */ 685 NGHTTP2_FLAG_NONE = 0, 686 /** 687 * The END_STREAM flag. 688 */ 689 NGHTTP2_FLAG_END_STREAM = 0x01, 690 /** 691 * The END_HEADERS flag. 692 */ 693 NGHTTP2_FLAG_END_HEADERS = 0x04, 694 /** 695 * The ACK flag. 696 */ 697 NGHTTP2_FLAG_ACK = 0x01, 698 /** 699 * The PADDED flag. 700 */ 701 NGHTTP2_FLAG_PADDED = 0x08, 702 /** 703 * The PRIORITY flag. 704 */ 705 NGHTTP2_FLAG_PRIORITY = 0x20 706 } nghttp2_flag; 707 708 /** 709 * @enum 710 * The SETTINGS ID. 711 */ 712 typedef enum { 713 /** 714 * SETTINGS_HEADER_TABLE_SIZE 715 */ 716 NGHTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x01, 717 /** 718 * SETTINGS_ENABLE_PUSH 719 */ 720 NGHTTP2_SETTINGS_ENABLE_PUSH = 0x02, 721 /** 722 * SETTINGS_MAX_CONCURRENT_STREAMS 723 */ 724 NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x03, 725 /** 726 * SETTINGS_INITIAL_WINDOW_SIZE 727 */ 728 NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x04, 729 /** 730 * SETTINGS_MAX_FRAME_SIZE 731 */ 732 NGHTTP2_SETTINGS_MAX_FRAME_SIZE = 0x05, 733 /** 734 * SETTINGS_MAX_HEADER_LIST_SIZE 735 */ 736 NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x06, 737 /** 738 * SETTINGS_ENABLE_CONNECT_PROTOCOL 739 * (`RFC 8441 <https://tools.ietf.org/html/rfc8441>`_) 740 */ 741 NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL = 0x08, 742 /** 743 * SETTINGS_NO_RFC7540_PRIORITIES (:rfc:`9218`) 744 */ 745 NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES = 0x09 746 } nghttp2_settings_id; 747 /* Note: If we add SETTINGS, update the capacity of 748 NGHTTP2_INBOUND_NUM_IV as well */ 749 750 /** 751 * @macro 752 * 753 * .. warning:: 754 * 755 * Deprecated. The initial max concurrent streams is 0xffffffffu. 756 * 757 * Default maximum number of incoming concurrent streams. Use 758 * `nghttp2_submit_settings()` with 759 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS` 760 * to change the maximum number of incoming concurrent streams. 761 * 762 * .. note:: 763 * 764 * The maximum number of outgoing concurrent streams is 100 by 765 * default. 766 */ 767 #define NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1) 768 769 /** 770 * @enum 771 * The status codes for the RST_STREAM and GOAWAY frames. 772 */ 773 typedef enum { 774 /** 775 * No errors. 776 */ 777 NGHTTP2_NO_ERROR = 0x00, 778 /** 779 * PROTOCOL_ERROR 780 */ 781 NGHTTP2_PROTOCOL_ERROR = 0x01, 782 /** 783 * INTERNAL_ERROR 784 */ 785 NGHTTP2_INTERNAL_ERROR = 0x02, 786 /** 787 * FLOW_CONTROL_ERROR 788 */ 789 NGHTTP2_FLOW_CONTROL_ERROR = 0x03, 790 /** 791 * SETTINGS_TIMEOUT 792 */ 793 NGHTTP2_SETTINGS_TIMEOUT = 0x04, 794 /** 795 * STREAM_CLOSED 796 */ 797 NGHTTP2_STREAM_CLOSED = 0x05, 798 /** 799 * FRAME_SIZE_ERROR 800 */ 801 NGHTTP2_FRAME_SIZE_ERROR = 0x06, 802 /** 803 * REFUSED_STREAM 804 */ 805 NGHTTP2_REFUSED_STREAM = 0x07, 806 /** 807 * CANCEL 808 */ 809 NGHTTP2_CANCEL = 0x08, 810 /** 811 * COMPRESSION_ERROR 812 */ 813 NGHTTP2_COMPRESSION_ERROR = 0x09, 814 /** 815 * CONNECT_ERROR 816 */ 817 NGHTTP2_CONNECT_ERROR = 0x0a, 818 /** 819 * ENHANCE_YOUR_CALM 820 */ 821 NGHTTP2_ENHANCE_YOUR_CALM = 0x0b, 822 /** 823 * INADEQUATE_SECURITY 824 */ 825 NGHTTP2_INADEQUATE_SECURITY = 0x0c, 826 /** 827 * HTTP_1_1_REQUIRED 828 */ 829 NGHTTP2_HTTP_1_1_REQUIRED = 0x0d 830 } nghttp2_error_code; 831 832 /** 833 * @struct 834 * The frame header. 835 */ 836 typedef struct { 837 /** 838 * The length field of this frame, excluding frame header. 839 */ 840 size_t length; 841 /** 842 * The stream identifier (aka, stream ID) 843 */ 844 int32_t stream_id; 845 /** 846 * The type of this frame. See `nghttp2_frame_type`. 847 */ 848 uint8_t type; 849 /** 850 * The flags. 851 */ 852 uint8_t flags; 853 /** 854 * Reserved bit in frame header. Currently, this is always set to 0 855 * and application should not expect something useful in here. 856 */ 857 uint8_t reserved; 858 } nghttp2_frame_hd; 859 860 /** 861 * @union 862 * 863 * This union represents the some kind of data source passed to 864 * :type:`nghttp2_data_source_read_callback2`. 865 */ 866 typedef union { 867 /** 868 * The integer field, suitable for a file descriptor. 869 */ 870 int fd; 871 /** 872 * The pointer to an arbitrary object. 873 */ 874 void *ptr; 875 } nghttp2_data_source; 876 877 /** 878 * @enum 879 * 880 * The flags used to set in |data_flags| output parameter in 881 * :type:`nghttp2_data_source_read_callback2`. 882 */ 883 typedef enum { 884 /** 885 * No flag set. 886 */ 887 NGHTTP2_DATA_FLAG_NONE = 0, 888 /** 889 * Indicates EOF was sensed. 890 */ 891 NGHTTP2_DATA_FLAG_EOF = 0x01, 892 /** 893 * Indicates that END_STREAM flag must not be set even if 894 * NGHTTP2_DATA_FLAG_EOF is set. Usually this flag is used to send 895 * trailer fields with `nghttp2_submit_request2()` or 896 * `nghttp2_submit_response2()`. 897 */ 898 NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02, 899 /** 900 * Indicates that application will send complete DATA frame in 901 * :type:`nghttp2_send_data_callback`. 902 */ 903 NGHTTP2_DATA_FLAG_NO_COPY = 0x04 904 } nghttp2_data_flag; 905 906 #ifndef NGHTTP2_NO_SSIZE_T 907 /** 908 * @functypedef 909 * 910 * .. warning:: 911 * 912 * Deprecated. Use :type:`nghttp2_data_source_read_callback2` 913 * instead. 914 * 915 * Callback function invoked when the library wants to read data from 916 * the |source|. The read data is sent in the stream |stream_id|. 917 * The implementation of this function must read at most |length| 918 * bytes of data from |source| (or possibly other places) and store 919 * them in |buf| and return number of data stored in |buf|. If EOF is 920 * reached, set :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag 921 * in |*data_flags|. 922 * 923 * Sometime it is desirable to avoid copying data into |buf| and let 924 * application to send data directly. To achieve this, set 925 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` to 926 * |*data_flags| (and possibly other flags, just like when we do 927 * copy), and return the number of bytes to send without copying data 928 * into |buf|. The library, seeing 929 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY`, will invoke 930 * :type:`nghttp2_send_data_callback`. The application must send 931 * complete DATA frame in that callback. 932 * 933 * If this callback is set by `nghttp2_submit_request()`, 934 * `nghttp2_submit_response()` or `nghttp2_submit_headers()` and 935 * `nghttp2_submit_data()` with flag parameter 936 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` set, and 937 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag is set to 938 * |*data_flags|, DATA frame will have END_STREAM flag set. Usually, 939 * this is expected behaviour and all are fine. One exception is send 940 * trailer fields. You cannot send trailer fields after sending frame 941 * with END_STREAM set. To avoid this problem, one can set 942 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM` along 943 * with :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` to signal the 944 * library not to set END_STREAM in DATA frame. Then application can 945 * use `nghttp2_submit_trailer()` to send trailer fields. 946 * `nghttp2_submit_trailer()` can be called inside this callback. 947 * 948 * If the application wants to postpone DATA frames (e.g., 949 * asynchronous I/O, or reading data blocks for long time), it is 950 * achieved by returning :enum:`nghttp2_error.NGHTTP2_ERR_DEFERRED` 951 * without reading any data in this invocation. The library removes 952 * DATA frame from the outgoing queue temporarily. To move back 953 * deferred DATA frame to outgoing queue, call 954 * `nghttp2_session_resume_data()`. 955 * 956 * By default, |length| is limited to 16KiB at maximum. If peer 957 * allows larger frames, application can enlarge transmission buffer 958 * size. See :type:`nghttp2_data_source_read_length_callback` for 959 * more details. 960 * 961 * If the application just wants to return from 962 * `nghttp2_session_send()` or `nghttp2_session_mem_send()` without 963 * sending anything, return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. 964 * 965 * In case of error, there are 2 choices. Returning 966 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will 967 * close the stream by issuing RST_STREAM with 968 * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. If a different 969 * error code is desirable, use `nghttp2_submit_rst_stream()` with a 970 * desired error code and then return 971 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 972 * Returning :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will 973 * signal the entire session failure. 974 */ 975 typedef ssize_t (*nghttp2_data_source_read_callback)( 976 nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, 977 uint32_t *data_flags, nghttp2_data_source *source, void *user_data); 978 979 #endif /* NGHTTP2_NO_SSIZE_T */ 980 981 /** 982 * @functypedef 983 * 984 * Callback function invoked when the library wants to read data from 985 * the |source|. The read data is sent in the stream |stream_id|. 986 * The implementation of this function must read at most |length| 987 * bytes of data from |source| (or possibly other places) and store 988 * them in |buf| and return number of data stored in |buf|. If EOF is 989 * reached, set :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag 990 * in |*data_flags|. 991 * 992 * Sometime it is desirable to avoid copying data into |buf| and let 993 * application to send data directly. To achieve this, set 994 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` to 995 * |*data_flags| (and possibly other flags, just like when we do 996 * copy), and return the number of bytes to send without copying data 997 * into |buf|. The library, seeing 998 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY`, will invoke 999 * :type:`nghttp2_send_data_callback`. The application must send 1000 * complete DATA frame in that callback. 1001 * 1002 * If this callback is set by `nghttp2_submit_request2()`, 1003 * `nghttp2_submit_response2()` or `nghttp2_submit_headers()` and 1004 * `nghttp2_submit_data2()` with flag parameter 1005 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` set, and 1006 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag is set to 1007 * |*data_flags|, DATA frame will have END_STREAM flag set. Usually, 1008 * this is expected behaviour and all are fine. One exception is send 1009 * trailer fields. You cannot send trailer fields after sending frame 1010 * with END_STREAM set. To avoid this problem, one can set 1011 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM` along 1012 * with :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` to signal the 1013 * library not to set END_STREAM in DATA frame. Then application can 1014 * use `nghttp2_submit_trailer()` to send trailer fields. 1015 * `nghttp2_submit_trailer()` can be called inside this callback. 1016 * 1017 * If the application wants to postpone DATA frames (e.g., 1018 * asynchronous I/O, or reading data blocks for long time), it is 1019 * achieved by returning :enum:`nghttp2_error.NGHTTP2_ERR_DEFERRED` 1020 * without reading any data in this invocation. The library removes 1021 * DATA frame from the outgoing queue temporarily. To move back 1022 * deferred DATA frame to outgoing queue, call 1023 * `nghttp2_session_resume_data()`. 1024 * 1025 * By default, |length| is limited to 16KiB at maximum. If peer 1026 * allows larger frames, application can enlarge transmission buffer 1027 * size. See :type:`nghttp2_data_source_read_length_callback` for 1028 * more details. 1029 * 1030 * If the application just wants to return from 1031 * `nghttp2_session_send()` or `nghttp2_session_mem_send2()` without 1032 * sending anything, return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. 1033 * 1034 * In case of error, there are 2 choices. Returning 1035 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will 1036 * close the stream by issuing RST_STREAM with 1037 * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. If a different 1038 * error code is desirable, use `nghttp2_submit_rst_stream()` with a 1039 * desired error code and then return 1040 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 1041 * Returning :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will 1042 * signal the entire session failure. 1043 */ 1044 typedef nghttp2_ssize (*nghttp2_data_source_read_callback2)( 1045 nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, 1046 uint32_t *data_flags, nghttp2_data_source *source, void *user_data); 1047 1048 #ifndef NGHTTP2_NO_SSIZE_T 1049 /** 1050 * @struct 1051 * 1052 * .. warning:: 1053 * 1054 * Deprecated. Use :type:`nghttp2_data_provider2` instead. 1055 * 1056 * This struct represents the data source and the way to read a chunk 1057 * of data from it. 1058 */ 1059 typedef struct { 1060 /** 1061 * The data source. 1062 */ 1063 nghttp2_data_source source; 1064 /** 1065 * The callback function to read a chunk of data from the |source|. 1066 */ 1067 nghttp2_data_source_read_callback read_callback; 1068 } nghttp2_data_provider; 1069 1070 #endif /* NGHTTP2_NO_SSIZE_T */ 1071 1072 /** 1073 * @struct 1074 * 1075 * This struct represents the data source and the way to read a chunk 1076 * of data from it. 1077 */ 1078 typedef struct { 1079 /** 1080 * The data source. 1081 */ 1082 nghttp2_data_source source; 1083 /** 1084 * The callback function to read a chunk of data from the |source|. 1085 */ 1086 nghttp2_data_source_read_callback2 read_callback; 1087 } nghttp2_data_provider2; 1088 1089 /** 1090 * @struct 1091 * 1092 * The DATA frame. The received data is delivered via 1093 * :type:`nghttp2_on_data_chunk_recv_callback`. 1094 */ 1095 typedef struct { 1096 nghttp2_frame_hd hd; 1097 /** 1098 * The length of the padding in this frame. This includes PAD_HIGH 1099 * and PAD_LOW. 1100 */ 1101 size_t padlen; 1102 } nghttp2_data; 1103 1104 /** 1105 * @enum 1106 * 1107 * The category of HEADERS, which indicates the role of the frame. In 1108 * HTTP/2 spec, request, response, push response and other arbitrary 1109 * headers (e.g., trailer fields) are all called just HEADERS. To 1110 * give the application the role of incoming HEADERS frame, we define 1111 * several categories. 1112 */ 1113 typedef enum { 1114 /** 1115 * The HEADERS frame is opening new stream, which is analogous to 1116 * SYN_STREAM in SPDY. 1117 */ 1118 NGHTTP2_HCAT_REQUEST = 0, 1119 /** 1120 * The HEADERS frame is the first response headers, which is 1121 * analogous to SYN_REPLY in SPDY. 1122 */ 1123 NGHTTP2_HCAT_RESPONSE = 1, 1124 /** 1125 * The HEADERS frame is the first headers sent against reserved 1126 * stream. 1127 */ 1128 NGHTTP2_HCAT_PUSH_RESPONSE = 2, 1129 /** 1130 * The HEADERS frame which does not apply for the above categories, 1131 * which is analogous to HEADERS in SPDY. If non-final response 1132 * (e.g., status 1xx) is used, final response HEADERS frame will be 1133 * categorized here. 1134 */ 1135 NGHTTP2_HCAT_HEADERS = 3 1136 } nghttp2_headers_category; 1137 1138 /** 1139 * @struct 1140 * 1141 * .. warning:: 1142 * 1143 * Deprecated. :rfc:`7540` priorities are deprecated by 1144 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 1145 * prioritization scheme. 1146 * 1147 * The structure to specify stream dependency. 1148 */ 1149 typedef struct { 1150 /** 1151 * The stream ID of the stream to depend on. Specifying 0 makes 1152 * stream not depend any other stream. 1153 */ 1154 int32_t stream_id; 1155 /** 1156 * The weight of this dependency. 1157 */ 1158 int32_t weight; 1159 /** 1160 * nonzero means exclusive dependency 1161 */ 1162 uint8_t exclusive; 1163 } nghttp2_priority_spec; 1164 1165 /** 1166 * @struct 1167 * 1168 * The HEADERS frame. It has the following members: 1169 */ 1170 typedef struct { 1171 /** 1172 * The frame header. 1173 */ 1174 nghttp2_frame_hd hd; 1175 /** 1176 * The length of the padding in this frame. This includes PAD_HIGH 1177 * and PAD_LOW. 1178 */ 1179 size_t padlen; 1180 /** 1181 * .. warning:: 1182 * 1183 * Deprecated. :rfc:`7540` priorities are deprecated by 1184 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 1185 * prioritization scheme. 1186 * 1187 * The priority specification 1188 */ 1189 nghttp2_priority_spec pri_spec; 1190 /** 1191 * The name/value pairs. 1192 */ 1193 nghttp2_nv *nva; 1194 /** 1195 * The number of name/value pairs in |nva|. 1196 */ 1197 size_t nvlen; 1198 /** 1199 * The category of this HEADERS frame. 1200 */ 1201 nghttp2_headers_category cat; 1202 } nghttp2_headers; 1203 1204 /** 1205 * @struct 1206 * 1207 * .. warning:: 1208 * 1209 * Deprecated. :rfc:`7540` priorities are deprecated by 1210 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 1211 * prioritization scheme. 1212 * 1213 * The PRIORITY frame. It has the following members: 1214 */ 1215 typedef struct { 1216 /** 1217 * The frame header. 1218 */ 1219 nghttp2_frame_hd hd; 1220 /** 1221 * The priority specification. 1222 */ 1223 nghttp2_priority_spec pri_spec; 1224 } nghttp2_priority; 1225 1226 /** 1227 * @struct 1228 * 1229 * The RST_STREAM frame. It has the following members: 1230 */ 1231 typedef struct { 1232 /** 1233 * The frame header. 1234 */ 1235 nghttp2_frame_hd hd; 1236 /** 1237 * The error code. See :type:`nghttp2_error_code`. 1238 */ 1239 uint32_t error_code; 1240 } nghttp2_rst_stream; 1241 1242 /** 1243 * @struct 1244 * 1245 * The SETTINGS ID/Value pair. It has the following members: 1246 */ 1247 typedef struct { 1248 /** 1249 * The SETTINGS ID. See :type:`nghttp2_settings_id`. 1250 */ 1251 int32_t settings_id; 1252 /** 1253 * The value of this entry. 1254 */ 1255 uint32_t value; 1256 } nghttp2_settings_entry; 1257 1258 /** 1259 * @struct 1260 * 1261 * The SETTINGS frame. It has the following members: 1262 */ 1263 typedef struct { 1264 /** 1265 * The frame header. 1266 */ 1267 nghttp2_frame_hd hd; 1268 /** 1269 * The number of SETTINGS ID/Value pairs in |iv|. 1270 */ 1271 size_t niv; 1272 /** 1273 * The pointer to the array of SETTINGS ID/Value pair. 1274 */ 1275 nghttp2_settings_entry *iv; 1276 } nghttp2_settings; 1277 1278 /** 1279 * @struct 1280 * 1281 * The PUSH_PROMISE frame. It has the following members: 1282 */ 1283 typedef struct { 1284 /** 1285 * The frame header. 1286 */ 1287 nghttp2_frame_hd hd; 1288 /** 1289 * The length of the padding in this frame. This includes PAD_HIGH 1290 * and PAD_LOW. 1291 */ 1292 size_t padlen; 1293 /** 1294 * The name/value pairs. 1295 */ 1296 nghttp2_nv *nva; 1297 /** 1298 * The number of name/value pairs in |nva|. 1299 */ 1300 size_t nvlen; 1301 /** 1302 * The promised stream ID 1303 */ 1304 int32_t promised_stream_id; 1305 /** 1306 * Reserved bit. Currently this is always set to 0 and application 1307 * should not expect something useful in here. 1308 */ 1309 uint8_t reserved; 1310 } nghttp2_push_promise; 1311 1312 /** 1313 * @struct 1314 * 1315 * The PING frame. It has the following members: 1316 */ 1317 typedef struct { 1318 /** 1319 * The frame header. 1320 */ 1321 nghttp2_frame_hd hd; 1322 /** 1323 * The opaque data 1324 */ 1325 uint8_t opaque_data[8]; 1326 } nghttp2_ping; 1327 1328 /** 1329 * @struct 1330 * 1331 * The GOAWAY frame. It has the following members: 1332 */ 1333 typedef struct { 1334 /** 1335 * The frame header. 1336 */ 1337 nghttp2_frame_hd hd; 1338 /** 1339 * The last stream stream ID. 1340 */ 1341 int32_t last_stream_id; 1342 /** 1343 * The error code. See :type:`nghttp2_error_code`. 1344 */ 1345 uint32_t error_code; 1346 /** 1347 * The additional debug data 1348 */ 1349 uint8_t *opaque_data; 1350 /** 1351 * The length of |opaque_data| member. 1352 */ 1353 size_t opaque_data_len; 1354 /** 1355 * Reserved bit. Currently this is always set to 0 and application 1356 * should not expect something useful in here. 1357 */ 1358 uint8_t reserved; 1359 } nghttp2_goaway; 1360 1361 /** 1362 * @struct 1363 * 1364 * The WINDOW_UPDATE frame. It has the following members: 1365 */ 1366 typedef struct { 1367 /** 1368 * The frame header. 1369 */ 1370 nghttp2_frame_hd hd; 1371 /** 1372 * The window size increment. 1373 */ 1374 int32_t window_size_increment; 1375 /** 1376 * Reserved bit. Currently this is always set to 0 and application 1377 * should not expect something useful in here. 1378 */ 1379 uint8_t reserved; 1380 } nghttp2_window_update; 1381 1382 /** 1383 * @struct 1384 * 1385 * The extension frame. It has following members: 1386 */ 1387 typedef struct { 1388 /** 1389 * The frame header. 1390 */ 1391 nghttp2_frame_hd hd; 1392 /** 1393 * The pointer to extension payload. The exact pointer type is 1394 * determined by hd.type. 1395 * 1396 * Currently, no extension is supported. This is a place holder for 1397 * the future extensions. 1398 */ 1399 void *payload; 1400 } nghttp2_extension; 1401 1402 /** 1403 * @union 1404 * 1405 * This union includes all frames to pass them to various function 1406 * calls as nghttp2_frame type. The CONTINUATION frame is omitted 1407 * from here because the library deals with it internally. 1408 */ 1409 typedef union { 1410 /** 1411 * The frame header, which is convenient to inspect frame header. 1412 */ 1413 nghttp2_frame_hd hd; 1414 /** 1415 * The DATA frame. 1416 */ 1417 nghttp2_data data; 1418 /** 1419 * The HEADERS frame. 1420 */ 1421 nghttp2_headers headers; 1422 /** 1423 * The PRIORITY frame. 1424 */ 1425 nghttp2_priority priority; 1426 /** 1427 * The RST_STREAM frame. 1428 */ 1429 nghttp2_rst_stream rst_stream; 1430 /** 1431 * The SETTINGS frame. 1432 */ 1433 nghttp2_settings settings; 1434 /** 1435 * The PUSH_PROMISE frame. 1436 */ 1437 nghttp2_push_promise push_promise; 1438 /** 1439 * The PING frame. 1440 */ 1441 nghttp2_ping ping; 1442 /** 1443 * The GOAWAY frame. 1444 */ 1445 nghttp2_goaway goaway; 1446 /** 1447 * The WINDOW_UPDATE frame. 1448 */ 1449 nghttp2_window_update window_update; 1450 /** 1451 * The extension frame. 1452 */ 1453 nghttp2_extension ext; 1454 } nghttp2_frame; 1455 1456 #ifndef NGHTTP2_NO_SSIZE_T 1457 /** 1458 * @functypedef 1459 * 1460 * .. warning:: 1461 * 1462 * Deprecated. Use :type:`nghttp2_send_callback2` instead. 1463 * 1464 * Callback function invoked when |session| wants to send data to the 1465 * remote peer. The implementation of this function must send at most 1466 * |length| bytes of data stored in |data|. The |flags| is currently 1467 * not used and always 0. It must return the number of bytes sent if 1468 * it succeeds. If it cannot send any single byte without blocking, 1469 * it must return :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. For 1470 * other errors, it must return 1471 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The 1472 * |user_data| pointer is the third argument passed in to the call to 1473 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1474 * 1475 * This callback is required if the application uses 1476 * `nghttp2_session_send()` to send data to the remote endpoint. If 1477 * the application uses solely `nghttp2_session_mem_send()` instead, 1478 * this callback function is unnecessary. 1479 * 1480 * To set this callback to :type:`nghttp2_session_callbacks`, use 1481 * `nghttp2_session_callbacks_set_send_callback()`. 1482 * 1483 * .. note:: 1484 * 1485 * The |length| may be very small. If that is the case, and 1486 * application disables Nagle algorithm (``TCP_NODELAY``), then just 1487 * writing |data| to the network stack leads to very small packet, 1488 * and it is very inefficient. An application should be responsible 1489 * to buffer up small chunks of data as necessary to avoid this 1490 * situation. 1491 */ 1492 typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session, 1493 const uint8_t *data, size_t length, 1494 int flags, void *user_data); 1495 1496 #endif /* NGHTTP2_NO_SSIZE_T */ 1497 1498 /** 1499 * @functypedef 1500 * 1501 * Callback function invoked when |session| wants to send data to the 1502 * remote peer. The implementation of this function must send at most 1503 * |length| bytes of data stored in |data|. The |flags| is currently 1504 * not used and always 0. It must return the number of bytes sent if 1505 * it succeeds. If it cannot send any single byte without blocking, 1506 * it must return :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. For 1507 * other errors, it must return 1508 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The 1509 * |user_data| pointer is the third argument passed in to the call to 1510 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1511 * 1512 * This callback is required if the application uses 1513 * `nghttp2_session_send()` to send data to the remote endpoint. If 1514 * the application uses solely `nghttp2_session_mem_send2()` instead, 1515 * this callback function is unnecessary. 1516 * 1517 * To set this callback to :type:`nghttp2_session_callbacks`, use 1518 * `nghttp2_session_callbacks_set_send_callback2()`. 1519 * 1520 * .. note:: 1521 * 1522 * The |length| may be very small. If that is the case, and 1523 * application disables Nagle algorithm (``TCP_NODELAY``), then just 1524 * writing |data| to the network stack leads to very small packet, 1525 * and it is very inefficient. An application should be responsible 1526 * to buffer up small chunks of data as necessary to avoid this 1527 * situation. 1528 */ 1529 typedef nghttp2_ssize (*nghttp2_send_callback2)(nghttp2_session *session, 1530 const uint8_t *data, 1531 size_t length, int flags, 1532 void *user_data); 1533 1534 /** 1535 * @functypedef 1536 * 1537 * Callback function invoked when 1538 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` is used in 1539 * :type:`nghttp2_data_source_read_callback` to send complete DATA 1540 * frame. 1541 * 1542 * The |frame| is a DATA frame to send. The |framehd| is the 1543 * serialized frame header (9 bytes). The |length| is the length of 1544 * application data to send (this does not include padding). The 1545 * |source| is the same pointer passed to 1546 * :type:`nghttp2_data_source_read_callback`. 1547 * 1548 * The application first must send frame header |framehd| of length 9 1549 * bytes. If ``frame->data.padlen > 0``, send 1 byte of value 1550 * ``frame->data.padlen - 1``. Then send exactly |length| bytes of 1551 * application data. Finally, if ``frame->data.padlen > 1``, send 1552 * ``frame->data.padlen - 1`` bytes of zero as padding. 1553 * 1554 * The application has to send complete DATA frame in this callback. 1555 * If all data were written successfully, return 0. 1556 * 1557 * If it cannot send any data at all, just return 1558 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`; the library will call 1559 * this callback with the same parameters later (It is recommended to 1560 * send complete DATA frame at once in this function to deal with 1561 * error; if partial frame data has already sent, it is impossible to 1562 * send another data in that state, and all we can do is tear down 1563 * connection). When data is fully processed, but application wants 1564 * to make `nghttp2_session_mem_send2()` or `nghttp2_session_send()` 1565 * return immediately without processing next frames, return 1566 * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. If application decided to 1567 * reset this stream, return 1568 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`, then 1569 * the library will send RST_STREAM with INTERNAL_ERROR as error code. 1570 * The application can also return 1571 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, which will 1572 * result in connection closure. Returning any other value is treated 1573 * as :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned. 1574 */ 1575 typedef int (*nghttp2_send_data_callback)(nghttp2_session *session, 1576 nghttp2_frame *frame, 1577 const uint8_t *framehd, size_t length, 1578 nghttp2_data_source *source, 1579 void *user_data); 1580 1581 #ifndef NGHTTP2_NO_SSIZE_T 1582 /** 1583 * @functypedef 1584 * 1585 * .. warning:: 1586 * 1587 * Deprecated. Use :type:`nghttp2_recv_callback2` instead. 1588 * 1589 * Callback function invoked when |session| wants to receive data from 1590 * the remote peer. The implementation of this function must read at 1591 * most |length| bytes of data and store it in |buf|. The |flags| is 1592 * currently not used and always 0. It must return the number of 1593 * bytes written in |buf| if it succeeds. If it cannot read any 1594 * single byte without blocking, it must return 1595 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF 1596 * before it reads any single byte, it must return 1597 * :enum:`nghttp2_error.NGHTTP2_ERR_EOF`. For other errors, it must 1598 * return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1599 * Returning 0 is treated as 1600 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. The |user_data| 1601 * pointer is the third argument passed in to the call to 1602 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1603 * 1604 * This callback is required if the application uses 1605 * `nghttp2_session_recv()` to receive data from the remote endpoint. 1606 * If the application uses solely `nghttp2_session_mem_recv()` 1607 * instead, this callback function is unnecessary. 1608 * 1609 * To set this callback to :type:`nghttp2_session_callbacks`, use 1610 * `nghttp2_session_callbacks_set_recv_callback()`. 1611 */ 1612 typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf, 1613 size_t length, int flags, 1614 void *user_data); 1615 1616 #endif /* NGHTTP2_NO_SSIZE_T */ 1617 1618 /** 1619 * @functypedef 1620 * 1621 * Callback function invoked when |session| wants to receive data from 1622 * the remote peer. The implementation of this function must read at 1623 * most |length| bytes of data and store it in |buf|. The |flags| is 1624 * currently not used and always 0. It must return the number of 1625 * bytes written in |buf| if it succeeds. If it cannot read any 1626 * single byte without blocking, it must return 1627 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF 1628 * before it reads any single byte, it must return 1629 * :enum:`nghttp2_error.NGHTTP2_ERR_EOF`. For other errors, it must 1630 * return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1631 * Returning 0 is treated as 1632 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. The |user_data| 1633 * pointer is the third argument passed in to the call to 1634 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1635 * 1636 * This callback is required if the application uses 1637 * `nghttp2_session_recv()` to receive data from the remote endpoint. 1638 * If the application uses solely `nghttp2_session_mem_recv2()` 1639 * instead, this callback function is unnecessary. 1640 * 1641 * To set this callback to :type:`nghttp2_session_callbacks`, use 1642 * `nghttp2_session_callbacks_set_recv_callback2()`. 1643 */ 1644 typedef nghttp2_ssize (*nghttp2_recv_callback2)(nghttp2_session *session, 1645 uint8_t *buf, size_t length, 1646 int flags, void *user_data); 1647 1648 /** 1649 * @functypedef 1650 * 1651 * Callback function invoked by `nghttp2_session_recv()` and 1652 * `nghttp2_session_mem_recv2()` when a frame is received. The 1653 * |user_data| pointer is the third argument passed in to the call to 1654 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1655 * 1656 * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen`` 1657 * member of their data structure are always ``NULL`` and 0 1658 * respectively. The header name/value pairs are emitted via 1659 * :type:`nghttp2_on_header_callback`. 1660 * 1661 * Only HEADERS and DATA frame can signal the end of incoming data. 1662 * If ``frame->hd.flags & NGHTTP2_FLAG_END_STREAM`` is nonzero, the 1663 * |frame| is the last frame from the remote peer in this stream. 1664 * 1665 * This callback won't be called for CONTINUATION frames. 1666 * HEADERS/PUSH_PROMISE + CONTINUATIONs are treated as single frame. 1667 * 1668 * The implementation of this function must return 0 if it succeeds. 1669 * If nonzero value is returned, it is treated as fatal error and 1670 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 1671 * functions immediately return 1672 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1673 * 1674 * To set this callback to :type:`nghttp2_session_callbacks`, use 1675 * `nghttp2_session_callbacks_set_on_frame_recv_callback()`. 1676 */ 1677 typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session, 1678 const nghttp2_frame *frame, 1679 void *user_data); 1680 1681 /** 1682 * @functypedef 1683 * 1684 * Callback function invoked by `nghttp2_session_recv()` and 1685 * `nghttp2_session_mem_recv2()` when an invalid non-DATA frame is 1686 * received. The error is indicated by the |lib_error_code|, which is 1687 * one of the values defined in :type:`nghttp2_error`. When this 1688 * callback function is invoked, the library automatically submits 1689 * either RST_STREAM or GOAWAY frame. The |user_data| pointer is the 1690 * third argument passed in to the call to 1691 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1692 * 1693 * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen`` 1694 * member of their data structure are always ``NULL`` and 0 1695 * respectively. 1696 * 1697 * The implementation of this function must return 0 if it succeeds. 1698 * If nonzero is returned, it is treated as fatal error and 1699 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 1700 * functions immediately return 1701 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1702 * 1703 * To set this callback to :type:`nghttp2_session_callbacks`, use 1704 * `nghttp2_session_callbacks_set_on_invalid_frame_recv_callback()`. 1705 */ 1706 typedef int (*nghttp2_on_invalid_frame_recv_callback)( 1707 nghttp2_session *session, const nghttp2_frame *frame, int lib_error_code, 1708 void *user_data); 1709 1710 /** 1711 * @functypedef 1712 * 1713 * Callback function invoked when a chunk of data in DATA frame is 1714 * received. The |stream_id| is the stream ID this DATA frame belongs 1715 * to. The |flags| is the flags of DATA frame which this data chunk 1716 * is contained. ``(flags & NGHTTP2_FLAG_END_STREAM) != 0`` does not 1717 * necessarily mean this chunk of data is the last one in the stream. 1718 * You should use :type:`nghttp2_on_frame_recv_callback` to know all 1719 * data frames are received. The |user_data| pointer is the third 1720 * argument passed in to the call to `nghttp2_session_client_new()` or 1721 * `nghttp2_session_server_new()`. 1722 * 1723 * If the application uses `nghttp2_session_mem_recv2()`, it can 1724 * return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make 1725 * `nghttp2_session_mem_recv2()` return without processing further 1726 * input bytes. The memory by pointed by the |data| is retained until 1727 * `nghttp2_session_mem_recv2()` or `nghttp2_session_recv()` is 1728 * called. The application must retain the input bytes which was used 1729 * to produce the |data| parameter, because it may refer to the memory 1730 * region included in the input bytes. 1731 * 1732 * The implementation of this function must return 0 if it succeeds. 1733 * If nonzero is returned, it is treated as fatal error, and 1734 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 1735 * functions immediately return 1736 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1737 * 1738 * To set this callback to :type:`nghttp2_session_callbacks`, use 1739 * `nghttp2_session_callbacks_set_on_data_chunk_recv_callback()`. 1740 */ 1741 typedef int (*nghttp2_on_data_chunk_recv_callback)(nghttp2_session *session, 1742 uint8_t flags, 1743 int32_t stream_id, 1744 const uint8_t *data, 1745 size_t len, void *user_data); 1746 1747 /** 1748 * @functypedef 1749 * 1750 * Callback function invoked just before the non-DATA frame |frame| is 1751 * sent. The |user_data| pointer is the third argument passed in to 1752 * the call to `nghttp2_session_client_new()` or 1753 * `nghttp2_session_server_new()`. 1754 * 1755 * The implementation of this function must return 0 if it succeeds. 1756 * It can also return :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL` to 1757 * cancel the transmission of the given frame. 1758 * 1759 * If there is a fatal error while executing this callback, the 1760 * implementation should return 1761 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, which makes 1762 * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` 1763 * functions immediately return 1764 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1765 * 1766 * If the other value is returned, it is treated as if 1767 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned. 1768 * But the implementation should not rely on this since the library 1769 * may define new return value to extend its capability. 1770 * 1771 * To set this callback to :type:`nghttp2_session_callbacks`, use 1772 * `nghttp2_session_callbacks_set_before_frame_send_callback()`. 1773 */ 1774 typedef int (*nghttp2_before_frame_send_callback)(nghttp2_session *session, 1775 const nghttp2_frame *frame, 1776 void *user_data); 1777 1778 /** 1779 * @functypedef 1780 * 1781 * Callback function invoked after the frame |frame| is sent. The 1782 * |user_data| pointer is the third argument passed in to the call to 1783 * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. 1784 * 1785 * The implementation of this function must return 0 if it succeeds. 1786 * If nonzero is returned, it is treated as fatal error and 1787 * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` 1788 * functions immediately return 1789 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1790 * 1791 * To set this callback to :type:`nghttp2_session_callbacks`, use 1792 * `nghttp2_session_callbacks_set_on_frame_send_callback()`. 1793 */ 1794 typedef int (*nghttp2_on_frame_send_callback)(nghttp2_session *session, 1795 const nghttp2_frame *frame, 1796 void *user_data); 1797 1798 /** 1799 * @functypedef 1800 * 1801 * Callback function invoked after the non-DATA frame |frame| is not 1802 * sent because of the error. The error is indicated by the 1803 * |lib_error_code|, which is one of the values defined in 1804 * :type:`nghttp2_error`. The |user_data| pointer is the third 1805 * argument passed in to the call to `nghttp2_session_client_new()` or 1806 * `nghttp2_session_server_new()`. 1807 * 1808 * The implementation of this function must return 0 if it succeeds. 1809 * If nonzero is returned, it is treated as fatal error and 1810 * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` 1811 * functions immediately return 1812 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1813 * 1814 * `nghttp2_session_get_stream_user_data()` can be used to get 1815 * associated data. 1816 * 1817 * To set this callback to :type:`nghttp2_session_callbacks`, use 1818 * `nghttp2_session_callbacks_set_on_frame_not_send_callback()`. 1819 */ 1820 typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session, 1821 const nghttp2_frame *frame, 1822 int lib_error_code, 1823 void *user_data); 1824 1825 /** 1826 * @functypedef 1827 * 1828 * Callback function invoked when the stream |stream_id| is closed. 1829 * The reason of closure is indicated by the |error_code|. The 1830 * |error_code| is usually one of :enum:`nghttp2_error_code`, but that 1831 * is not guaranteed. The stream_user_data, which was specified in 1832 * `nghttp2_submit_request2()` or `nghttp2_submit_headers()`, is still 1833 * available in this function. The |user_data| pointer is the third 1834 * argument passed in to the call to `nghttp2_session_client_new()` or 1835 * `nghttp2_session_server_new()`. 1836 * 1837 * This function is also called for a stream in reserved state. 1838 * 1839 * The implementation of this function must return 0 if it succeeds. 1840 * If nonzero is returned, it is treated as fatal error and 1841 * `nghttp2_session_recv()`, `nghttp2_session_mem_recv2()`, 1842 * `nghttp2_session_send()`, and `nghttp2_session_mem_send2()` 1843 * functions immediately return 1844 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1845 * 1846 * To set this callback to :type:`nghttp2_session_callbacks`, use 1847 * `nghttp2_session_callbacks_set_on_stream_close_callback()`. 1848 */ 1849 typedef int (*nghttp2_on_stream_close_callback)(nghttp2_session *session, 1850 int32_t stream_id, 1851 uint32_t error_code, 1852 void *user_data); 1853 1854 /** 1855 * @functypedef 1856 * 1857 * Callback function invoked when the reception of header block in 1858 * HEADERS or PUSH_PROMISE is started. Each header name/value pair 1859 * will be emitted by :type:`nghttp2_on_header_callback`. 1860 * 1861 * The ``frame->hd.flags`` may not have 1862 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_HEADERS` flag set, which 1863 * indicates that one or more CONTINUATION frames are involved. But 1864 * the application does not need to care about that because the header 1865 * name/value pairs are emitted transparently regardless of 1866 * CONTINUATION frames. 1867 * 1868 * The server applications probably create an object to store 1869 * information about new stream if ``frame->hd.type == 1870 * NGHTTP2_HEADERS`` and ``frame->headers.cat == 1871 * NGHTTP2_HCAT_REQUEST``. If |session| is configured as server side, 1872 * ``frame->headers.cat`` is either ``NGHTTP2_HCAT_REQUEST`` 1873 * containing request headers or ``NGHTTP2_HCAT_HEADERS`` containing 1874 * trailer fields and never get PUSH_PROMISE in this callback. 1875 * 1876 * For the client applications, ``frame->hd.type`` is either 1877 * ``NGHTTP2_HEADERS`` or ``NGHTTP2_PUSH_PROMISE``. In case of 1878 * ``NGHTTP2_HEADERS``, ``frame->headers.cat == 1879 * NGHTTP2_HCAT_RESPONSE`` means that it is the first response 1880 * headers, but it may be non-final response which is indicated by 1xx 1881 * status code. In this case, there may be zero or more HEADERS frame 1882 * with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` which has 1883 * non-final response code and finally client gets exactly one HEADERS 1884 * frame with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` 1885 * containing final response headers (non-1xx status code). The 1886 * trailer fields also has ``frame->headers.cat == 1887 * NGHTTP2_HCAT_HEADERS`` which does not contain any status code. 1888 * 1889 * Returning 1890 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will 1891 * close the stream (promised stream if frame is PUSH_PROMISE) by 1892 * issuing RST_STREAM with 1893 * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. In this case, 1894 * :type:`nghttp2_on_header_callback` and 1895 * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a 1896 * different error code is desirable, use 1897 * `nghttp2_submit_rst_stream()` with a desired error code and then 1898 * return :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 1899 * Again, use ``frame->push_promise.promised_stream_id`` as stream_id 1900 * parameter in `nghttp2_submit_rst_stream()` if frame is 1901 * PUSH_PROMISE. 1902 * 1903 * The implementation of this function must return 0 if it succeeds. 1904 * It can return 1905 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` to 1906 * reset the stream (promised stream if frame is PUSH_PROMISE). For 1907 * critical errors, it must return 1908 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 1909 * value is returned, it is treated as if 1910 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned. If 1911 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned, 1912 * `nghttp2_session_mem_recv2()` function will immediately return 1913 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1914 * 1915 * To set this callback to :type:`nghttp2_session_callbacks`, use 1916 * `nghttp2_session_callbacks_set_on_begin_headers_callback()`. 1917 */ 1918 typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session, 1919 const nghttp2_frame *frame, 1920 void *user_data); 1921 1922 /** 1923 * @functypedef 1924 * 1925 * Callback function invoked when a header name/value pair is received 1926 * for the |frame|. The |name| of length |namelen| is header name. 1927 * The |value| of length |valuelen| is header value. The |flags| is 1928 * bitwise OR of one or more of :type:`nghttp2_nv_flag`. 1929 * 1930 * If :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_INDEX` is set in 1931 * |flags|, the receiver must not index this name/value pair when 1932 * forwarding it to the next hop. More specifically, "Literal Header 1933 * Field never Indexed" representation must be used in HPACK encoding. 1934 * 1935 * When this callback is invoked, ``frame->hd.type`` is either 1936 * :enum:`nghttp2_frame_type.NGHTTP2_HEADERS` or 1937 * :enum:`nghttp2_frame_type.NGHTTP2_PUSH_PROMISE`. After all header 1938 * name/value pairs are processed with this callback, and no error has 1939 * been detected, :type:`nghttp2_on_frame_recv_callback` will be 1940 * invoked. If there is an error in decompression, 1941 * :type:`nghttp2_on_frame_recv_callback` for the |frame| will not be 1942 * invoked. 1943 * 1944 * Both |name| and |value| are guaranteed to be NULL-terminated. The 1945 * |namelen| and |valuelen| do not include terminal NULL. If 1946 * `nghttp2_option_set_no_http_messaging()` is used with nonzero 1947 * value, NULL character may be included in |name| or |value| before 1948 * terminating NULL. 1949 * 1950 * Please note that unless `nghttp2_option_set_no_http_messaging()` is 1951 * used, nghttp2 library does perform validation against the |name| 1952 * and the |value| using `nghttp2_check_header_name()` and 1953 * `nghttp2_check_header_value()`. In addition to this, nghttp2 1954 * performs validation based on HTTP Messaging rule, which is briefly 1955 * explained in :ref:`http-messaging` section. 1956 * 1957 * If the application uses `nghttp2_session_mem_recv2()`, it can 1958 * return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make 1959 * `nghttp2_session_mem_recv2()` return without processing further 1960 * input bytes. The memory pointed by |frame|, |name| and |value| 1961 * parameters are retained until `nghttp2_session_mem_recv2()` or 1962 * `nghttp2_session_recv()` is called. The application must retain 1963 * the input bytes which was used to produce these parameters, because 1964 * it may refer to the memory region included in the input bytes. 1965 * 1966 * Returning 1967 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will 1968 * close the stream (promised stream if frame is PUSH_PROMISE) by 1969 * issuing RST_STREAM with 1970 * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. In this case, 1971 * :type:`nghttp2_on_header_callback` and 1972 * :type:`nghttp2_on_frame_recv_callback` will not be invoked. If a 1973 * different error code is desirable, use 1974 * `nghttp2_submit_rst_stream()` with a desired error code and then 1975 * return :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 1976 * Again, use ``frame->push_promise.promised_stream_id`` as stream_id 1977 * parameter in `nghttp2_submit_rst_stream()` if frame is 1978 * PUSH_PROMISE. 1979 * 1980 * The implementation of this function must return 0 if it succeeds. 1981 * It may return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` or 1982 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. For 1983 * other critical failures, it must return 1984 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 1985 * nonzero value is returned, it is treated as 1986 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If 1987 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned, 1988 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 1989 * functions immediately return 1990 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 1991 * 1992 * To set this callback to :type:`nghttp2_session_callbacks`, use 1993 * `nghttp2_session_callbacks_set_on_header_callback()`. 1994 * 1995 * .. warning:: 1996 * 1997 * Application should properly limit the total buffer size to store 1998 * incoming header fields. Without it, peer may send large number 1999 * of header fields or large header fields to cause out of memory in 2000 * local endpoint. Due to how HPACK works, peer can do this 2001 * effectively without using much memory on their own. 2002 */ 2003 typedef int (*nghttp2_on_header_callback)(nghttp2_session *session, 2004 const nghttp2_frame *frame, 2005 const uint8_t *name, size_t namelen, 2006 const uint8_t *value, size_t valuelen, 2007 uint8_t flags, void *user_data); 2008 2009 /** 2010 * @functypedef 2011 * 2012 * Callback function invoked when a header name/value pair is received 2013 * for the |frame|. The |name| is header name. The |value| is header 2014 * value. The |flags| is bitwise OR of one or more of 2015 * :type:`nghttp2_nv_flag`. 2016 * 2017 * This callback behaves like :type:`nghttp2_on_header_callback`, 2018 * except that |name| and |value| are stored in reference counted 2019 * buffer. If application wishes to keep these references without 2020 * copying them, use `nghttp2_rcbuf_incref()` to increment their 2021 * reference count. It is the application's responsibility to call 2022 * `nghttp2_rcbuf_decref()` if they called `nghttp2_rcbuf_incref()` so 2023 * as not to leak memory. If the |session| is created by 2024 * `nghttp2_session_server_new3()` or `nghttp2_session_client_new3()`, 2025 * the function to free memory is the one belongs to the mem 2026 * parameter. As long as this free function alives, |name| and 2027 * |value| can live after |session| was destroyed. 2028 */ 2029 typedef int (*nghttp2_on_header_callback2)(nghttp2_session *session, 2030 const nghttp2_frame *frame, 2031 nghttp2_rcbuf *name, 2032 nghttp2_rcbuf *value, uint8_t flags, 2033 void *user_data); 2034 2035 /** 2036 * @functypedef 2037 * 2038 * Callback function invoked when a invalid header name/value pair is 2039 * received for the |frame|. 2040 * 2041 * The parameter and behaviour are similar to 2042 * :type:`nghttp2_on_header_callback`. The difference is that this 2043 * callback is only invoked when a invalid header name/value pair is 2044 * received which is treated as stream error if this callback is not 2045 * set. Only invalid regular header field are passed to this 2046 * callback. In other words, invalid pseudo header field is not 2047 * passed to this callback. Also header fields which includes upper 2048 * cased latter are also treated as error without passing them to this 2049 * callback. 2050 * 2051 * This callback is only considered if HTTP messaging validation is 2052 * turned on (which is on by default, see 2053 * `nghttp2_option_set_no_http_messaging()`). 2054 * 2055 * With this callback, application inspects the incoming invalid 2056 * field, and it also can reset stream from this callback by returning 2057 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. By 2058 * default, the error code is 2059 * :enum:`nghttp2_error_code.NGHTTP2_PROTOCOL_ERROR`. To change the 2060 * error code, call `nghttp2_submit_rst_stream()` with the error code 2061 * of choice in addition to returning 2062 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 2063 * 2064 * If 0 is returned, the header field is ignored, and the stream is 2065 * not reset. 2066 */ 2067 typedef int (*nghttp2_on_invalid_header_callback)( 2068 nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, 2069 size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags, 2070 void *user_data); 2071 2072 /** 2073 * @functypedef 2074 * 2075 * Callback function invoked when a invalid header name/value pair is 2076 * received for the |frame|. 2077 * 2078 * The parameter and behaviour are similar to 2079 * :type:`nghttp2_on_header_callback2`. The difference is that this 2080 * callback is only invoked when a invalid header name/value pair is 2081 * received which is silently ignored if this callback is not set. 2082 * Only invalid regular header field are passed to this callback. In 2083 * other words, invalid pseudo header field is not passed to this 2084 * callback. Also header fields which includes upper cased latter are 2085 * also treated as error without passing them to this callback. 2086 * 2087 * This callback is only considered if HTTP messaging validation is 2088 * turned on (which is on by default, see 2089 * `nghttp2_option_set_no_http_messaging()`). 2090 * 2091 * With this callback, application inspects the incoming invalid 2092 * field, and it also can reset stream from this callback by returning 2093 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. By 2094 * default, the error code is 2095 * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. To change the 2096 * error code, call `nghttp2_submit_rst_stream()` with the error code 2097 * of choice in addition to returning 2098 * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. 2099 */ 2100 typedef int (*nghttp2_on_invalid_header_callback2)( 2101 nghttp2_session *session, const nghttp2_frame *frame, nghttp2_rcbuf *name, 2102 nghttp2_rcbuf *value, uint8_t flags, void *user_data); 2103 2104 #ifndef NGHTTP2_NO_SSIZE_T 2105 /** 2106 * @functypedef 2107 * 2108 * .. warning:: 2109 * 2110 * Deprecated. Use :type:`nghttp2_select_padding_callback2` 2111 * instead. 2112 * 2113 * Callback function invoked when the library asks application how 2114 * many padding bytes are required for the transmission of the 2115 * |frame|. The application must choose the total length of payload 2116 * including padded bytes in range [frame->hd.length, max_payloadlen], 2117 * inclusive. Choosing number not in this range will be treated as 2118 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Returning 2119 * ``frame->hd.length`` means no padding is added. Returning 2120 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will make 2121 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions 2122 * immediately return 2123 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2124 * 2125 * To set this callback to :type:`nghttp2_session_callbacks`, use 2126 * `nghttp2_session_callbacks_set_select_padding_callback()`. 2127 */ 2128 typedef ssize_t (*nghttp2_select_padding_callback)(nghttp2_session *session, 2129 const nghttp2_frame *frame, 2130 size_t max_payloadlen, 2131 void *user_data); 2132 2133 #endif /* NGHTTP2_NO_SSIZE_T */ 2134 2135 /** 2136 * @functypedef 2137 * 2138 * Callback function invoked when the library asks application how 2139 * many padding bytes are required for the transmission of the 2140 * |frame|. The application must choose the total length of payload 2141 * including padded bytes in range [frame->hd.length, max_payloadlen], 2142 * inclusive. Choosing number not in this range will be treated as 2143 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Returning 2144 * ``frame->hd.length`` means no padding is added. Returning 2145 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will make 2146 * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` 2147 * functions immediately return 2148 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2149 * 2150 * To set this callback to :type:`nghttp2_session_callbacks`, use 2151 * `nghttp2_session_callbacks_set_select_padding_callback2()`. 2152 */ 2153 typedef nghttp2_ssize (*nghttp2_select_padding_callback2)( 2154 nghttp2_session *session, const nghttp2_frame *frame, size_t max_payloadlen, 2155 void *user_data); 2156 2157 #ifndef NGHTTP2_NO_SSIZE_T 2158 /** 2159 * @functypedef 2160 * 2161 * .. warning:: 2162 * 2163 * Deprecated. Use 2164 * :type:`nghttp2_data_source_read_length_callback2` instead. 2165 * 2166 * Callback function invoked when library wants to get max length of 2167 * data to send data to the remote peer. The implementation of this 2168 * function should return a value in the following range. [1, 2169 * min(|session_remote_window_size|, |stream_remote_window_size|, 2170 * |remote_max_frame_size|)]. If a value greater than this range is 2171 * returned than the max allow value will be used. Returning a value 2172 * smaller than this range is treated as 2173 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The 2174 * |frame_type| is provided for future extensibility and identifies 2175 * the type of frame (see :type:`nghttp2_frame_type`) for which to get 2176 * the length for. Currently supported frame types are: 2177 * :enum:`nghttp2_frame_type.NGHTTP2_DATA`. 2178 * 2179 * This callback can be used to control the length in bytes for which 2180 * :type:`nghttp2_data_source_read_callback` is allowed to send to the 2181 * remote endpoint. This callback is optional. Returning 2182 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will signal the 2183 * entire session failure. 2184 * 2185 * To set this callback to :type:`nghttp2_session_callbacks`, use 2186 * `nghttp2_session_callbacks_set_data_source_read_length_callback()`. 2187 */ 2188 typedef ssize_t (*nghttp2_data_source_read_length_callback)( 2189 nghttp2_session *session, uint8_t frame_type, int32_t stream_id, 2190 int32_t session_remote_window_size, int32_t stream_remote_window_size, 2191 uint32_t remote_max_frame_size, void *user_data); 2192 2193 #endif /* NGHTTP2_NO_SSIZE_T */ 2194 2195 /** 2196 * @functypedef 2197 * 2198 * Callback function invoked when library wants to get max length of 2199 * data to send data to the remote peer. The implementation of this 2200 * function should return a value in the following range. [1, 2201 * min(|session_remote_window_size|, |stream_remote_window_size|, 2202 * |remote_max_frame_size|)]. If a value greater than this range is 2203 * returned than the max allow value will be used. Returning a value 2204 * smaller than this range is treated as 2205 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The 2206 * |frame_type| is provided for future extensibility and identifies 2207 * the type of frame (see :type:`nghttp2_frame_type`) for which to get 2208 * the length for. Currently supported frame types are: 2209 * :enum:`nghttp2_frame_type.NGHTTP2_DATA`. 2210 * 2211 * This callback can be used to control the length in bytes for which 2212 * :type:`nghttp2_data_source_read_callback` is allowed to send to the 2213 * remote endpoint. This callback is optional. Returning 2214 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will signal the 2215 * entire session failure. 2216 * 2217 * To set this callback to :type:`nghttp2_session_callbacks`, use 2218 * `nghttp2_session_callbacks_set_data_source_read_length_callback2()`. 2219 */ 2220 typedef nghttp2_ssize (*nghttp2_data_source_read_length_callback2)( 2221 nghttp2_session *session, uint8_t frame_type, int32_t stream_id, 2222 int32_t session_remote_window_size, int32_t stream_remote_window_size, 2223 uint32_t remote_max_frame_size, void *user_data); 2224 2225 /** 2226 * @functypedef 2227 * 2228 * Callback function invoked when a frame header is received. The 2229 * |hd| points to received frame header. 2230 * 2231 * Unlike :type:`nghttp2_on_frame_recv_callback`, this callback will 2232 * also be called when frame header of CONTINUATION frame is received. 2233 * 2234 * If both :type:`nghttp2_on_begin_frame_callback` and 2235 * :type:`nghttp2_on_begin_headers_callback` are set and HEADERS or 2236 * PUSH_PROMISE is received, :type:`nghttp2_on_begin_frame_callback` 2237 * will be called first. 2238 * 2239 * The implementation of this function must return 0 if it succeeds. 2240 * If nonzero value is returned, it is treated as fatal error and 2241 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 2242 * functions immediately return 2243 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2244 * 2245 * To set this callback to :type:`nghttp2_session_callbacks`, use 2246 * `nghttp2_session_callbacks_set_on_begin_frame_callback()`. 2247 */ 2248 typedef int (*nghttp2_on_begin_frame_callback)(nghttp2_session *session, 2249 const nghttp2_frame_hd *hd, 2250 void *user_data); 2251 2252 /** 2253 * @functypedef 2254 * 2255 * Callback function invoked when chunk of extension frame payload is 2256 * received. The |hd| points to frame header. The received 2257 * chunk is |data| of length |len|. 2258 * 2259 * The implementation of this function must return 0 if it succeeds. 2260 * 2261 * To abort processing this extension frame, return 2262 * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`. 2263 * 2264 * If fatal error occurred, application should return 2265 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, 2266 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 2267 * functions immediately return 2268 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 2269 * values are returned, currently they are treated as 2270 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2271 */ 2272 typedef int (*nghttp2_on_extension_chunk_recv_callback)( 2273 nghttp2_session *session, const nghttp2_frame_hd *hd, const uint8_t *data, 2274 size_t len, void *user_data); 2275 2276 /** 2277 * @functypedef 2278 * 2279 * Callback function invoked when library asks the application to 2280 * unpack extension payload from its wire format. The extension 2281 * payload has been passed to the application using 2282 * :type:`nghttp2_on_extension_chunk_recv_callback`. The frame header 2283 * is already unpacked by the library and provided as |hd|. 2284 * 2285 * To receive extension frames, the application must tell desired 2286 * extension frame type to the library using 2287 * `nghttp2_option_set_user_recv_extension_type()`. 2288 * 2289 * The implementation of this function may store the pointer to the 2290 * created object as a result of unpacking in |*payload|, and returns 2291 * 0. The pointer stored in |*payload| is opaque to the library, and 2292 * the library does not own its pointer. |*payload| is initialized as 2293 * ``NULL``. The |*payload| is available as ``frame->ext.payload`` in 2294 * :type:`nghttp2_on_frame_recv_callback`. Therefore if application 2295 * can free that memory inside :type:`nghttp2_on_frame_recv_callback` 2296 * callback. Of course, application has a liberty not to use 2297 * |*payload|, and do its own mechanism to process extension frames. 2298 * 2299 * To abort processing this extension frame, return 2300 * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`. 2301 * 2302 * If fatal error occurred, application should return 2303 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, 2304 * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` 2305 * functions immediately return 2306 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 2307 * values are returned, currently they are treated as 2308 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2309 */ 2310 typedef int (*nghttp2_unpack_extension_callback)(nghttp2_session *session, 2311 void **payload, 2312 const nghttp2_frame_hd *hd, 2313 void *user_data); 2314 2315 #ifndef NGHTTP2_NO_SSIZE_T 2316 /** 2317 * @functypedef 2318 * 2319 * .. warning:: 2320 * 2321 * Deprecated. Use :type:`nghttp2_pack_extension_callback2` 2322 * instead. 2323 * 2324 * Callback function invoked when library asks the application to pack 2325 * extension payload in its wire format. The frame header will be 2326 * packed by library. Application must pack payload only. 2327 * ``frame->ext.payload`` is the object passed to 2328 * `nghttp2_submit_extension()` as payload parameter. Application 2329 * must pack extension payload to the |buf| of its capacity |len| 2330 * bytes. The |len| is at least 16KiB. 2331 * 2332 * The implementation of this function should return the number of 2333 * bytes written into |buf| when it succeeds. 2334 * 2335 * To abort processing this extension frame, return 2336 * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`, and 2337 * :type:`nghttp2_on_frame_not_send_callback` will be invoked. 2338 * 2339 * If fatal error occurred, application should return 2340 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, 2341 * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions 2342 * immediately return 2343 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 2344 * values are returned, currently they are treated as 2345 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the return 2346 * value is strictly larger than |len|, it is treated as 2347 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2348 */ 2349 typedef ssize_t (*nghttp2_pack_extension_callback)(nghttp2_session *session, 2350 uint8_t *buf, size_t len, 2351 const nghttp2_frame *frame, 2352 void *user_data); 2353 2354 #endif /* NGHTTP2_NO_SSIZE_T */ 2355 2356 /** 2357 * @functypedef 2358 * 2359 * Callback function invoked when library asks the application to pack 2360 * extension payload in its wire format. The frame header will be 2361 * packed by library. Application must pack payload only. 2362 * ``frame->ext.payload`` is the object passed to 2363 * `nghttp2_submit_extension()` as payload parameter. Application 2364 * must pack extension payload to the |buf| of its capacity |len| 2365 * bytes. The |len| is at least 16KiB. 2366 * 2367 * The implementation of this function should return the number of 2368 * bytes written into |buf| when it succeeds. 2369 * 2370 * To abort processing this extension frame, return 2371 * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`, and 2372 * :type:`nghttp2_on_frame_not_send_callback` will be invoked. 2373 * 2374 * If fatal error occurred, application should return 2375 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, 2376 * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` 2377 * functions immediately return 2378 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other 2379 * values are returned, currently they are treated as 2380 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the return 2381 * value is strictly larger than |len|, it is treated as 2382 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2383 */ 2384 typedef nghttp2_ssize (*nghttp2_pack_extension_callback2)( 2385 nghttp2_session *session, uint8_t *buf, size_t len, 2386 const nghttp2_frame *frame, void *user_data); 2387 2388 /** 2389 * @functypedef 2390 * 2391 * .. warning:: 2392 * 2393 * Deprecated. Use :type:`nghttp2_error_callback2` instead. 2394 * 2395 * Callback function invoked when library provides the error message 2396 * intended for human consumption. This callback is solely for 2397 * debugging purpose. The |msg| is typically NULL-terminated string 2398 * of length |len|. |len| does not include the sentinel NULL 2399 * character. 2400 * 2401 * The format of error message may change between nghttp2 library 2402 * versions. The application should not depend on the particular 2403 * format. 2404 * 2405 * Normally, application should return 0 from this callback. If fatal 2406 * error occurred while doing something in this callback, application 2407 * should return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2408 * In this case, library will return immediately with return value 2409 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if 2410 * nonzero value is returned from this callback, they are treated as 2411 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, but application 2412 * should not rely on this details. 2413 */ 2414 typedef int (*nghttp2_error_callback)(nghttp2_session *session, const char *msg, 2415 size_t len, void *user_data); 2416 2417 /** 2418 * @functypedef 2419 * 2420 * Callback function invoked when library provides the error code, and 2421 * message. This callback is solely for debugging purpose. 2422 * |lib_error_code| is one of error code defined in 2423 * :enum:`nghttp2_error`. The |msg| is typically NULL-terminated 2424 * string of length |len|, and intended for human consumption. |len| 2425 * does not include the sentinel NULL character. 2426 * 2427 * The format of error message may change between nghttp2 library 2428 * versions. The application should not depend on the particular 2429 * format. 2430 * 2431 * Normally, application should return 0 from this callback. If fatal 2432 * error occurred while doing something in this callback, application 2433 * should return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. 2434 * In this case, library will return immediately with return value 2435 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Currently, if 2436 * nonzero value is returned from this callback, they are treated as 2437 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, but application 2438 * should not rely on this details. 2439 */ 2440 typedef int (*nghttp2_error_callback2)(nghttp2_session *session, 2441 int lib_error_code, const char *msg, 2442 size_t len, void *user_data); 2443 2444 struct nghttp2_session_callbacks; 2445 2446 /** 2447 * @struct 2448 * 2449 * Callback functions for :type:`nghttp2_session`. The details of 2450 * this structure are intentionally hidden from the public API. 2451 */ 2452 typedef struct nghttp2_session_callbacks nghttp2_session_callbacks; 2453 2454 /** 2455 * @function 2456 * 2457 * Initializes |*callbacks_ptr| with NULL values. 2458 * 2459 * The initialized object can be used when initializing multiple 2460 * :type:`nghttp2_session` objects. 2461 * 2462 * When the application finished using this object, it can use 2463 * `nghttp2_session_callbacks_del()` to free its memory. 2464 * 2465 * This function returns 0 if it succeeds, or one of the following 2466 * negative error codes: 2467 * 2468 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 2469 * Out of memory. 2470 */ 2471 NGHTTP2_EXTERN int 2472 nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr); 2473 2474 /** 2475 * @function 2476 * 2477 * Frees any resources allocated for |callbacks|. If |callbacks| is 2478 * ``NULL``, this function does nothing. 2479 */ 2480 NGHTTP2_EXTERN void 2481 nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks); 2482 2483 #ifndef NGHTTP2_NO_SSIZE_T 2484 /** 2485 * @function 2486 * 2487 * .. warning:: 2488 * 2489 * Deprecated. Use `nghttp2_session_callbacks_set_send_callback2()` 2490 * with :type:`nghttp2_send_callback2` instead. 2491 * 2492 * Sets callback function invoked when a session wants to send data to 2493 * the remote peer. This callback is not necessary if the application 2494 * uses solely `nghttp2_session_mem_send()` to serialize data to 2495 * transmit. 2496 */ 2497 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback( 2498 nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback); 2499 2500 #endif /* NGHTTP2_NO_SSIZE_T */ 2501 2502 /** 2503 * @function 2504 * 2505 * Sets callback function invoked when a session wants to send data to 2506 * the remote peer. This callback is not necessary if the application 2507 * uses solely `nghttp2_session_mem_send2()` to serialize data to 2508 * transmit. 2509 */ 2510 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback2( 2511 nghttp2_session_callbacks *cbs, nghttp2_send_callback2 send_callback); 2512 2513 #ifndef NGHTTP2_NO_SSIZE_T 2514 /** 2515 * @function 2516 * 2517 * .. warning:: 2518 * 2519 * Deprecated. Use `nghttp2_session_callbacks_set_recv_callback2()` 2520 * with :type:`nghttp2_recv_callback2` instead. 2521 * 2522 * Sets callback function invoked when the a session wants to receive 2523 * data from the remote peer. This callback is not necessary if the 2524 * application uses solely `nghttp2_session_mem_recv()` to process 2525 * received data. 2526 */ 2527 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback( 2528 nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback); 2529 2530 #endif /* NGHTTP2_NO_SSIZE_T */ 2531 2532 /** 2533 * @function 2534 * 2535 * Sets callback function invoked when the a session wants to receive 2536 * data from the remote peer. This callback is not necessary if the 2537 * application uses solely `nghttp2_session_mem_recv2()` to process 2538 * received data. 2539 */ 2540 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback2( 2541 nghttp2_session_callbacks *cbs, nghttp2_recv_callback2 recv_callback); 2542 2543 /** 2544 * @function 2545 * 2546 * Sets callback function invoked by `nghttp2_session_recv()` and 2547 * `nghttp2_session_mem_recv2()` when a frame is received. 2548 */ 2549 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback( 2550 nghttp2_session_callbacks *cbs, 2551 nghttp2_on_frame_recv_callback on_frame_recv_callback); 2552 2553 /** 2554 * @function 2555 * 2556 * Sets callback function invoked by `nghttp2_session_recv()` and 2557 * `nghttp2_session_mem_recv2()` when an invalid non-DATA frame is 2558 * received. 2559 */ 2560 NGHTTP2_EXTERN void 2561 nghttp2_session_callbacks_set_on_invalid_frame_recv_callback( 2562 nghttp2_session_callbacks *cbs, 2563 nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback); 2564 2565 /** 2566 * @function 2567 * 2568 * Sets callback function invoked when a chunk of data in DATA frame 2569 * is received. 2570 */ 2571 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_data_chunk_recv_callback( 2572 nghttp2_session_callbacks *cbs, 2573 nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback); 2574 2575 /** 2576 * @function 2577 * 2578 * Sets callback function invoked before a non-DATA frame is sent. 2579 */ 2580 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_before_frame_send_callback( 2581 nghttp2_session_callbacks *cbs, 2582 nghttp2_before_frame_send_callback before_frame_send_callback); 2583 2584 /** 2585 * @function 2586 * 2587 * Sets callback function invoked after a frame is sent. 2588 */ 2589 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_send_callback( 2590 nghttp2_session_callbacks *cbs, 2591 nghttp2_on_frame_send_callback on_frame_send_callback); 2592 2593 /** 2594 * @function 2595 * 2596 * Sets callback function invoked when a non-DATA frame is not sent 2597 * because of an error. 2598 */ 2599 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_not_send_callback( 2600 nghttp2_session_callbacks *cbs, 2601 nghttp2_on_frame_not_send_callback on_frame_not_send_callback); 2602 2603 /** 2604 * @function 2605 * 2606 * Sets callback function invoked when the stream is closed. 2607 */ 2608 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_stream_close_callback( 2609 nghttp2_session_callbacks *cbs, 2610 nghttp2_on_stream_close_callback on_stream_close_callback); 2611 2612 /** 2613 * @function 2614 * 2615 * Sets callback function invoked when the reception of header block 2616 * in HEADERS or PUSH_PROMISE is started. 2617 */ 2618 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_headers_callback( 2619 nghttp2_session_callbacks *cbs, 2620 nghttp2_on_begin_headers_callback on_begin_headers_callback); 2621 2622 /** 2623 * @function 2624 * 2625 * Sets callback function invoked when a header name/value pair is 2626 * received. If both 2627 * `nghttp2_session_callbacks_set_on_header_callback()` and 2628 * `nghttp2_session_callbacks_set_on_header_callback2()` are used to 2629 * set callbacks, the latter has the precedence. 2630 */ 2631 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback( 2632 nghttp2_session_callbacks *cbs, 2633 nghttp2_on_header_callback on_header_callback); 2634 2635 /** 2636 * @function 2637 * 2638 * Sets callback function invoked when a header name/value pair is 2639 * received. 2640 */ 2641 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback2( 2642 nghttp2_session_callbacks *cbs, 2643 nghttp2_on_header_callback2 on_header_callback2); 2644 2645 /** 2646 * @function 2647 * 2648 * Sets callback function invoked when a invalid header name/value 2649 * pair is received. If both 2650 * `nghttp2_session_callbacks_set_on_invalid_header_callback()` and 2651 * `nghttp2_session_callbacks_set_on_invalid_header_callback2()` are 2652 * used to set callbacks, the latter takes the precedence. 2653 */ 2654 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback( 2655 nghttp2_session_callbacks *cbs, 2656 nghttp2_on_invalid_header_callback on_invalid_header_callback); 2657 2658 /** 2659 * @function 2660 * 2661 * Sets callback function invoked when a invalid header name/value 2662 * pair is received. 2663 */ 2664 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback2( 2665 nghttp2_session_callbacks *cbs, 2666 nghttp2_on_invalid_header_callback2 on_invalid_header_callback2); 2667 2668 #ifndef NGHTTP2_NO_SSIZE_T 2669 /** 2670 * @function 2671 * 2672 * .. warning:: 2673 * 2674 * Deprecated. Use 2675 * `nghttp2_session_callbacks_set_select_padding_callback2()` with 2676 * :type:`nghttp2_select_padding_callback2` instead. 2677 * 2678 * Sets callback function invoked when the library asks application 2679 * how many padding bytes are required for the transmission of the 2680 * given frame. 2681 */ 2682 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback( 2683 nghttp2_session_callbacks *cbs, 2684 nghttp2_select_padding_callback select_padding_callback); 2685 2686 #endif /* NGHTTP2_NO_SSIZE_T */ 2687 2688 /** 2689 * @function 2690 * 2691 * Sets callback function invoked when the library asks application 2692 * how many padding bytes are required for the transmission of the 2693 * given frame. 2694 */ 2695 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback2( 2696 nghttp2_session_callbacks *cbs, 2697 nghttp2_select_padding_callback2 select_padding_callback); 2698 2699 #ifndef NGHTTP2_NO_SSIZE_T 2700 /** 2701 * @function 2702 * 2703 * .. warning:: 2704 * 2705 * Deprecated. Use 2706 * `nghttp2_session_callbacks_set_data_source_read_length_callback2()` 2707 * with :type:`nghttp2_data_source_read_length_callback2` instead. 2708 * 2709 * Sets callback function determine the length allowed in 2710 * :type:`nghttp2_data_source_read_callback`. 2711 */ 2712 NGHTTP2_EXTERN void 2713 nghttp2_session_callbacks_set_data_source_read_length_callback( 2714 nghttp2_session_callbacks *cbs, 2715 nghttp2_data_source_read_length_callback data_source_read_length_callback); 2716 2717 #endif /* NGHTTP2_NO_SSIZE_T */ 2718 2719 /** 2720 * @function 2721 * 2722 * Sets callback function determine the length allowed in 2723 * :type:`nghttp2_data_source_read_callback2`. 2724 */ 2725 NGHTTP2_EXTERN void 2726 nghttp2_session_callbacks_set_data_source_read_length_callback2( 2727 nghttp2_session_callbacks *cbs, 2728 nghttp2_data_source_read_length_callback2 data_source_read_length_callback); 2729 2730 /** 2731 * @function 2732 * 2733 * Sets callback function invoked when a frame header is received. 2734 */ 2735 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_frame_callback( 2736 nghttp2_session_callbacks *cbs, 2737 nghttp2_on_begin_frame_callback on_begin_frame_callback); 2738 2739 /** 2740 * @function 2741 * 2742 * Sets callback function invoked when 2743 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` is used in 2744 * :type:`nghttp2_data_source_read_callback2` to avoid data copy. 2745 */ 2746 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_data_callback( 2747 nghttp2_session_callbacks *cbs, 2748 nghttp2_send_data_callback send_data_callback); 2749 2750 #ifndef NGHTTP2_NO_SSIZE_T 2751 /** 2752 * @function 2753 * 2754 * .. warning:: 2755 * 2756 * Deprecated. Use 2757 * `nghttp2_session_callbacks_set_pack_extension_callback2()` with 2758 * :type:`nghttp2_pack_extension_callback2` instead. 2759 * 2760 * Sets callback function invoked when the library asks the 2761 * application to pack extension frame payload in wire format. 2762 */ 2763 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback( 2764 nghttp2_session_callbacks *cbs, 2765 nghttp2_pack_extension_callback pack_extension_callback); 2766 2767 #endif /* NGHTTP2_NO_SSIZE_T */ 2768 2769 /** 2770 * @function 2771 * 2772 * Sets callback function invoked when the library asks the 2773 * application to pack extension frame payload in wire format. 2774 */ 2775 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback2( 2776 nghttp2_session_callbacks *cbs, 2777 nghttp2_pack_extension_callback2 pack_extension_callback); 2778 2779 /** 2780 * @function 2781 * 2782 * Sets callback function invoked when the library asks the 2783 * application to unpack extension frame payload from wire format. 2784 */ 2785 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_unpack_extension_callback( 2786 nghttp2_session_callbacks *cbs, 2787 nghttp2_unpack_extension_callback unpack_extension_callback); 2788 2789 /** 2790 * @function 2791 * 2792 * Sets callback function invoked when chunk of extension frame 2793 * payload is received. 2794 */ 2795 NGHTTP2_EXTERN void 2796 nghttp2_session_callbacks_set_on_extension_chunk_recv_callback( 2797 nghttp2_session_callbacks *cbs, 2798 nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback); 2799 2800 /** 2801 * @function 2802 * 2803 * .. warning:: 2804 * 2805 * Deprecated. Use 2806 * `nghttp2_session_callbacks_set_error_callback2()` with 2807 * :type:`nghttp2_error_callback2` instead. 2808 * 2809 * Sets callback function invoked when library tells error message to 2810 * the application. 2811 * 2812 * If both :type:`nghttp2_error_callback` and 2813 * :type:`nghttp2_error_callback2` are set, the latter takes 2814 * precedence. 2815 */ 2816 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback( 2817 nghttp2_session_callbacks *cbs, nghttp2_error_callback error_callback); 2818 2819 /** 2820 * @function 2821 * 2822 * Sets callback function invoked when library tells error code, and 2823 * message to the application. 2824 * 2825 * If both :type:`nghttp2_error_callback` and 2826 * :type:`nghttp2_error_callback2` are set, the latter takes 2827 * precedence. 2828 */ 2829 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback2( 2830 nghttp2_session_callbacks *cbs, nghttp2_error_callback2 error_callback2); 2831 2832 /** 2833 * @functypedef 2834 * 2835 * Custom memory allocator to replace malloc(). The |mem_user_data| 2836 * is the mem_user_data member of :type:`nghttp2_mem` structure. 2837 */ 2838 typedef void *(*nghttp2_malloc)(size_t size, void *mem_user_data); 2839 2840 /** 2841 * @functypedef 2842 * 2843 * Custom memory allocator to replace free(). The |mem_user_data| is 2844 * the mem_user_data member of :type:`nghttp2_mem` structure. 2845 */ 2846 typedef void (*nghttp2_free)(void *ptr, void *mem_user_data); 2847 2848 /** 2849 * @functypedef 2850 * 2851 * Custom memory allocator to replace calloc(). The |mem_user_data| 2852 * is the mem_user_data member of :type:`nghttp2_mem` structure. 2853 */ 2854 typedef void *(*nghttp2_calloc)(size_t nmemb, size_t size, void *mem_user_data); 2855 2856 /** 2857 * @functypedef 2858 * 2859 * Custom memory allocator to replace realloc(). The |mem_user_data| 2860 * is the mem_user_data member of :type:`nghttp2_mem` structure. 2861 */ 2862 typedef void *(*nghttp2_realloc)(void *ptr, size_t size, void *mem_user_data); 2863 2864 /** 2865 * @struct 2866 * 2867 * Custom memory allocator functions and user defined pointer. The 2868 * |mem_user_data| member is passed to each allocator function. This 2869 * can be used, for example, to achieve per-session memory pool. 2870 * 2871 * In the following example code, ``my_malloc``, ``my_free``, 2872 * ``my_calloc`` and ``my_realloc`` are the replacement of the 2873 * standard allocators ``malloc``, ``free``, ``calloc`` and 2874 * ``realloc`` respectively:: 2875 * 2876 * void *my_malloc_cb(size_t size, void *mem_user_data) { 2877 * return my_malloc(size); 2878 * } 2879 * 2880 * void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); } 2881 * 2882 * void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) { 2883 * return my_calloc(nmemb, size); 2884 * } 2885 * 2886 * void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) { 2887 * return my_realloc(ptr, size); 2888 * } 2889 * 2890 * void session_new() { 2891 * nghttp2_session *session; 2892 * nghttp2_session_callbacks *callbacks; 2893 * nghttp2_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb, 2894 * my_realloc_cb}; 2895 * 2896 * ... 2897 * 2898 * nghttp2_session_client_new3(&session, callbacks, NULL, NULL, &mem); 2899 * 2900 * ... 2901 * } 2902 */ 2903 typedef struct { 2904 /** 2905 * An arbitrary user supplied data. This is passed to each 2906 * allocator function. 2907 */ 2908 void *mem_user_data; 2909 /** 2910 * Custom allocator function to replace malloc(). 2911 */ 2912 nghttp2_malloc malloc; 2913 /** 2914 * Custom allocator function to replace free(). 2915 */ 2916 nghttp2_free free; 2917 /** 2918 * Custom allocator function to replace calloc(). 2919 */ 2920 nghttp2_calloc calloc; 2921 /** 2922 * Custom allocator function to replace realloc(). 2923 */ 2924 nghttp2_realloc realloc; 2925 } nghttp2_mem; 2926 2927 struct nghttp2_option; 2928 2929 /** 2930 * @struct 2931 * 2932 * Configuration options for :type:`nghttp2_session`. The details of 2933 * this structure are intentionally hidden from the public API. 2934 */ 2935 typedef struct nghttp2_option nghttp2_option; 2936 2937 /** 2938 * @function 2939 * 2940 * Initializes |*option_ptr| with default values. 2941 * 2942 * When the application finished using this object, it can use 2943 * `nghttp2_option_del()` to free its memory. 2944 * 2945 * This function returns 0 if it succeeds, or one of the following 2946 * negative error codes: 2947 * 2948 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 2949 * Out of memory. 2950 */ 2951 NGHTTP2_EXTERN int nghttp2_option_new(nghttp2_option **option_ptr); 2952 2953 /** 2954 * @function 2955 * 2956 * Frees any resources allocated for |option|. If |option| is 2957 * ``NULL``, this function does nothing. 2958 */ 2959 NGHTTP2_EXTERN void nghttp2_option_del(nghttp2_option *option); 2960 2961 /** 2962 * @function 2963 * 2964 * This option prevents the library from sending WINDOW_UPDATE for a 2965 * connection automatically. If this option is set to nonzero, the 2966 * library won't send WINDOW_UPDATE for DATA until application calls 2967 * `nghttp2_session_consume()` to indicate the consumed amount of 2968 * data. Don't use `nghttp2_submit_window_update()` for this purpose. 2969 * By default, this option is set to zero. 2970 */ 2971 NGHTTP2_EXTERN void 2972 nghttp2_option_set_no_auto_window_update(nghttp2_option *option, int val); 2973 2974 /** 2975 * @function 2976 * 2977 * This option sets the SETTINGS_MAX_CONCURRENT_STREAMS value of 2978 * remote endpoint as if it is received in SETTINGS frame. Without 2979 * specifying this option, the maximum number of outgoing concurrent 2980 * streams is initially limited to 100 to avoid issues when the local 2981 * endpoint submits lots of requests before receiving initial SETTINGS 2982 * frame from the remote endpoint, since sending them at once to the 2983 * remote endpoint could lead to rejection of some of the requests. 2984 * This value will be overwritten when the local endpoint receives 2985 * initial SETTINGS frame from the remote endpoint, either to the 2986 * value advertised in SETTINGS_MAX_CONCURRENT_STREAMS or to the 2987 * default value (unlimited) if none was advertised. 2988 */ 2989 NGHTTP2_EXTERN void 2990 nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option, 2991 uint32_t val); 2992 2993 /** 2994 * @function 2995 * 2996 * By default, nghttp2 library, if configured as server, requires 2997 * first 24 bytes of client magic byte string (MAGIC). In most cases, 2998 * this will simplify the implementation of server. But sometimes 2999 * server may want to detect the application protocol based on first 3000 * few bytes on clear text communication. 3001 * 3002 * If this option is used with nonzero |val|, nghttp2 library does not 3003 * handle MAGIC. It still checks following SETTINGS frame. This 3004 * means that applications should deal with MAGIC by themselves. 3005 * 3006 * If this option is not used or used with zero value, if MAGIC does 3007 * not match :macro:`NGHTTP2_CLIENT_MAGIC`, `nghttp2_session_recv()` 3008 * and `nghttp2_session_mem_recv2()` will return error 3009 * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`, which is fatal 3010 * error. 3011 */ 3012 NGHTTP2_EXTERN void 3013 nghttp2_option_set_no_recv_client_magic(nghttp2_option *option, int val); 3014 3015 /** 3016 * @function 3017 * 3018 * By default, nghttp2 library enforces subset of HTTP Messaging rules 3019 * described in `HTTP/2 specification, section 8 3020 * <https://tools.ietf.org/html/rfc7540#section-8>`_. See 3021 * :ref:`http-messaging` section for details. For those applications 3022 * who use nghttp2 library as non-HTTP use, give nonzero to |val| to 3023 * disable this enforcement. Please note that disabling this feature 3024 * does not change the fundamental client and server model of HTTP. 3025 * That is, even if the validation is disabled, only client can send 3026 * requests. 3027 */ 3028 NGHTTP2_EXTERN void nghttp2_option_set_no_http_messaging(nghttp2_option *option, 3029 int val); 3030 3031 /** 3032 * @function 3033 * 3034 * RFC 7540 does not enforce any limit on the number of incoming 3035 * reserved streams (in RFC 7540 terms, streams in reserved (remote) 3036 * state). This only affects client side, since only server can push 3037 * streams. Malicious server can push arbitrary number of streams, 3038 * and make client's memory exhausted. This option can set the 3039 * maximum number of such incoming streams to avoid possible memory 3040 * exhaustion. If this option is set, and pushed streams are 3041 * automatically closed on reception, without calling user provided 3042 * callback, if they exceed the given limit. The default value is 3043 * 200. If session is configured as server side, this option has no 3044 * effect. Server can control the number of streams to push. 3045 */ 3046 NGHTTP2_EXTERN void 3047 nghttp2_option_set_max_reserved_remote_streams(nghttp2_option *option, 3048 uint32_t val); 3049 3050 /** 3051 * @function 3052 * 3053 * Sets extension frame type the application is willing to handle with 3054 * user defined callbacks (see 3055 * :type:`nghttp2_on_extension_chunk_recv_callback` and 3056 * :type:`nghttp2_unpack_extension_callback`). The |type| is 3057 * extension frame type, and must be strictly greater than 0x9. 3058 * Otherwise, this function does nothing. The application can call 3059 * this function multiple times to set more than one frame type to 3060 * receive. The application does not have to call this function if it 3061 * just sends extension frames. 3062 */ 3063 NGHTTP2_EXTERN void 3064 nghttp2_option_set_user_recv_extension_type(nghttp2_option *option, 3065 uint8_t type); 3066 3067 /** 3068 * @function 3069 * 3070 * Sets extension frame type the application is willing to receive 3071 * using builtin handler. The |type| is the extension frame type to 3072 * receive, and must be strictly greater than 0x9. Otherwise, this 3073 * function does nothing. The application can call this function 3074 * multiple times to set more than one frame type to receive. The 3075 * application does not have to call this function if it just sends 3076 * extension frames. 3077 * 3078 * If same frame type is passed to both 3079 * `nghttp2_option_set_builtin_recv_extension_type()` and 3080 * `nghttp2_option_set_user_recv_extension_type()`, the latter takes 3081 * precedence. 3082 */ 3083 NGHTTP2_EXTERN void 3084 nghttp2_option_set_builtin_recv_extension_type(nghttp2_option *option, 3085 uint8_t type); 3086 3087 /** 3088 * @function 3089 * 3090 * This option prevents the library from sending PING frame with ACK 3091 * flag set automatically when PING frame without ACK flag set is 3092 * received. If this option is set to nonzero, the library won't send 3093 * PING frame with ACK flag set in the response for incoming PING 3094 * frame. The application can send PING frame with ACK flag set using 3095 * `nghttp2_submit_ping()` with :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK` 3096 * as flags parameter. 3097 */ 3098 NGHTTP2_EXTERN void nghttp2_option_set_no_auto_ping_ack(nghttp2_option *option, 3099 int val); 3100 3101 /** 3102 * @function 3103 * 3104 * This option sets the maximum length of header block (a set of 3105 * header fields per one HEADERS frame) to send. The length of a 3106 * given set of header fields is calculated using 3107 * `nghttp2_hd_deflate_bound()`. The default value is 64KiB. If 3108 * application attempts to send header fields larger than this limit, 3109 * the transmission of the frame fails with error code 3110 * :enum:`nghttp2_error.NGHTTP2_ERR_FRAME_SIZE_ERROR`. 3111 */ 3112 NGHTTP2_EXTERN void 3113 nghttp2_option_set_max_send_header_block_length(nghttp2_option *option, 3114 size_t val); 3115 3116 /** 3117 * @function 3118 * 3119 * This option sets the maximum dynamic table size for deflating 3120 * header fields. The default value is 4KiB. In HTTP/2, receiver of 3121 * deflated header block can specify maximum dynamic table size. The 3122 * actual maximum size is the minimum of the size receiver specified 3123 * and this option value. 3124 */ 3125 NGHTTP2_EXTERN void 3126 nghttp2_option_set_max_deflate_dynamic_table_size(nghttp2_option *option, 3127 size_t val); 3128 3129 /** 3130 * @function 3131 * 3132 * This option prevents the library from retaining closed streams to 3133 * maintain the priority tree. If this option is set to nonzero, 3134 * applications can discard closed stream completely to save memory. 3135 * 3136 * If 3137 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 3138 * of value of 1 is submitted via `nghttp2_submit_settings()`, any 3139 * closed streams are not retained regardless of this option. 3140 */ 3141 NGHTTP2_EXTERN void nghttp2_option_set_no_closed_streams(nghttp2_option *option, 3142 int val); 3143 3144 /** 3145 * @function 3146 * 3147 * This function sets the maximum number of outgoing SETTINGS ACK and 3148 * PING ACK frames retained in :type:`nghttp2_session` object. If 3149 * more than those frames are retained, the peer is considered to be 3150 * misbehaving and session will be closed. The default value is 1000. 3151 */ 3152 NGHTTP2_EXTERN void nghttp2_option_set_max_outbound_ack(nghttp2_option *option, 3153 size_t val); 3154 3155 /** 3156 * @function 3157 * 3158 * This function sets the maximum number of SETTINGS entries per 3159 * SETTINGS frame that will be accepted. If more than those entries 3160 * are received, the peer is considered to be misbehaving and session 3161 * will be closed. The default value is 32. 3162 */ 3163 NGHTTP2_EXTERN void nghttp2_option_set_max_settings(nghttp2_option *option, 3164 size_t val); 3165 3166 /** 3167 * @function 3168 * 3169 * This option, if set to nonzero, allows server to fallback to 3170 * :rfc:`7540` priorities if SETTINGS_NO_RFC7540_PRIORITIES was not 3171 * received from client, and server submitted 3172 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 3173 * = 1 via `nghttp2_submit_settings()`. Most of the advanced 3174 * functionality for RFC 7540 priorities are still disabled. This 3175 * fallback only enables the minimal feature set of RFC 7540 3176 * priorities to deal with priority signaling from client. 3177 * 3178 * Client session ignores this option. 3179 */ 3180 NGHTTP2_EXTERN void 3181 nghttp2_option_set_server_fallback_rfc7540_priorities(nghttp2_option *option, 3182 int val); 3183 3184 /** 3185 * @function 3186 * 3187 * This option, if set to nonzero, turns off RFC 9113 leading and 3188 * trailing white spaces validation against HTTP field value. Some 3189 * important fields, such as HTTP/2 pseudo header fields, are 3190 * validated more strictly and this option does not apply to them. 3191 */ 3192 NGHTTP2_EXTERN void 3193 nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation( 3194 nghttp2_option *option, int val); 3195 3196 /** 3197 * @function 3198 * 3199 * This function sets the rate limit for the incoming stream reset 3200 * (RST_STREAM frame). It is server use only. It is a token-bucket 3201 * based rate limiter. |burst| specifies the number of tokens that is 3202 * initially available. The maximum number of tokens is capped to 3203 * this value. |rate| specifies the number of tokens that are 3204 * regenerated per second. An incoming RST_STREAM consumes one token. 3205 * If there is no token available, GOAWAY is sent to tear down the 3206 * connection. |burst| and |rate| default to 1000 and 33 3207 * respectively. 3208 */ 3209 NGHTTP2_EXTERN void 3210 nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option, 3211 uint64_t burst, uint64_t rate); 3212 3213 /** 3214 * @function 3215 * 3216 * This function sets the maximum number of CONTINUATION frames 3217 * following an incoming HEADER frame. If more than those frames are 3218 * received, the remote endpoint is considered to be misbehaving and 3219 * session will be closed. The default value is 8. 3220 */ 3221 NGHTTP2_EXTERN void nghttp2_option_set_max_continuations(nghttp2_option *option, 3222 size_t val); 3223 3224 /** 3225 * @function 3226 * 3227 * Initializes |*session_ptr| for client use. The all members of 3228 * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr| 3229 * does not store |callbacks|. The |user_data| is an arbitrary user 3230 * supplied data, which will be passed to the callback functions. 3231 * 3232 * The :type:`nghttp2_send_callback2` must be specified. If the 3233 * application code uses `nghttp2_session_recv()`, the 3234 * :type:`nghttp2_recv_callback` must be specified. The other members 3235 * of |callbacks| can be ``NULL``. 3236 * 3237 * If this function fails, |*session_ptr| is left untouched. 3238 * 3239 * This function returns 0 if it succeeds, or one of the following 3240 * negative error codes: 3241 * 3242 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3243 * Out of memory. 3244 */ 3245 NGHTTP2_EXTERN int 3246 nghttp2_session_client_new(nghttp2_session **session_ptr, 3247 const nghttp2_session_callbacks *callbacks, 3248 void *user_data); 3249 3250 /** 3251 * @function 3252 * 3253 * Initializes |*session_ptr| for server use. The all members of 3254 * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr| 3255 * does not store |callbacks|. The |user_data| is an arbitrary user 3256 * supplied data, which will be passed to the callback functions. 3257 * 3258 * The :type:`nghttp2_send_callback2` must be specified. If the 3259 * application code uses `nghttp2_session_recv()`, the 3260 * :type:`nghttp2_recv_callback` must be specified. The other members 3261 * of |callbacks| can be ``NULL``. 3262 * 3263 * If this function fails, |*session_ptr| is left untouched. 3264 * 3265 * This function returns 0 if it succeeds, or one of the following 3266 * negative error codes: 3267 * 3268 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3269 * Out of memory. 3270 */ 3271 NGHTTP2_EXTERN int 3272 nghttp2_session_server_new(nghttp2_session **session_ptr, 3273 const nghttp2_session_callbacks *callbacks, 3274 void *user_data); 3275 3276 /** 3277 * @function 3278 * 3279 * Like `nghttp2_session_client_new()`, but with additional options 3280 * specified in the |option|. 3281 * 3282 * The |option| can be ``NULL`` and the call is equivalent to 3283 * `nghttp2_session_client_new()`. 3284 * 3285 * This function does not take ownership |option|. The application is 3286 * responsible for freeing |option| if it finishes using the object. 3287 * 3288 * The library code does not refer to |option| after this function 3289 * returns. 3290 * 3291 * This function returns 0 if it succeeds, or one of the following 3292 * negative error codes: 3293 * 3294 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3295 * Out of memory. 3296 */ 3297 NGHTTP2_EXTERN int 3298 nghttp2_session_client_new2(nghttp2_session **session_ptr, 3299 const nghttp2_session_callbacks *callbacks, 3300 void *user_data, const nghttp2_option *option); 3301 3302 /** 3303 * @function 3304 * 3305 * Like `nghttp2_session_server_new()`, but with additional options 3306 * specified in the |option|. 3307 * 3308 * The |option| can be ``NULL`` and the call is equivalent to 3309 * `nghttp2_session_server_new()`. 3310 * 3311 * This function does not take ownership |option|. The application is 3312 * responsible for freeing |option| if it finishes using the object. 3313 * 3314 * The library code does not refer to |option| after this function 3315 * returns. 3316 * 3317 * This function returns 0 if it succeeds, or one of the following 3318 * negative error codes: 3319 * 3320 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3321 * Out of memory. 3322 */ 3323 NGHTTP2_EXTERN int 3324 nghttp2_session_server_new2(nghttp2_session **session_ptr, 3325 const nghttp2_session_callbacks *callbacks, 3326 void *user_data, const nghttp2_option *option); 3327 3328 /** 3329 * @function 3330 * 3331 * Like `nghttp2_session_client_new2()`, but with additional custom 3332 * memory allocator specified in the |mem|. 3333 * 3334 * The |mem| can be ``NULL`` and the call is equivalent to 3335 * `nghttp2_session_client_new2()`. 3336 * 3337 * This function does not take ownership |mem|. The application is 3338 * responsible for freeing |mem|. 3339 * 3340 * The library code does not refer to |mem| pointer after this 3341 * function returns, so the application can safely free it. 3342 * 3343 * This function returns 0 if it succeeds, or one of the following 3344 * negative error codes: 3345 * 3346 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3347 * Out of memory. 3348 */ 3349 NGHTTP2_EXTERN int nghttp2_session_client_new3( 3350 nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks, 3351 void *user_data, const nghttp2_option *option, nghttp2_mem *mem); 3352 3353 /** 3354 * @function 3355 * 3356 * Like `nghttp2_session_server_new2()`, but with additional custom 3357 * memory allocator specified in the |mem|. 3358 * 3359 * The |mem| can be ``NULL`` and the call is equivalent to 3360 * `nghttp2_session_server_new2()`. 3361 * 3362 * This function does not take ownership |mem|. The application is 3363 * responsible for freeing |mem|. 3364 * 3365 * The library code does not refer to |mem| pointer after this 3366 * function returns, so the application can safely free it. 3367 * 3368 * This function returns 0 if it succeeds, or one of the following 3369 * negative error codes: 3370 * 3371 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3372 * Out of memory. 3373 */ 3374 NGHTTP2_EXTERN int nghttp2_session_server_new3( 3375 nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks, 3376 void *user_data, const nghttp2_option *option, nghttp2_mem *mem); 3377 3378 /** 3379 * @function 3380 * 3381 * Frees any resources allocated for |session|. If |session| is 3382 * ``NULL``, this function does nothing. 3383 */ 3384 NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session); 3385 3386 /** 3387 * @function 3388 * 3389 * Sends pending frames to the remote peer. 3390 * 3391 * This function retrieves the highest prioritized frame from the 3392 * outbound queue and sends it to the remote peer. It does this as 3393 * many times as possible until the user callback 3394 * :type:`nghttp2_send_callback2` returns 3395 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`, the outbound queue 3396 * becomes empty or flow control is triggered (remote window size 3397 * becomes depleted or maximum number of concurrent streams is 3398 * reached). This function calls several callback functions which are 3399 * passed when initializing the |session|. Here is the simple time 3400 * chart which tells when each callback is invoked: 3401 * 3402 * 1. Get the next frame to send from outbound queue. 3403 * 3404 * 2. Prepare transmission of the frame. 3405 * 3406 * 3. If the control frame cannot be sent because some preconditions 3407 * are not met (e.g., request HEADERS cannot be sent after GOAWAY), 3408 * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort 3409 * the following steps. 3410 * 3411 * 4. If the frame is HEADERS, PUSH_PROMISE or DATA, 3412 * :type:`nghttp2_select_padding_callback` is invoked. 3413 * 3414 * 5. If the frame is request HEADERS, the stream is opened here. 3415 * 3416 * 6. :type:`nghttp2_before_frame_send_callback` is invoked. 3417 * 3418 * 7. If :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL` is returned from 3419 * :type:`nghttp2_before_frame_send_callback`, the current frame 3420 * transmission is canceled, and 3421 * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort 3422 * the following steps. 3423 * 3424 * 8. :type:`nghttp2_send_callback2` is invoked one or more times to 3425 * send the frame. 3426 * 3427 * 9. :type:`nghttp2_on_frame_send_callback` is invoked. 3428 * 3429 * 10. If the transmission of the frame triggers closure of the 3430 * stream, the stream is closed and 3431 * :type:`nghttp2_on_stream_close_callback` is invoked. 3432 * 3433 * This function returns 0 if it succeeds, or one of the following 3434 * negative error codes: 3435 * 3436 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3437 * Out of memory. 3438 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` 3439 * The callback function failed. 3440 */ 3441 NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session); 3442 3443 #ifndef NGHTTP2_NO_SSIZE_T 3444 /** 3445 * @function 3446 * 3447 * .. warning:: 3448 * 3449 * Deprecated. Use `nghttp2_session_mem_send2()` instead. 3450 * 3451 * Returns the serialized data to send. 3452 * 3453 * This function behaves like `nghttp2_session_send()` except that it 3454 * does not use :type:`nghttp2_send_callback` to transmit data. 3455 * Instead, it assigns the pointer to the serialized data to the 3456 * |*data_ptr| and returns its length. The other callbacks are called 3457 * in the same way as they are in `nghttp2_session_send()`. 3458 * 3459 * If no data is available to send, this function returns 0. 3460 * 3461 * This function may not return all serialized data in one invocation. 3462 * To get all data, call this function repeatedly until it returns 0 3463 * or one of negative error codes. 3464 * 3465 * The assigned |*data_ptr| is valid until the next call of 3466 * `nghttp2_session_mem_send()` or `nghttp2_session_send()`. 3467 * 3468 * The caller must send all data before sending the next chunk of 3469 * data. 3470 * 3471 * This function returns the length of the data pointed by the 3472 * |*data_ptr| if it succeeds, or one of the following negative error 3473 * codes: 3474 * 3475 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3476 * Out of memory. 3477 * 3478 * .. note:: 3479 * 3480 * This function may produce very small byte string. If that is the 3481 * case, and application disables Nagle algorithm (``TCP_NODELAY``), 3482 * then writing this small chunk leads to very small packet, and it 3483 * is very inefficient. An application should be responsible to 3484 * buffer up small chunks of data as necessary to avoid this 3485 * situation. 3486 */ 3487 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session, 3488 const uint8_t **data_ptr); 3489 3490 #endif /* NGHTTP2_NO_SSIZE_T */ 3491 3492 /** 3493 * @function 3494 * 3495 * Returns the serialized data to send. 3496 * 3497 * This function behaves like `nghttp2_session_send()` except that it 3498 * does not use :type:`nghttp2_send_callback2` to transmit data. 3499 * Instead, it assigns the pointer to the serialized data to the 3500 * |*data_ptr| and returns its length. The other callbacks are called 3501 * in the same way as they are in `nghttp2_session_send()`. 3502 * 3503 * If no data is available to send, this function returns 0. 3504 * 3505 * This function may not return all serialized data in one invocation. 3506 * To get all data, call this function repeatedly until it returns 0 3507 * or one of negative error codes. 3508 * 3509 * The assigned |*data_ptr| is valid until the next call of 3510 * `nghttp2_session_mem_send2()` or `nghttp2_session_send()`. 3511 * 3512 * The caller must send all data before sending the next chunk of 3513 * data. 3514 * 3515 * This function returns the length of the data pointed by the 3516 * |*data_ptr| if it succeeds, or one of the following negative error 3517 * codes: 3518 * 3519 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3520 * Out of memory. 3521 * 3522 * .. note:: 3523 * 3524 * This function may produce very small byte string. If that is the 3525 * case, and application disables Nagle algorithm (``TCP_NODELAY``), 3526 * then writing this small chunk leads to very small packet, and it 3527 * is very inefficient. An application should be responsible to 3528 * buffer up small chunks of data as necessary to avoid this 3529 * situation. 3530 */ 3531 NGHTTP2_EXTERN nghttp2_ssize 3532 nghttp2_session_mem_send2(nghttp2_session *session, const uint8_t **data_ptr); 3533 3534 /** 3535 * @function 3536 * 3537 * Receives frames from the remote peer. 3538 * 3539 * This function receives as many frames as possible until the user 3540 * callback :type:`nghttp2_recv_callback` returns 3541 * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. This function calls 3542 * several callback functions which are passed when initializing the 3543 * |session|. Here is the simple time chart which tells when each 3544 * callback is invoked: 3545 * 3546 * 1. :type:`nghttp2_recv_callback` is invoked one or more times to 3547 * receive frame header. 3548 * 3549 * 2. When frame header is received, 3550 * :type:`nghttp2_on_begin_frame_callback` is invoked. 3551 * 3552 * 3. If the frame is DATA frame: 3553 * 3554 * 1. :type:`nghttp2_recv_callback` is invoked to receive DATA 3555 * payload. For each chunk of data, 3556 * :type:`nghttp2_on_data_chunk_recv_callback` is invoked. 3557 * 3558 * 2. If one DATA frame is completely received, 3559 * :type:`nghttp2_on_frame_recv_callback` is invoked. If the 3560 * reception of the frame triggers the closure of the stream, 3561 * :type:`nghttp2_on_stream_close_callback` is invoked. 3562 * 3563 * 4. If the frame is the control frame: 3564 * 3565 * 1. :type:`nghttp2_recv_callback` is invoked one or more times to 3566 * receive whole frame. 3567 * 3568 * 2. If the received frame is valid, then following actions are 3569 * taken. If the frame is either HEADERS or PUSH_PROMISE, 3570 * :type:`nghttp2_on_begin_headers_callback` is invoked. Then 3571 * :type:`nghttp2_on_header_callback` is invoked for each header 3572 * name/value pair. For invalid header field, 3573 * :type:`nghttp2_on_invalid_header_callback` is called. After 3574 * all name/value pairs are emitted successfully, 3575 * :type:`nghttp2_on_frame_recv_callback` is invoked. For other 3576 * frames, :type:`nghttp2_on_frame_recv_callback` is invoked. 3577 * If the reception of the frame triggers the closure of the 3578 * stream, :type:`nghttp2_on_stream_close_callback` is invoked. 3579 * 3580 * 3. If the received frame is unpacked but is interpreted as 3581 * invalid, :type:`nghttp2_on_invalid_frame_recv_callback` is 3582 * invoked. 3583 * 3584 * This function returns 0 if it succeeds, or one of the following 3585 * negative error codes: 3586 * 3587 * :enum:`nghttp2_error.NGHTTP2_ERR_EOF` 3588 * The remote peer did shutdown on the connection. 3589 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3590 * Out of memory. 3591 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` 3592 * The callback function failed. 3593 * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC` 3594 * Invalid client magic was detected. This error only returns 3595 * when |session| was configured as server and 3596 * `nghttp2_option_set_no_recv_client_magic()` is not used with 3597 * nonzero value. 3598 * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED` 3599 * Flooding was detected in this HTTP/2 session, and it must be 3600 * closed. This is most likely caused by misbehaviour of peer. 3601 */ 3602 NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session); 3603 3604 #ifndef NGHTTP2_NO_SSIZE_T 3605 /** 3606 * @function 3607 * 3608 * .. warning:: 3609 * 3610 * Deprecated. Use `nghttp2_session_mem_recv2()` instead. 3611 * 3612 * Processes data |in| as an input from the remote endpoint. The 3613 * |inlen| indicates the number of bytes to receive in the |in|. 3614 * 3615 * This function behaves like `nghttp2_session_recv()` except that it 3616 * does not use :type:`nghttp2_recv_callback` to receive data; the 3617 * |in| is the only data for the invocation of this function. If all 3618 * bytes are processed, this function returns. The other callbacks 3619 * are called in the same way as they are in `nghttp2_session_recv()`. 3620 * 3621 * In the current implementation, this function always tries to 3622 * processes |inlen| bytes of input data unless either an error occurs or 3623 * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from 3624 * :type:`nghttp2_on_header_callback` or 3625 * :type:`nghttp2_on_data_chunk_recv_callback`. If 3626 * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value 3627 * includes the number of bytes which was used to produce the data or 3628 * frame for the callback. 3629 * 3630 * This function returns the number of processed bytes, or one of the 3631 * following negative error codes: 3632 * 3633 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3634 * Out of memory. 3635 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` 3636 * The callback function failed. 3637 * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC` 3638 * Invalid client magic was detected. This error only returns 3639 * when |session| was configured as server and 3640 * `nghttp2_option_set_no_recv_client_magic()` is not used with 3641 * nonzero value. 3642 * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED` 3643 * Flooding was detected in this HTTP/2 session, and it must be 3644 * closed. This is most likely caused by misbehaviour of peer. 3645 */ 3646 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session, 3647 const uint8_t *in, 3648 size_t inlen); 3649 3650 #endif /* NGHTTP2_NO_SSIZE_T */ 3651 3652 /** 3653 * @function 3654 * 3655 * Processes data |in| as an input from the remote endpoint. The 3656 * |inlen| indicates the number of bytes to receive in the |in|. 3657 * 3658 * This function behaves like `nghttp2_session_recv()` except that it 3659 * does not use :type:`nghttp2_recv_callback` to receive data; the 3660 * |in| is the only data for the invocation of this function. If all 3661 * bytes are processed, this function returns. The other callbacks 3662 * are called in the same way as they are in `nghttp2_session_recv()`. 3663 * 3664 * In the current implementation, this function always tries to 3665 * processes |inlen| bytes of input data unless either an error occurs or 3666 * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from 3667 * :type:`nghttp2_on_header_callback` or 3668 * :type:`nghttp2_on_data_chunk_recv_callback`. If 3669 * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value 3670 * includes the number of bytes which was used to produce the data or 3671 * frame for the callback. 3672 * 3673 * This function returns the number of processed bytes, or one of the 3674 * following negative error codes: 3675 * 3676 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3677 * Out of memory. 3678 * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` 3679 * The callback function failed. 3680 * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC` 3681 * Invalid client magic was detected. This error only returns 3682 * when |session| was configured as server and 3683 * `nghttp2_option_set_no_recv_client_magic()` is not used with 3684 * nonzero value. 3685 * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED` 3686 * Flooding was detected in this HTTP/2 session, and it must be 3687 * closed. This is most likely caused by misbehaviour of peer. 3688 */ 3689 NGHTTP2_EXTERN nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, 3690 const uint8_t *in, 3691 size_t inlen); 3692 3693 /** 3694 * @function 3695 * 3696 * Puts back previously deferred DATA frame in the stream |stream_id| 3697 * to the outbound queue. 3698 * 3699 * This function returns 0 if it succeeds, or one of the following 3700 * negative error codes: 3701 * 3702 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 3703 * The stream does not exist; or no deferred data exist. 3704 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3705 * Out of memory. 3706 */ 3707 NGHTTP2_EXTERN int nghttp2_session_resume_data(nghttp2_session *session, 3708 int32_t stream_id); 3709 3710 /** 3711 * @function 3712 * 3713 * Returns nonzero value if |session| wants to receive data from the 3714 * remote peer. 3715 * 3716 * If both `nghttp2_session_want_read()` and 3717 * `nghttp2_session_want_write()` return 0, the application should 3718 * drop the connection. 3719 */ 3720 NGHTTP2_EXTERN int nghttp2_session_want_read(nghttp2_session *session); 3721 3722 /** 3723 * @function 3724 * 3725 * Returns nonzero value if |session| wants to send data to the remote 3726 * peer. 3727 * 3728 * If both `nghttp2_session_want_read()` and 3729 * `nghttp2_session_want_write()` return 0, the application should 3730 * drop the connection. 3731 */ 3732 NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session); 3733 3734 /** 3735 * @function 3736 * 3737 * Returns stream_user_data for the stream |stream_id|. The 3738 * stream_user_data is provided by `nghttp2_submit_request2()`, 3739 * `nghttp2_submit_headers()` or 3740 * `nghttp2_session_set_stream_user_data()`. Unless it is set using 3741 * `nghttp2_session_set_stream_user_data()`, if the stream is 3742 * initiated by the remote endpoint, stream_user_data is always 3743 * ``NULL``. If the stream does not exist, this function returns 3744 * ``NULL``. 3745 */ 3746 NGHTTP2_EXTERN void * 3747 nghttp2_session_get_stream_user_data(nghttp2_session *session, 3748 int32_t stream_id); 3749 3750 /** 3751 * @function 3752 * 3753 * Sets the |stream_user_data| to the stream denoted by the 3754 * |stream_id|. If a stream user data is already set to the stream, 3755 * it is replaced with the |stream_user_data|. It is valid to specify 3756 * ``NULL`` in the |stream_user_data|, which nullifies the associated 3757 * data pointer. 3758 * 3759 * It is valid to set the |stream_user_data| to the stream reserved by 3760 * PUSH_PROMISE frame. 3761 * 3762 * This function returns 0 if it succeeds, or one of following 3763 * negative error codes: 3764 * 3765 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 3766 * The stream does not exist 3767 */ 3768 NGHTTP2_EXTERN int 3769 nghttp2_session_set_stream_user_data(nghttp2_session *session, 3770 int32_t stream_id, void *stream_user_data); 3771 3772 /** 3773 * @function 3774 * 3775 * Sets |user_data| to |session|, overwriting the existing user data 3776 * specified in `nghttp2_session_client_new()`, or 3777 * `nghttp2_session_server_new()`. 3778 */ 3779 NGHTTP2_EXTERN void nghttp2_session_set_user_data(nghttp2_session *session, 3780 void *user_data); 3781 3782 /** 3783 * @function 3784 * 3785 * Returns the number of frames in the outbound queue. This does not 3786 * include the deferred DATA frames. 3787 */ 3788 NGHTTP2_EXTERN size_t 3789 nghttp2_session_get_outbound_queue_size(nghttp2_session *session); 3790 3791 /** 3792 * @function 3793 * 3794 * Returns the number of DATA payload in bytes received without 3795 * WINDOW_UPDATE transmission for the stream |stream_id|. The local 3796 * (receive) window size can be adjusted by 3797 * `nghttp2_submit_window_update()`. This function takes into account 3798 * that and returns effective data length. In particular, if the 3799 * local window size is reduced by submitting negative 3800 * window_size_increment with `nghttp2_submit_window_update()`, this 3801 * function returns the number of bytes less than actually received. 3802 * 3803 * This function returns -1 if it fails. 3804 */ 3805 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_recv_data_length( 3806 nghttp2_session *session, int32_t stream_id); 3807 3808 /** 3809 * @function 3810 * 3811 * Returns the local (receive) window size for the stream |stream_id|. 3812 * The local window size can be adjusted by 3813 * `nghttp2_submit_window_update()`. This function takes into account 3814 * that and returns effective window size. 3815 * 3816 * This function does not take into account the amount of received 3817 * data from the remote endpoint. Use 3818 * `nghttp2_session_get_stream_local_window_size()` to know the amount 3819 * of data the remote endpoint can send without receiving stream level 3820 * WINDOW_UPDATE frame. Note that each stream is still subject to the 3821 * connection level flow control. 3822 * 3823 * This function returns -1 if it fails. 3824 */ 3825 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_local_window_size( 3826 nghttp2_session *session, int32_t stream_id); 3827 3828 /** 3829 * @function 3830 * 3831 * Returns the amount of flow-controlled payload (e.g., DATA) that the 3832 * remote endpoint can send without receiving stream level 3833 * WINDOW_UPDATE frame. It is also subject to the connection level 3834 * flow control. So the actual amount of data to send is 3835 * min(`nghttp2_session_get_stream_local_window_size()`, 3836 * `nghttp2_session_get_local_window_size()`). 3837 * 3838 * This function returns -1 if it fails. 3839 */ 3840 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_local_window_size( 3841 nghttp2_session *session, int32_t stream_id); 3842 3843 /** 3844 * @function 3845 * 3846 * Returns the number of DATA payload in bytes received without 3847 * WINDOW_UPDATE transmission for a connection. The local (receive) 3848 * window size can be adjusted by `nghttp2_submit_window_update()`. 3849 * This function takes into account that and returns effective data 3850 * length. In particular, if the local window size is reduced by 3851 * submitting negative window_size_increment with 3852 * `nghttp2_submit_window_update()`, this function returns the number 3853 * of bytes less than actually received. 3854 * 3855 * This function returns -1 if it fails. 3856 */ 3857 NGHTTP2_EXTERN int32_t 3858 nghttp2_session_get_effective_recv_data_length(nghttp2_session *session); 3859 3860 /** 3861 * @function 3862 * 3863 * Returns the local (receive) window size for a connection. The 3864 * local window size can be adjusted by 3865 * `nghttp2_submit_window_update()`. This function takes into account 3866 * that and returns effective window size. 3867 * 3868 * This function does not take into account the amount of received 3869 * data from the remote endpoint. Use 3870 * `nghttp2_session_get_local_window_size()` to know the amount of 3871 * data the remote endpoint can send without receiving 3872 * connection-level WINDOW_UPDATE frame. Note that each stream is 3873 * still subject to the stream level flow control. 3874 * 3875 * This function returns -1 if it fails. 3876 */ 3877 NGHTTP2_EXTERN int32_t 3878 nghttp2_session_get_effective_local_window_size(nghttp2_session *session); 3879 3880 /** 3881 * @function 3882 * 3883 * Returns the amount of flow-controlled payload (e.g., DATA) that the 3884 * remote endpoint can send without receiving connection level 3885 * WINDOW_UPDATE frame. Note that each stream is still subject to the 3886 * stream level flow control (see 3887 * `nghttp2_session_get_stream_local_window_size()`). 3888 * 3889 * This function returns -1 if it fails. 3890 */ 3891 NGHTTP2_EXTERN int32_t 3892 nghttp2_session_get_local_window_size(nghttp2_session *session); 3893 3894 /** 3895 * @function 3896 * 3897 * Returns the remote window size for a given stream |stream_id|. 3898 * 3899 * This is the amount of flow-controlled payload (e.g., DATA) that the 3900 * local endpoint can send without stream level WINDOW_UPDATE. There 3901 * is also connection level flow control, so the effective size of 3902 * payload that the local endpoint can actually send is 3903 * min(`nghttp2_session_get_stream_remote_window_size()`, 3904 * `nghttp2_session_get_remote_window_size()`). 3905 * 3906 * This function returns -1 if it fails. 3907 */ 3908 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_remote_window_size( 3909 nghttp2_session *session, int32_t stream_id); 3910 3911 /** 3912 * @function 3913 * 3914 * Returns the remote window size for a connection. 3915 * 3916 * This function always succeeds. 3917 */ 3918 NGHTTP2_EXTERN int32_t 3919 nghttp2_session_get_remote_window_size(nghttp2_session *session); 3920 3921 /** 3922 * @function 3923 * 3924 * Returns 1 if local peer half closed the given stream |stream_id|. 3925 * Returns 0 if it did not. Returns -1 if no such stream exists. 3926 */ 3927 NGHTTP2_EXTERN int 3928 nghttp2_session_get_stream_local_close(nghttp2_session *session, 3929 int32_t stream_id); 3930 3931 /** 3932 * @function 3933 * 3934 * Returns 1 if remote peer half closed the given stream |stream_id|. 3935 * Returns 0 if it did not. Returns -1 if no such stream exists. 3936 */ 3937 NGHTTP2_EXTERN int 3938 nghttp2_session_get_stream_remote_close(nghttp2_session *session, 3939 int32_t stream_id); 3940 3941 /** 3942 * @function 3943 * 3944 * Returns the current dynamic table size of HPACK inflater, including 3945 * the overhead 32 bytes per entry described in RFC 7541. 3946 */ 3947 NGHTTP2_EXTERN size_t 3948 nghttp2_session_get_hd_inflate_dynamic_table_size(nghttp2_session *session); 3949 3950 /** 3951 * @function 3952 * 3953 * Returns the current dynamic table size of HPACK deflater including 3954 * the overhead 32 bytes per entry described in RFC 7541. 3955 */ 3956 NGHTTP2_EXTERN size_t 3957 nghttp2_session_get_hd_deflate_dynamic_table_size(nghttp2_session *session); 3958 3959 /** 3960 * @function 3961 * 3962 * Signals the session so that the connection should be terminated. 3963 * 3964 * The last stream ID is the minimum value between the stream ID of a 3965 * stream for which :type:`nghttp2_on_frame_recv_callback` was called 3966 * most recently and the last stream ID we have sent to the peer 3967 * previously. 3968 * 3969 * The |error_code| is the error code of this GOAWAY frame. The 3970 * pre-defined error code is one of :enum:`nghttp2_error_code`. 3971 * 3972 * After the transmission, both `nghttp2_session_want_read()` and 3973 * `nghttp2_session_want_write()` return 0. 3974 * 3975 * This function should be called when the connection should be 3976 * terminated after sending GOAWAY. If the remaining streams should 3977 * be processed after GOAWAY, use `nghttp2_submit_goaway()` instead. 3978 * 3979 * This function returns 0 if it succeeds, or one of the following 3980 * negative error codes: 3981 * 3982 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 3983 * Out of memory. 3984 */ 3985 NGHTTP2_EXTERN int nghttp2_session_terminate_session(nghttp2_session *session, 3986 uint32_t error_code); 3987 3988 /** 3989 * @function 3990 * 3991 * Signals the session so that the connection should be terminated. 3992 * 3993 * This function behaves like `nghttp2_session_terminate_session()`, 3994 * but the last stream ID can be specified by the application for fine 3995 * grained control of stream. The HTTP/2 specification does not allow 3996 * last_stream_id to be increased. So the actual value sent as 3997 * last_stream_id is the minimum value between the given 3998 * |last_stream_id| and the last_stream_id we have previously sent to 3999 * the peer. 4000 * 4001 * The |last_stream_id| is peer's stream ID or 0. So if |session| is 4002 * initialized as client, |last_stream_id| must be even or 0. If 4003 * |session| is initialized as server, |last_stream_id| must be odd or 4004 * 0. 4005 * 4006 * This function returns 0 if it succeeds, or one of the following 4007 * negative error codes: 4008 * 4009 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4010 * Out of memory. 4011 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4012 * The |last_stream_id| is invalid. 4013 */ 4014 NGHTTP2_EXTERN int nghttp2_session_terminate_session2(nghttp2_session *session, 4015 int32_t last_stream_id, 4016 uint32_t error_code); 4017 4018 /** 4019 * @function 4020 * 4021 * Signals to the client that the server started graceful shutdown 4022 * procedure. 4023 * 4024 * This function is only usable for server. If this function is 4025 * called with client side session, this function returns 4026 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. 4027 * 4028 * To gracefully shutdown HTTP/2 session, server should call this 4029 * function to send GOAWAY with last_stream_id (1u << 31) - 1. And 4030 * after some delay (e.g., 1 RTT), send another GOAWAY with the stream 4031 * ID that the server has some processing using 4032 * `nghttp2_submit_goaway()`. See also 4033 * `nghttp2_session_get_last_proc_stream_id()`. 4034 * 4035 * Unlike `nghttp2_submit_goaway()`, this function just sends GOAWAY 4036 * and does nothing more. This is a mere indication to the client 4037 * that session shutdown is imminent. The application should call 4038 * `nghttp2_submit_goaway()` with appropriate last_stream_id after 4039 * this call. 4040 * 4041 * If one or more GOAWAY frame have been already sent by either 4042 * `nghttp2_submit_goaway()` or `nghttp2_session_terminate_session()`, 4043 * this function has no effect. 4044 * 4045 * This function returns 0 if it succeeds, or one of the following 4046 * negative error codes: 4047 * 4048 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4049 * Out of memory. 4050 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 4051 * The |session| is initialized as client. 4052 */ 4053 NGHTTP2_EXTERN int nghttp2_submit_shutdown_notice(nghttp2_session *session); 4054 4055 /** 4056 * @function 4057 * 4058 * Returns the value of SETTINGS |id| notified by a remote endpoint. 4059 * The |id| must be one of values defined in 4060 * :enum:`nghttp2_settings_id`. 4061 */ 4062 NGHTTP2_EXTERN uint32_t nghttp2_session_get_remote_settings( 4063 nghttp2_session *session, nghttp2_settings_id id); 4064 4065 /** 4066 * @function 4067 * 4068 * Returns the value of SETTINGS |id| of local endpoint acknowledged 4069 * by the remote endpoint. The |id| must be one of the values defined 4070 * in :enum:`nghttp2_settings_id`. 4071 */ 4072 NGHTTP2_EXTERN uint32_t nghttp2_session_get_local_settings( 4073 nghttp2_session *session, nghttp2_settings_id id); 4074 4075 /** 4076 * @function 4077 * 4078 * Tells the |session| that next stream ID is |next_stream_id|. The 4079 * |next_stream_id| must be equal or greater than the value returned 4080 * by `nghttp2_session_get_next_stream_id()`. 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_INVALID_ARGUMENT` 4086 * The |next_stream_id| is strictly less than the value 4087 * `nghttp2_session_get_next_stream_id()` returns; or 4088 * |next_stream_id| is invalid (e.g., even integer for client, or 4089 * odd integer for server). 4090 */ 4091 NGHTTP2_EXTERN int nghttp2_session_set_next_stream_id(nghttp2_session *session, 4092 int32_t next_stream_id); 4093 4094 /** 4095 * @function 4096 * 4097 * Returns the next outgoing stream ID. Notice that return type is 4098 * uint32_t. If we run out of stream ID for this session, this 4099 * function returns 1 << 31. 4100 */ 4101 NGHTTP2_EXTERN uint32_t 4102 nghttp2_session_get_next_stream_id(nghttp2_session *session); 4103 4104 /** 4105 * @function 4106 * 4107 * Tells the |session| that |size| bytes for a stream denoted by 4108 * |stream_id| were consumed by application and are ready to 4109 * WINDOW_UPDATE. The consumed bytes are counted towards both 4110 * connection and stream level WINDOW_UPDATE (see 4111 * `nghttp2_session_consume_connection()` and 4112 * `nghttp2_session_consume_stream()` to update consumption 4113 * independently). This function is intended to be used without 4114 * automatic window update (see 4115 * `nghttp2_option_set_no_auto_window_update()`). 4116 * 4117 * This function returns 0 if it succeeds, or one of the following 4118 * negative error codes: 4119 * 4120 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4121 * Out of memory. 4122 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4123 * The |stream_id| is 0. 4124 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 4125 * Automatic WINDOW_UPDATE is not disabled. 4126 */ 4127 NGHTTP2_EXTERN int nghttp2_session_consume(nghttp2_session *session, 4128 int32_t stream_id, size_t size); 4129 4130 /** 4131 * @function 4132 * 4133 * Like `nghttp2_session_consume()`, but this only tells library that 4134 * |size| bytes were consumed only for connection level. Note that 4135 * HTTP/2 maintains connection and stream level flow control windows 4136 * independently. 4137 * 4138 * This function returns 0 if it succeeds, or one of the following 4139 * negative error codes: 4140 * 4141 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4142 * Out of memory. 4143 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 4144 * Automatic WINDOW_UPDATE is not disabled. 4145 */ 4146 NGHTTP2_EXTERN int nghttp2_session_consume_connection(nghttp2_session *session, 4147 size_t size); 4148 4149 /** 4150 * @function 4151 * 4152 * Like `nghttp2_session_consume()`, but this only tells library that 4153 * |size| bytes were consumed only for stream denoted by |stream_id|. 4154 * Note that HTTP/2 maintains connection and stream level flow control 4155 * windows independently. 4156 * 4157 * This function returns 0 if it succeeds, or one of the following 4158 * negative error codes: 4159 * 4160 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4161 * Out of memory. 4162 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4163 * The |stream_id| is 0. 4164 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 4165 * Automatic WINDOW_UPDATE is not disabled. 4166 */ 4167 NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session, 4168 int32_t stream_id, 4169 size_t size); 4170 4171 /** 4172 * @function 4173 * 4174 * .. warning:: 4175 * 4176 * Deprecated. :rfc:`7540` priorities are deprecated by 4177 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4178 * prioritization scheme. In the future release after the end of 4179 * 2024, this function will always return 0 without doing anything. 4180 * 4181 * Changes priority of existing stream denoted by |stream_id|. The 4182 * new priority specification is |pri_spec|. 4183 * 4184 * The priority is changed silently and instantly, and no PRIORITY 4185 * frame will be sent to notify the peer of this change. This 4186 * function may be useful for server to change the priority of pushed 4187 * stream. 4188 * 4189 * If |session| is initialized as server, and ``pri_spec->stream_id`` 4190 * points to the idle stream, the idle stream is created if it does 4191 * not exist. The created idle stream will depend on root stream 4192 * (stream 0) with weight 16. 4193 * 4194 * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not 4195 * found, we use default priority instead of given |pri_spec|. That 4196 * is make stream depend on root stream with weight 16. 4197 * 4198 * If 4199 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 4200 * of value of 1 is submitted via `nghttp2_submit_settings()`, this 4201 * function does nothing and returns 0. 4202 * 4203 * This function returns 0 if it succeeds, or one of the following 4204 * negative error codes: 4205 * 4206 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4207 * Out of memory. 4208 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4209 * Attempted to depend on itself; or no stream exist for the given 4210 * |stream_id|; or |stream_id| is 0 4211 */ 4212 NGHTTP2_EXTERN int 4213 nghttp2_session_change_stream_priority(nghttp2_session *session, 4214 int32_t stream_id, 4215 const nghttp2_priority_spec *pri_spec); 4216 4217 /** 4218 * @function 4219 * 4220 * .. warning:: 4221 * 4222 * Deprecated. :rfc:`7540` priorities are deprecated by 4223 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4224 * prioritization scheme. In the future release after the end of 4225 * 2024, this function will always return 0 without doing anything. 4226 * 4227 * Creates idle stream with the given |stream_id|, and priority 4228 * |pri_spec|. 4229 * 4230 * The stream creation is done without sending PRIORITY frame, which 4231 * means that peer does not know about the existence of this idle 4232 * stream in the local endpoint. 4233 * 4234 * RFC 7540 does not disallow the use of creation of idle stream with 4235 * odd or even stream ID regardless of client or server. So this 4236 * function can create odd or even stream ID regardless of client or 4237 * server. But probably it is a bit safer to use the stream ID the 4238 * local endpoint can initiate (in other words, use odd stream ID for 4239 * client, and even stream ID for server), to avoid potential 4240 * collision from peer's instruction. Also we can use 4241 * `nghttp2_session_set_next_stream_id()` to avoid to open created 4242 * idle streams accidentally if we follow this recommendation. 4243 * 4244 * If |session| is initialized as server, and ``pri_spec->stream_id`` 4245 * points to the idle stream, the idle stream is created if it does 4246 * not exist. The created idle stream will depend on root stream 4247 * (stream 0) with weight 16. 4248 * 4249 * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not 4250 * found, we use default priority instead of given |pri_spec|. That 4251 * is make stream depend on root stream with weight 16. 4252 * 4253 * If 4254 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 4255 * of value of 1 is submitted via `nghttp2_submit_settings()`, this 4256 * function does nothing and returns 0. 4257 * 4258 * This function returns 0 if it succeeds, or one of the following 4259 * negative error codes: 4260 * 4261 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4262 * Out of memory. 4263 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4264 * Attempted to depend on itself; or stream denoted by |stream_id| 4265 * already exists; or |stream_id| cannot be used to create idle 4266 * stream (in other words, local endpoint has already opened 4267 * stream ID greater than or equal to the given stream ID; or 4268 * |stream_id| is 0 4269 */ 4270 NGHTTP2_EXTERN int 4271 nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id, 4272 const nghttp2_priority_spec *pri_spec); 4273 4274 /** 4275 * @function 4276 * 4277 * .. warning:: 4278 * 4279 * This function is deprecated in favor of 4280 * `nghttp2_session_upgrade2()`, because this function lacks the 4281 * parameter to tell the library the request method used in the 4282 * original HTTP request. This information is required for client 4283 * to validate actual response body length against content-length 4284 * header field (see `nghttp2_option_set_no_http_messaging()`). If 4285 * HEAD is used in request, the length of response body must be 0 4286 * regardless of value included in content-length header field. 4287 * 4288 * Performs post-process of HTTP Upgrade request. This function can 4289 * be called from both client and server, but the behavior is very 4290 * different in each other. 4291 * 4292 * If called from client side, the |settings_payload| must be the 4293 * value sent in ``HTTP2-Settings`` header field and must be decoded 4294 * by base64url decoder. The |settings_payloadlen| is the length of 4295 * |settings_payload|. The |settings_payload| is unpacked and its 4296 * setting values will be submitted using `nghttp2_submit_settings()`. 4297 * This means that the client application code does not need to submit 4298 * SETTINGS by itself. The stream with stream ID=1 is opened and the 4299 * |stream_user_data| is used for its stream_user_data. The opened 4300 * stream becomes half-closed (local) state. 4301 * 4302 * If called from server side, the |settings_payload| must be the 4303 * value received in ``HTTP2-Settings`` header field and must be 4304 * decoded by base64url decoder. The |settings_payloadlen| is the 4305 * length of |settings_payload|. It is treated as if the SETTINGS 4306 * frame with that payload is received. Thus, callback functions for 4307 * the reception of SETTINGS frame will be invoked. The stream with 4308 * stream ID=1 is opened. The |stream_user_data| is ignored. The 4309 * opened stream becomes half-closed (remote). 4310 * 4311 * This function returns 0 if it succeeds, or one of the following 4312 * negative error codes: 4313 * 4314 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4315 * Out of memory. 4316 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4317 * The |settings_payload| is badly formed. 4318 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4319 * The stream ID 1 is already used or closed; or is not available. 4320 */ 4321 NGHTTP2_EXTERN int nghttp2_session_upgrade(nghttp2_session *session, 4322 const uint8_t *settings_payload, 4323 size_t settings_payloadlen, 4324 void *stream_user_data); 4325 4326 /** 4327 * @function 4328 * 4329 * Performs post-process of HTTP Upgrade request. This function can 4330 * be called from both client and server, but the behavior is very 4331 * different in each other. 4332 * 4333 * If called from client side, the |settings_payload| must be the 4334 * value sent in ``HTTP2-Settings`` header field and must be decoded 4335 * by base64url decoder. The |settings_payloadlen| is the length of 4336 * |settings_payload|. The |settings_payload| is unpacked and its 4337 * setting values will be submitted using `nghttp2_submit_settings()`. 4338 * This means that the client application code does not need to submit 4339 * SETTINGS by itself. The stream with stream ID=1 is opened and the 4340 * |stream_user_data| is used for its stream_user_data. The opened 4341 * stream becomes half-closed (local) state. 4342 * 4343 * If called from server side, the |settings_payload| must be the 4344 * value received in ``HTTP2-Settings`` header field and must be 4345 * decoded by base64url decoder. The |settings_payloadlen| is the 4346 * length of |settings_payload|. It is treated as if the SETTINGS 4347 * frame with that payload is received. Thus, callback functions for 4348 * the reception of SETTINGS frame will be invoked. The stream with 4349 * stream ID=1 is opened. The |stream_user_data| is ignored. The 4350 * opened stream becomes half-closed (remote). 4351 * 4352 * If the request method is HEAD, pass nonzero value to 4353 * |head_request|. Otherwise, pass 0. 4354 * 4355 * This function returns 0 if it succeeds, or one of the following 4356 * negative error codes: 4357 * 4358 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4359 * Out of memory. 4360 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4361 * The |settings_payload| is badly formed. 4362 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4363 * The stream ID 1 is already used or closed; or is not available. 4364 */ 4365 NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session, 4366 const uint8_t *settings_payload, 4367 size_t settings_payloadlen, 4368 int head_request, 4369 void *stream_user_data); 4370 4371 #ifndef NGHTTP2_NO_SSIZE_T 4372 /** 4373 * @function 4374 * 4375 * .. warning:: 4376 * 4377 * Deprecated. Use `nghttp2_pack_settings_payload2()` instead. 4378 * 4379 * Serializes the SETTINGS values |iv| in the |buf|. The size of the 4380 * |buf| is specified by |buflen|. The number of entries in the |iv| 4381 * array is given by |niv|. The required space in |buf| for the |niv| 4382 * entries is ``6*niv`` bytes and if the given buffer is too small, an 4383 * error is returned. This function is used mainly for creating a 4384 * SETTINGS payload to be sent with the ``HTTP2-Settings`` header 4385 * field in an HTTP Upgrade request. The data written in |buf| is NOT 4386 * base64url encoded and the application is responsible for encoding. 4387 * 4388 * This function returns the number of bytes written in |buf|, or one 4389 * of the following negative error codes: 4390 * 4391 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4392 * The |iv| contains duplicate settings ID or invalid value. 4393 * 4394 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 4395 * The provided |buflen| size is too small to hold the output. 4396 */ 4397 NGHTTP2_EXTERN ssize_t nghttp2_pack_settings_payload( 4398 uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv); 4399 4400 #endif /* NGHTTP2_NO_SSIZE_T */ 4401 4402 /** 4403 * @function 4404 * 4405 * Serializes the SETTINGS values |iv| in the |buf|. The size of the 4406 * |buf| is specified by |buflen|. The number of entries in the |iv| 4407 * array is given by |niv|. The required space in |buf| for the |niv| 4408 * entries is ``6*niv`` bytes and if the given buffer is too small, an 4409 * error is returned. This function is used mainly for creating a 4410 * SETTINGS payload to be sent with the ``HTTP2-Settings`` header 4411 * field in an HTTP Upgrade request. The data written in |buf| is NOT 4412 * base64url encoded and the application is responsible for encoding. 4413 * 4414 * This function returns the number of bytes written in |buf|, or one 4415 * of the following negative error codes: 4416 * 4417 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4418 * The |iv| contains duplicate settings ID or invalid value. 4419 * 4420 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 4421 * The provided |buflen| size is too small to hold the output. 4422 */ 4423 NGHTTP2_EXTERN nghttp2_ssize nghttp2_pack_settings_payload2( 4424 uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv); 4425 4426 /** 4427 * @function 4428 * 4429 * Returns string describing the |lib_error_code|. The 4430 * |lib_error_code| must be one of the :enum:`nghttp2_error`. 4431 */ 4432 NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code); 4433 4434 /** 4435 * @function 4436 * 4437 * Returns string representation of HTTP/2 error code |error_code| 4438 * (e.g., ``PROTOCOL_ERROR`` is returned if ``error_code == 4439 * NGHTTP2_PROTOCOL_ERROR``). If string representation is unknown for 4440 * given |error_code|, this function returns string ``unknown``. 4441 */ 4442 NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code); 4443 4444 /** 4445 * @function 4446 * 4447 * .. warning:: 4448 * 4449 * Deprecated. :rfc:`7540` priorities are deprecated by 4450 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4451 * prioritization scheme. 4452 * 4453 * Initializes |pri_spec| with the |stream_id| of the stream to depend 4454 * on with |weight| and its exclusive flag. If |exclusive| is 4455 * nonzero, exclusive flag is set. 4456 * 4457 * The |weight| must be in [:macro:`NGHTTP2_MIN_WEIGHT`, 4458 * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. 4459 */ 4460 NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec, 4461 int32_t stream_id, 4462 int32_t weight, int exclusive); 4463 4464 /** 4465 * @function 4466 * 4467 * .. warning:: 4468 * 4469 * Deprecated. :rfc:`7540` priorities are deprecated by 4470 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4471 * prioritization scheme. 4472 * 4473 * Initializes |pri_spec| with the default values. The default values 4474 * are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and 4475 * exclusive = 0. 4476 */ 4477 NGHTTP2_EXTERN void 4478 nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec); 4479 4480 /** 4481 * @function 4482 * 4483 * .. warning:: 4484 * 4485 * Deprecated. :rfc:`7540` priorities are deprecated by 4486 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 4487 * prioritization scheme. 4488 * 4489 * Returns nonzero if the |pri_spec| is filled with default values. 4490 */ 4491 NGHTTP2_EXTERN int 4492 nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec); 4493 4494 #ifndef NGHTTP2_NO_SSIZE_T 4495 /** 4496 * @function 4497 * 4498 * .. warning:: 4499 * 4500 * Deprecated. Use `nghttp2_submit_request2()` instead. 4501 * 4502 * Submits HEADERS frame and optionally one or more DATA frames. 4503 * 4504 * The |pri_spec| is a deprecated priority specification of this 4505 * request. ``NULL`` means the default priority (see 4506 * `nghttp2_priority_spec_default_init()`). To specify the priority, 4507 * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, 4508 * this function will copy its data members. 4509 * 4510 * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, 4511 * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` 4512 * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes 4513 * :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than 4514 * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes 4515 * :macro:`NGHTTP2_MAX_WEIGHT`. 4516 * 4517 * If 4518 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 4519 * of value of 1 is received by a remote endpoint, |pri_spec| is 4520 * ignored, and treated as if ``NULL`` is specified. 4521 * 4522 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4523 * |nvlen| elements. The application is responsible to include 4524 * required pseudo-header fields (header field whose name starts with 4525 * ":") in |nva| and must place pseudo-headers before regular header 4526 * fields. 4527 * 4528 * This function creates copies of all name/value pairs in |nva|. It 4529 * also lower-cases all names in |nva|. The order of elements in 4530 * |nva| is preserved. For header fields with 4531 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 4532 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 4533 * header field name and value are not copied respectively. With 4534 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 4535 * is responsible to pass header field name in lowercase. The 4536 * application should maintain the references to them until 4537 * :type:`nghttp2_on_frame_send_callback` or 4538 * :type:`nghttp2_on_frame_not_send_callback` is called. 4539 * 4540 * HTTP/2 specification has requirement about header fields in the 4541 * request HEADERS. See the specification for more details. 4542 * 4543 * If |data_prd| is not ``NULL``, it provides data which will be sent 4544 * in subsequent DATA frames. In this case, a method that allows 4545 * request message bodies 4546 * (https://tools.ietf.org/html/rfc7231#section-4) must be specified 4547 * with ``:method`` key in |nva| (e.g. ``POST``). This function does 4548 * not take ownership of the |data_prd|. The function copies the 4549 * members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have 4550 * END_STREAM set. The |stream_user_data| is data associated to the 4551 * stream opened by this request and can be an arbitrary pointer, 4552 * which can be retrieved later by 4553 * `nghttp2_session_get_stream_user_data()`. 4554 * 4555 * This function returns assigned stream ID if it succeeds, or one of 4556 * the following negative error codes: 4557 * 4558 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4559 * Out of memory. 4560 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` 4561 * No stream ID is available because maximum stream ID was 4562 * reached. 4563 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4564 * Trying to depend on itself (new stream ID equals 4565 * ``pri_spec->stream_id``). 4566 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4567 * The |session| is server session. 4568 * 4569 * .. warning:: 4570 * 4571 * This function returns assigned stream ID if it succeeds. But 4572 * that stream is not created yet. The application must not submit 4573 * frame to that stream ID before 4574 * :type:`nghttp2_before_frame_send_callback` is called for this 4575 * frame. This means `nghttp2_session_get_stream_user_data()` does 4576 * not work before the callback. But 4577 * `nghttp2_session_set_stream_user_data()` handles this situation 4578 * specially, and it can set data to a stream during this period. 4579 * 4580 */ 4581 NGHTTP2_EXTERN int32_t nghttp2_submit_request( 4582 nghttp2_session *session, const nghttp2_priority_spec *pri_spec, 4583 const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd, 4584 void *stream_user_data); 4585 4586 #endif /* NGHTTP2_NO_SSIZE_T */ 4587 4588 /** 4589 * @function 4590 * 4591 * Submits HEADERS frame and optionally one or more DATA frames. 4592 * 4593 * The |pri_spec| is a deprecated priority specification of this 4594 * request. ``NULL`` means the default priority (see 4595 * `nghttp2_priority_spec_default_init()`). To specify the priority, 4596 * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, 4597 * this function will copy its data members. In the future release 4598 * after the end of 2024, this function will ignore |pri_spec| and 4599 * behave as if ``NULL`` is given. 4600 * 4601 * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, 4602 * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` 4603 * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes 4604 * :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than 4605 * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes 4606 * :macro:`NGHTTP2_MAX_WEIGHT`. 4607 * 4608 * If 4609 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 4610 * of value of 1 is received by a remote endpoint, |pri_spec| is 4611 * ignored, and treated as if ``NULL`` is specified. 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 * request 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. In this case, a method that allows 4636 * request message bodies 4637 * (https://tools.ietf.org/html/rfc7231#section-4) must be specified 4638 * with ``:method`` key in |nva| (e.g. ``POST``). This function does 4639 * not take ownership of the |data_prd|. The function copies the 4640 * members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have 4641 * END_STREAM set. The |stream_user_data| is data associated to the 4642 * stream opened by this request and can be an arbitrary pointer, 4643 * which can be retrieved later by 4644 * `nghttp2_session_get_stream_user_data()`. 4645 * 4646 * This function returns assigned stream ID if it succeeds, or one of 4647 * the following negative error codes: 4648 * 4649 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4650 * Out of memory. 4651 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` 4652 * No stream ID is available because maximum stream ID was 4653 * reached. 4654 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4655 * Trying to depend on itself (new stream ID equals 4656 * ``pri_spec->stream_id``). 4657 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4658 * The |session| is server session. 4659 * 4660 * .. warning:: 4661 * 4662 * This function returns assigned stream ID if it succeeds. But 4663 * that stream is not created yet. The application must not submit 4664 * frame to that stream ID before 4665 * :type:`nghttp2_before_frame_send_callback` is called for this 4666 * frame. This means `nghttp2_session_get_stream_user_data()` does 4667 * not work before the callback. But 4668 * `nghttp2_session_set_stream_user_data()` handles this situation 4669 * specially, and it can set data to a stream during this period. 4670 * 4671 */ 4672 NGHTTP2_EXTERN int32_t nghttp2_submit_request2( 4673 nghttp2_session *session, const nghttp2_priority_spec *pri_spec, 4674 const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider2 *data_prd, 4675 void *stream_user_data); 4676 4677 #ifndef NGHTTP2_NO_SSIZE_T 4678 /** 4679 * @function 4680 * 4681 * .. warning:: 4682 * 4683 * Deprecated. Use `nghttp2_submit_response2()` instead. 4684 * 4685 * Submits response HEADERS frame and optionally one or more DATA 4686 * frames against the stream |stream_id|. 4687 * 4688 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4689 * |nvlen| elements. The application is responsible to include 4690 * required pseudo-header fields (header field whose name starts with 4691 * ":") in |nva| and must place pseudo-headers before regular header 4692 * fields. 4693 * 4694 * This function creates copies of all name/value pairs in |nva|. It 4695 * also lower-cases all names in |nva|. The order of elements in 4696 * |nva| is preserved. For header fields with 4697 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 4698 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 4699 * header field name and value are not copied respectively. With 4700 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 4701 * is responsible to pass header field name in lowercase. The 4702 * application should maintain the references to them until 4703 * :type:`nghttp2_on_frame_send_callback` or 4704 * :type:`nghttp2_on_frame_not_send_callback` is called. 4705 * 4706 * HTTP/2 specification has requirement about header fields in the 4707 * response HEADERS. See the specification for more details. 4708 * 4709 * If |data_prd| is not ``NULL``, it provides data which will be sent 4710 * in subsequent DATA frames. This function does not take ownership 4711 * of the |data_prd|. The function copies the members of the 4712 * |data_prd|. If |data_prd| is ``NULL``, HEADERS will have 4713 * END_STREAM flag set. 4714 * 4715 * This method can be used as normal HTTP response and push response. 4716 * When pushing a resource using this function, the |session| must be 4717 * configured using `nghttp2_session_server_new()` or its variants and 4718 * the target stream denoted by the |stream_id| must be reserved using 4719 * `nghttp2_submit_push_promise()`. 4720 * 4721 * To send non-final response headers (e.g., HTTP status 101), don't 4722 * use this function because this function half-closes the outbound 4723 * stream. Instead, use `nghttp2_submit_headers()` for this purpose. 4724 * 4725 * This function returns 0 if it succeeds, or one of the following 4726 * negative error codes: 4727 * 4728 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4729 * Out of memory. 4730 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4731 * The |stream_id| is 0. 4732 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` 4733 * DATA or HEADERS has been already submitted and not fully 4734 * processed yet. Normally, this does not happen, but when 4735 * application wrongly calls `nghttp2_submit_response()` twice, 4736 * this may happen. 4737 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4738 * The |session| is client session. 4739 * 4740 * .. warning:: 4741 * 4742 * Calling this function twice for the same stream ID may lead to 4743 * program crash. It is generally considered to a programming error 4744 * to commit response twice. 4745 */ 4746 NGHTTP2_EXTERN int 4747 nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, 4748 const nghttp2_nv *nva, size_t nvlen, 4749 const nghttp2_data_provider *data_prd); 4750 4751 #endif /* NGHTTP2_NO_SSIZE_T */ 4752 4753 /** 4754 * @function 4755 * 4756 * Submits response HEADERS frame and optionally one or more DATA 4757 * frames against the stream |stream_id|. 4758 * 4759 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4760 * |nvlen| elements. The application is responsible to include 4761 * required pseudo-header fields (header field whose name starts with 4762 * ":") in |nva| and must place pseudo-headers before regular header 4763 * fields. 4764 * 4765 * This function creates copies of all name/value pairs in |nva|. It 4766 * also lower-cases all names in |nva|. The order of elements in 4767 * |nva| is preserved. For header fields with 4768 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 4769 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 4770 * header field name and value are not copied respectively. With 4771 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 4772 * is responsible to pass header field name in lowercase. The 4773 * application should maintain the references to them until 4774 * :type:`nghttp2_on_frame_send_callback` or 4775 * :type:`nghttp2_on_frame_not_send_callback` is called. 4776 * 4777 * HTTP/2 specification has requirement about header fields in the 4778 * response HEADERS. See the specification for more details. 4779 * 4780 * If |data_prd| is not ``NULL``, it provides data which will be sent 4781 * in subsequent DATA frames. This function does not take ownership 4782 * of the |data_prd|. The function copies the members of the 4783 * |data_prd|. If |data_prd| is ``NULL``, HEADERS will have 4784 * END_STREAM flag set. 4785 * 4786 * This method can be used as normal HTTP response and push response. 4787 * When pushing a resource using this function, the |session| must be 4788 * configured using `nghttp2_session_server_new()` or its variants and 4789 * the target stream denoted by the |stream_id| must be reserved using 4790 * `nghttp2_submit_push_promise()`. 4791 * 4792 * To send non-final response headers (e.g., HTTP status 101), don't 4793 * use this function because this function half-closes the outbound 4794 * stream. Instead, use `nghttp2_submit_headers()` for this purpose. 4795 * 4796 * This function returns 0 if it succeeds, or one of the following 4797 * negative error codes: 4798 * 4799 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4800 * Out of memory. 4801 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4802 * The |stream_id| is 0. 4803 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` 4804 * DATA or HEADERS has been already submitted and not fully 4805 * processed yet. Normally, this does not happen, but when 4806 * application wrongly calls `nghttp2_submit_response2()` twice, 4807 * this may happen. 4808 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4809 * The |session| is client session. 4810 * 4811 * .. warning:: 4812 * 4813 * Calling this function twice for the same stream ID may lead to 4814 * program crash. It is generally considered to a programming error 4815 * to commit response twice. 4816 */ 4817 NGHTTP2_EXTERN int 4818 nghttp2_submit_response2(nghttp2_session *session, int32_t stream_id, 4819 const nghttp2_nv *nva, size_t nvlen, 4820 const nghttp2_data_provider2 *data_prd); 4821 4822 /** 4823 * @function 4824 * 4825 * Submits trailer fields HEADERS against the stream |stream_id|. 4826 * 4827 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4828 * |nvlen| elements. The application must not include pseudo-header 4829 * fields (headers whose names starts with ":") in |nva|. 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 * For server, trailer fields must follow response HEADERS or response 4844 * DATA without END_STREAM flat set. The library does not enforce 4845 * this requirement, and applications should do this for themselves. 4846 * If `nghttp2_submit_trailer()` is called before any response HEADERS 4847 * submission (usually by `nghttp2_submit_response2()`), the content 4848 * of |nva| will be sent as response headers, which will result in 4849 * error. 4850 * 4851 * This function has the same effect with `nghttp2_submit_headers()`, 4852 * with flags = :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` and both 4853 * pri_spec and stream_user_data to NULL. 4854 * 4855 * To submit trailer fields after `nghttp2_submit_response2()` is 4856 * called, the application has to specify 4857 * :type:`nghttp2_data_provider2` to `nghttp2_submit_response2()`. 4858 * Inside of :type:`nghttp2_data_source_read_callback2`, when setting 4859 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF`, also set 4860 * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM`. After 4861 * that, the application can send trailer fields using 4862 * `nghttp2_submit_trailer()`. `nghttp2_submit_trailer()` can be used 4863 * inside :type:`nghttp2_data_source_read_callback2`. 4864 * 4865 * This function returns 0 if it succeeds and |stream_id| is -1. 4866 * Otherwise, this function returns 0 if it succeeds, or one of the 4867 * following negative error codes: 4868 * 4869 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4870 * Out of memory. 4871 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4872 * The |stream_id| is 0. 4873 */ 4874 NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session, 4875 int32_t stream_id, 4876 const nghttp2_nv *nva, size_t nvlen); 4877 4878 /** 4879 * @function 4880 * 4881 * Submits HEADERS frame. The |flags| is bitwise OR of the 4882 * following values: 4883 * 4884 * * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` 4885 * 4886 * If |flags| includes :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, 4887 * this frame has END_STREAM flag set. 4888 * 4889 * The library handles the CONTINUATION frame internally and it 4890 * correctly sets END_HEADERS to the last sequence of the PUSH_PROMISE 4891 * or CONTINUATION frame. 4892 * 4893 * If the |stream_id| is -1, this frame is assumed as request (i.e., 4894 * request HEADERS frame which opens new stream). In this case, the 4895 * assigned stream ID will be returned. Otherwise, specify stream ID 4896 * in |stream_id|. 4897 * 4898 * The |pri_spec| is a deprecated priority specification of this 4899 * request. ``NULL`` means the default priority (see 4900 * `nghttp2_priority_spec_default_init()`). To specify the priority, 4901 * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, 4902 * this function will copy its data members. In the future release 4903 * after the end of 2024, this function will ignore |pri_spec| and 4904 * behave as if ``NULL`` is given. 4905 * 4906 * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, 4907 * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` 4908 * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes 4909 * :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than 4910 * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes :macro:`NGHTTP2_MAX_WEIGHT`. 4911 * 4912 * If 4913 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 4914 * of value of 1 is received by a remote endpoint, |pri_spec| is 4915 * ignored, and treated as if ``NULL`` is specified. 4916 * 4917 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 4918 * |nvlen| elements. The application is responsible to include 4919 * required pseudo-header fields (header field whose name starts with 4920 * ":") in |nva| and must place pseudo-headers before regular header 4921 * fields. 4922 * 4923 * This function creates copies of all name/value pairs in |nva|. It 4924 * also lower-cases all names in |nva|. The order of elements in 4925 * |nva| is preserved. For header fields with 4926 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 4927 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 4928 * header field name and value are not copied respectively. With 4929 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 4930 * is responsible to pass header field name in lowercase. The 4931 * application should maintain the references to them until 4932 * :type:`nghttp2_on_frame_send_callback` or 4933 * :type:`nghttp2_on_frame_not_send_callback` is called. 4934 * 4935 * The |stream_user_data| is a pointer to an arbitrary data which is 4936 * associated to the stream this frame will open. Therefore it is 4937 * only used if this frame opens streams, in other words, it changes 4938 * stream state from idle or reserved to open. 4939 * 4940 * This function is low-level in a sense that the application code can 4941 * specify flags directly. For usual HTTP request, 4942 * `nghttp2_submit_request2()` is useful. Likewise, for HTTP 4943 * response, prefer `nghttp2_submit_response2()`. 4944 * 4945 * This function returns newly assigned stream ID if it succeeds and 4946 * |stream_id| is -1. Otherwise, this function returns 0 if it 4947 * succeeds, or one of the following negative error codes: 4948 * 4949 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4950 * Out of memory. 4951 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` 4952 * No stream ID is available because maximum stream ID was 4953 * reached. 4954 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 4955 * The |stream_id| is 0; or trying to depend on itself (stream ID 4956 * equals ``pri_spec->stream_id``). 4957 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` 4958 * DATA or HEADERS has been already submitted and not fully 4959 * processed yet. This happens if stream denoted by |stream_id| 4960 * is in reserved state. 4961 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 4962 * The |stream_id| is -1, and |session| is server session. 4963 * 4964 * .. warning:: 4965 * 4966 * This function returns assigned stream ID if it succeeds and 4967 * |stream_id| is -1. But that stream is not opened yet. The 4968 * application must not submit frame to that stream ID before 4969 * :type:`nghttp2_before_frame_send_callback` is called for this 4970 * frame. 4971 * 4972 */ 4973 NGHTTP2_EXTERN int32_t nghttp2_submit_headers( 4974 nghttp2_session *session, uint8_t flags, int32_t stream_id, 4975 const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen, 4976 void *stream_user_data); 4977 4978 #ifndef NGHTTP2_NO_SSIZE_T 4979 /** 4980 * @function 4981 * 4982 * .. warning:: 4983 * 4984 * Deprecated. Use `nghttp2_submit_data2()` instead. 4985 * 4986 * Submits one or more DATA frames to the stream |stream_id|. The 4987 * data to be sent are provided by |data_prd|. If |flags| contains 4988 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame 4989 * has END_STREAM flag set. 4990 * 4991 * This function does not take ownership of the |data_prd|. The 4992 * function copies the members of the |data_prd|. 4993 * 4994 * This function returns 0 if it succeeds, or one of the following 4995 * negative error codes: 4996 * 4997 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 4998 * Out of memory. 4999 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` 5000 * DATA or HEADERS has been already submitted and not fully 5001 * processed yet. 5002 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5003 * The |stream_id| is 0. 5004 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED` 5005 * The stream was already closed; or the |stream_id| is invalid. 5006 * 5007 * .. note:: 5008 * 5009 * Currently, only one DATA or HEADERS is allowed for a stream at a 5010 * time. Submitting these frames more than once before first DATA 5011 * or HEADERS is finished results in 5012 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code. The 5013 * earliest callback which tells that previous frame is done is 5014 * :type:`nghttp2_on_frame_send_callback`. In side that callback, 5015 * new data can be submitted using `nghttp2_submit_data()`. Of 5016 * course, all data except for last one must not have 5017 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|. 5018 * This sounds a bit complicated, and we recommend to use 5019 * `nghttp2_submit_request()` and `nghttp2_submit_response()` to 5020 * avoid this cascading issue. The experience shows that for HTTP 5021 * use, these two functions are enough to implement both client and 5022 * server. 5023 */ 5024 NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, 5025 int32_t stream_id, 5026 const nghttp2_data_provider *data_prd); 5027 5028 #endif /* NGHTTP2_NO_SSIZE_T */ 5029 5030 /** 5031 * @function 5032 * 5033 * Submits one or more DATA frames to the stream |stream_id|. The 5034 * data to be sent are provided by |data_prd|. If |flags| contains 5035 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame 5036 * has END_STREAM flag set. 5037 * 5038 * This function does not take ownership of the |data_prd|. The 5039 * function copies the members of the |data_prd|. 5040 * 5041 * This function returns 0 if it succeeds, or one of the following 5042 * negative error codes: 5043 * 5044 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5045 * Out of memory. 5046 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` 5047 * DATA or HEADERS has been already submitted and not fully 5048 * processed yet. 5049 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5050 * The |stream_id| is 0. 5051 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED` 5052 * The stream was already closed; or the |stream_id| is invalid. 5053 * 5054 * .. note:: 5055 * 5056 * Currently, only one DATA or HEADERS is allowed for a stream at a 5057 * time. Submitting these frames more than once before first DATA 5058 * or HEADERS is finished results in 5059 * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code. The 5060 * earliest callback which tells that previous frame is done is 5061 * :type:`nghttp2_on_frame_send_callback`. In side that callback, 5062 * new data can be submitted using `nghttp2_submit_data2()`. Of 5063 * course, all data except for last one must not have 5064 * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|. 5065 * This sounds a bit complicated, and we recommend to use 5066 * `nghttp2_submit_request2()` and `nghttp2_submit_response2()` to 5067 * avoid this cascading issue. The experience shows that for HTTP 5068 * use, these two functions are enough to implement both client and 5069 * server. 5070 */ 5071 NGHTTP2_EXTERN int nghttp2_submit_data2(nghttp2_session *session, uint8_t flags, 5072 int32_t stream_id, 5073 const nghttp2_data_provider2 *data_prd); 5074 5075 /** 5076 * @function 5077 * 5078 * .. warning:: 5079 * 5080 * Deprecated. :rfc:`7540` priorities are deprecated by 5081 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 5082 * prioritization scheme. In the future release after the end of 5083 * 2024, this function will always return 0 without doing anything. 5084 * 5085 * Submits PRIORITY frame to change the priority of stream |stream_id| 5086 * to the priority specification |pri_spec|. 5087 * 5088 * The |flags| is currently ignored and should be 5089 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5090 * 5091 * The |pri_spec| is a deprecated priority specification of this 5092 * request. ``NULL`` is not allowed for this function. To specify the 5093 * priority, use `nghttp2_priority_spec_init()`. This function will 5094 * copy its data members. 5095 * 5096 * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, 5097 * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` 5098 * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes 5099 * :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than 5100 * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes 5101 * :macro:`NGHTTP2_MAX_WEIGHT`. 5102 * 5103 * If 5104 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 5105 * of value of 1 is received by a remote endpoint, this function does 5106 * nothing and returns 0. 5107 * 5108 * This function returns 0 if it succeeds, or one of the following 5109 * negative error codes: 5110 * 5111 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5112 * Out of memory. 5113 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5114 * The |stream_id| is 0; or the |pri_spec| is NULL; or trying to 5115 * depend on itself. 5116 */ 5117 NGHTTP2_EXTERN int 5118 nghttp2_submit_priority(nghttp2_session *session, uint8_t flags, 5119 int32_t stream_id, 5120 const nghttp2_priority_spec *pri_spec); 5121 5122 /** 5123 * @macro 5124 * 5125 * :macro:`NGHTTP2_EXTPRI_DEFAULT_URGENCY` is the default urgency 5126 * level for :rfc:`9218` extensible priorities. 5127 */ 5128 #define NGHTTP2_EXTPRI_DEFAULT_URGENCY 3 5129 5130 /** 5131 * @macro 5132 * 5133 * :macro:`NGHTTP2_EXTPRI_URGENCY_HIGH` is the highest urgency level 5134 * for :rfc:`9218` extensible priorities. 5135 */ 5136 #define NGHTTP2_EXTPRI_URGENCY_HIGH 0 5137 5138 /** 5139 * @macro 5140 * 5141 * :macro:`NGHTTP2_EXTPRI_URGENCY_LOW` is the lowest urgency level for 5142 * :rfc:`9218` extensible priorities. 5143 */ 5144 #define NGHTTP2_EXTPRI_URGENCY_LOW 7 5145 5146 /** 5147 * @macro 5148 * 5149 * :macro:`NGHTTP2_EXTPRI_URGENCY_LEVELS` is the number of urgency 5150 * levels for :rfc:`9218` extensible priorities. 5151 */ 5152 #define NGHTTP2_EXTPRI_URGENCY_LEVELS (NGHTTP2_EXTPRI_URGENCY_LOW + 1) 5153 5154 /** 5155 * @struct 5156 * 5157 * :type:`nghttp2_extpri` is :rfc:`9218` extensible priorities 5158 * specification for a stream. 5159 */ 5160 typedef struct nghttp2_extpri { 5161 /** 5162 * :member:`urgency` is the urgency of a stream, it must be in 5163 * [:macro:`NGHTTP2_EXTPRI_URGENCY_HIGH`, 5164 * :macro:`NGHTTP2_EXTPRI_URGENCY_LOW`], inclusive, and 0 is the 5165 * highest urgency. 5166 */ 5167 uint32_t urgency; 5168 /** 5169 * :member:`inc` indicates that a content can be processed 5170 * incrementally or not. If inc is 0, it cannot be processed 5171 * incrementally. If inc is 1, it can be processed incrementally. 5172 * Other value is not permitted. 5173 */ 5174 int inc; 5175 } nghttp2_extpri; 5176 5177 /** 5178 * @function 5179 * 5180 * Submits RST_STREAM frame to cancel/reject the stream |stream_id| 5181 * with the error code |error_code|. 5182 * 5183 * The pre-defined error code is one of :enum:`nghttp2_error_code`. 5184 * 5185 * The |flags| is currently ignored and should be 5186 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5187 * 5188 * This function returns 0 if it succeeds, or one of the following 5189 * negative error codes: 5190 * 5191 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5192 * Out of memory. 5193 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5194 * The |stream_id| is 0. 5195 */ 5196 NGHTTP2_EXTERN int nghttp2_submit_rst_stream(nghttp2_session *session, 5197 uint8_t flags, int32_t stream_id, 5198 uint32_t error_code); 5199 5200 /** 5201 * @function 5202 * 5203 * Stores local settings and submits SETTINGS frame. The |iv| is the 5204 * pointer to the array of :type:`nghttp2_settings_entry`. The |niv| 5205 * indicates the number of :type:`nghttp2_settings_entry`. 5206 * 5207 * The |flags| is currently ignored and should be 5208 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5209 * 5210 * This function does not take ownership of the |iv|. This function 5211 * copies all the elements in the |iv|. 5212 * 5213 * While updating individual stream's local window size, if the window 5214 * size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE, 5215 * RST_STREAM is issued against such a stream. 5216 * 5217 * SETTINGS with :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK` is 5218 * automatically submitted by the library and application could not 5219 * send it at its will. 5220 * 5221 * This function returns 0 if it succeeds, or one of the following 5222 * negative error codes: 5223 * 5224 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5225 * The |iv| contains invalid value (e.g., initial window size 5226 * strictly greater than (1 << 31) - 1. 5227 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5228 * Out of memory. 5229 */ 5230 NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session, 5231 uint8_t flags, 5232 const nghttp2_settings_entry *iv, 5233 size_t niv); 5234 5235 /** 5236 * @function 5237 * 5238 * Submits PUSH_PROMISE frame. 5239 * 5240 * The |flags| is currently ignored. The library handles the 5241 * CONTINUATION frame internally and it correctly sets END_HEADERS to 5242 * the last sequence of the PUSH_PROMISE or CONTINUATION frame. 5243 * 5244 * The |stream_id| must be client initiated stream ID. 5245 * 5246 * The |nva| is an array of name/value pair :type:`nghttp2_nv` with 5247 * |nvlen| elements. The application is responsible to include 5248 * required pseudo-header fields (header field whose name starts with 5249 * ":") in |nva| and must place pseudo-headers before regular header 5250 * fields. 5251 * 5252 * This function creates copies of all name/value pairs in |nva|. It 5253 * also lower-cases all names in |nva|. The order of elements in 5254 * |nva| is preserved. For header fields with 5255 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and 5256 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, 5257 * header field name and value are not copied respectively. With 5258 * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application 5259 * is responsible to pass header field name in lowercase. The 5260 * application should maintain the references to them until 5261 * :type:`nghttp2_on_frame_send_callback` or 5262 * :type:`nghttp2_on_frame_not_send_callback` is called. 5263 * 5264 * The |promised_stream_user_data| is a pointer to an arbitrary data 5265 * which is associated to the promised stream this frame will open and 5266 * make it in reserved state. It is available using 5267 * `nghttp2_session_get_stream_user_data()`. The application can 5268 * access it in :type:`nghttp2_before_frame_send_callback` and 5269 * :type:`nghttp2_on_frame_send_callback` of this frame. 5270 * 5271 * The client side is not allowed to use this function. 5272 * 5273 * To submit response headers and data, use 5274 * `nghttp2_submit_response2()`. 5275 * 5276 * This function returns assigned promised stream ID if it succeeds, 5277 * or one of the following negative error codes: 5278 * 5279 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5280 * Out of memory. 5281 * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` 5282 * This function was invoked when |session| is initialized as 5283 * client. 5284 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` 5285 * No stream ID is available because maximum stream ID was 5286 * reached. 5287 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5288 * The |stream_id| is 0; The |stream_id| does not designate stream 5289 * that peer initiated. 5290 * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED` 5291 * The stream was already closed; or the |stream_id| is invalid. 5292 * 5293 * .. warning:: 5294 * 5295 * This function returns assigned promised stream ID if it succeeds. 5296 * As of 1.16.0, stream object for pushed resource is created when 5297 * this function succeeds. In that case, the application can submit 5298 * push response for the promised frame. 5299 * 5300 * In 1.15.0 or prior versions, pushed stream is not opened yet when 5301 * this function succeeds. The application must not submit frame to 5302 * that stream ID before :type:`nghttp2_before_frame_send_callback` 5303 * is called for this frame. 5304 * 5305 */ 5306 NGHTTP2_EXTERN int32_t nghttp2_submit_push_promise( 5307 nghttp2_session *session, uint8_t flags, int32_t stream_id, 5308 const nghttp2_nv *nva, size_t nvlen, void *promised_stream_user_data); 5309 5310 /** 5311 * @function 5312 * 5313 * Submits PING frame. You don't have to send PING back when you 5314 * received PING frame. The library automatically submits PING frame 5315 * in this case. 5316 * 5317 * The |flags| is bitwise OR of 0 or more of the following value. 5318 * 5319 * * :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK` 5320 * 5321 * Unless `nghttp2_option_set_no_auto_ping_ack()` is used, the |flags| 5322 * should be :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5323 * 5324 * If the |opaque_data| is non ``NULL``, then it should point to the 8 5325 * bytes array of memory to specify opaque data to send with PING 5326 * frame. If the |opaque_data| is ``NULL``, zero-cleared 8 bytes will 5327 * be sent as opaque data. 5328 * 5329 * This function returns 0 if it succeeds, or one of the following 5330 * negative error codes: 5331 * 5332 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5333 * Out of memory. 5334 */ 5335 NGHTTP2_EXTERN int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags, 5336 const uint8_t *opaque_data); 5337 5338 /** 5339 * @function 5340 * 5341 * Submits GOAWAY frame with the last stream ID |last_stream_id| and 5342 * the error code |error_code|. 5343 * 5344 * The pre-defined error code is one of :enum:`nghttp2_error_code`. 5345 * 5346 * The |flags| is currently ignored and should be 5347 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5348 * 5349 * The |last_stream_id| is peer's stream ID or 0. So if |session| is 5350 * initialized as client, |last_stream_id| must be even or 0. If 5351 * |session| is initialized as server, |last_stream_id| must be odd or 5352 * 0. 5353 * 5354 * The HTTP/2 specification says last_stream_id must not be increased 5355 * from the value previously sent. So the actual value sent as 5356 * last_stream_id is the minimum value between the given 5357 * |last_stream_id| and the last_stream_id previously sent to the 5358 * peer. 5359 * 5360 * If the |opaque_data| is not ``NULL`` and |opaque_data_len| is not 5361 * zero, those data will be sent as additional debug data. The 5362 * library makes a copy of the memory region pointed by |opaque_data| 5363 * with the length |opaque_data_len|, so the caller does not need to 5364 * keep this memory after the return of this function. If the 5365 * |opaque_data_len| is 0, the |opaque_data| could be ``NULL``. 5366 * 5367 * After successful transmission of GOAWAY, following things happen. 5368 * All incoming streams having strictly more than |last_stream_id| are 5369 * closed. All incoming HEADERS which starts new stream are simply 5370 * ignored. After all active streams are handled, both 5371 * `nghttp2_session_want_read()` and `nghttp2_session_want_write()` 5372 * return 0 and the application can close session. 5373 * 5374 * This function returns 0 if it succeeds, or one of the following 5375 * negative error codes: 5376 * 5377 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5378 * Out of memory. 5379 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5380 * The |opaque_data_len| is too large; the |last_stream_id| is 5381 * invalid. 5382 */ 5383 NGHTTP2_EXTERN int nghttp2_submit_goaway(nghttp2_session *session, 5384 uint8_t flags, int32_t last_stream_id, 5385 uint32_t error_code, 5386 const uint8_t *opaque_data, 5387 size_t opaque_data_len); 5388 5389 /** 5390 * @function 5391 * 5392 * Returns the last stream ID of a stream for which 5393 * :type:`nghttp2_on_frame_recv_callback` was invoked most recently. 5394 * The returned value can be used as last_stream_id parameter for 5395 * `nghttp2_submit_goaway()` and 5396 * `nghttp2_session_terminate_session2()`. 5397 * 5398 * This function always succeeds. 5399 */ 5400 NGHTTP2_EXTERN int32_t 5401 nghttp2_session_get_last_proc_stream_id(nghttp2_session *session); 5402 5403 /** 5404 * @function 5405 * 5406 * Returns nonzero if new request can be sent from local endpoint. 5407 * 5408 * This function return 0 if request is not allowed for this session. 5409 * There are several reasons why request is not allowed. Some of the 5410 * reasons are: session is server; stream ID has been spent; GOAWAY 5411 * has been sent or received. 5412 * 5413 * The application can call `nghttp2_submit_request2()` without 5414 * consulting this function. In that case, 5415 * `nghttp2_submit_request2()` may return error. Or, request is 5416 * failed to sent, and :type:`nghttp2_on_stream_close_callback` is 5417 * called. 5418 */ 5419 NGHTTP2_EXTERN int 5420 nghttp2_session_check_request_allowed(nghttp2_session *session); 5421 5422 /** 5423 * @function 5424 * 5425 * Returns nonzero if |session| is initialized as server side session. 5426 */ 5427 NGHTTP2_EXTERN int 5428 nghttp2_session_check_server_session(nghttp2_session *session); 5429 5430 /** 5431 * @function 5432 * 5433 * Submits WINDOW_UPDATE frame. 5434 * 5435 * The |flags| is currently ignored and should be 5436 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5437 * 5438 * The |stream_id| is the stream ID to send this WINDOW_UPDATE. To 5439 * send connection level WINDOW_UPDATE, specify 0 to |stream_id|. 5440 * 5441 * If the |window_size_increment| is positive, the WINDOW_UPDATE with 5442 * that value as window_size_increment is queued. If the 5443 * |window_size_increment| is larger than the received bytes from the 5444 * remote endpoint, the local window size is increased by that 5445 * difference. If the sole purpose is to increase the local window 5446 * size, consider to use `nghttp2_session_set_local_window_size()`. 5447 * 5448 * If the |window_size_increment| is negative, the local window size 5449 * is decreased by -|window_size_increment|. If automatic 5450 * WINDOW_UPDATE is enabled 5451 * (`nghttp2_option_set_no_auto_window_update()`), and the library 5452 * decided that the WINDOW_UPDATE should be submitted, then 5453 * WINDOW_UPDATE is queued with the current received bytes count. If 5454 * the sole purpose is to decrease the local window size, consider to 5455 * use `nghttp2_session_set_local_window_size()`. 5456 * 5457 * If the |window_size_increment| is 0, the function does nothing and 5458 * returns 0. 5459 * 5460 * This function returns 0 if it succeeds, or one of the following 5461 * negative error codes: 5462 * 5463 * :enum:`nghttp2_error.NGHTTP2_ERR_FLOW_CONTROL` 5464 * The local window size overflow or gets negative. 5465 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5466 * Out of memory. 5467 */ 5468 NGHTTP2_EXTERN int nghttp2_submit_window_update(nghttp2_session *session, 5469 uint8_t flags, 5470 int32_t stream_id, 5471 int32_t window_size_increment); 5472 5473 /** 5474 * @function 5475 * 5476 * Set local window size (local endpoints's window size) to the given 5477 * |window_size| for the given stream denoted by |stream_id|. To 5478 * change connection level window size, specify 0 to |stream_id|. To 5479 * increase window size, this function may submit WINDOW_UPDATE frame 5480 * to transmission queue. 5481 * 5482 * The |flags| is currently ignored and should be 5483 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5484 * 5485 * This sounds similar to `nghttp2_submit_window_update()`, but there 5486 * are 2 differences. The first difference is that this function 5487 * takes the absolute value of window size to set, rather than the 5488 * delta. To change the window size, this may be easier to use since 5489 * the application just declares the intended window size, rather than 5490 * calculating delta. The second difference is that 5491 * `nghttp2_submit_window_update()` affects the received bytes count 5492 * which has not acked yet. By the specification of 5493 * `nghttp2_submit_window_update()`, to strictly increase the local 5494 * window size, we have to submit delta including all received bytes 5495 * count, which might not be desirable in some cases. On the other 5496 * hand, this function does not affect the received bytes count. It 5497 * just sets the local window size to the given value. 5498 * 5499 * This function returns 0 if it succeeds, or one of the following 5500 * negative error codes: 5501 * 5502 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5503 * The |stream_id| is negative. 5504 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5505 * Out of memory. 5506 */ 5507 NGHTTP2_EXTERN int 5508 nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags, 5509 int32_t stream_id, int32_t window_size); 5510 5511 /** 5512 * @function 5513 * 5514 * Submits extension frame. 5515 * 5516 * Application can pass arbitrary frame flags and stream ID in |flags| 5517 * and |stream_id| respectively. The |payload| is opaque pointer, and 5518 * it can be accessible though ``frame->ext.payload`` in 5519 * :type:`nghttp2_pack_extension_callback2`. The library will not own 5520 * passed |payload| pointer. 5521 * 5522 * The application must set :type:`nghttp2_pack_extension_callback2` 5523 * using `nghttp2_session_callbacks_set_pack_extension_callback2()`. 5524 * 5525 * The application should retain the memory pointed by |payload| until 5526 * the transmission of extension frame is done (which is indicated by 5527 * :type:`nghttp2_on_frame_send_callback`), or transmission fails 5528 * (which is indicated by :type:`nghttp2_on_frame_not_send_callback`). 5529 * If application does not touch this memory region after packing it 5530 * into a wire format, application can free it inside 5531 * :type:`nghttp2_pack_extension_callback2`. 5532 * 5533 * The standard HTTP/2 frame cannot be sent with this function, so 5534 * |type| must be strictly grater than 0x9. Otherwise, this function 5535 * will fail with error code 5536 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`. 5537 * 5538 * This function returns 0 if it succeeds, or one of the following 5539 * negative error codes: 5540 * 5541 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5542 * If :type:`nghttp2_pack_extension_callback2` is not set. 5543 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5544 * If |type| specifies standard HTTP/2 frame type. The frame 5545 * types in the rage [0x0, 0x9], both inclusive, are standard 5546 * HTTP/2 frame type, and cannot be sent using this function. 5547 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5548 * Out of memory 5549 */ 5550 NGHTTP2_EXTERN int nghttp2_submit_extension(nghttp2_session *session, 5551 uint8_t type, uint8_t flags, 5552 int32_t stream_id, void *payload); 5553 5554 /** 5555 * @struct 5556 * 5557 * The payload of ALTSVC frame. ALTSVC frame is a non-critical 5558 * extension to HTTP/2. If this frame is received, and 5559 * `nghttp2_option_set_user_recv_extension_type()` is not set, and 5560 * `nghttp2_option_set_builtin_recv_extension_type()` is set for 5561 * :enum:`nghttp2_frame_type.NGHTTP2_ALTSVC`, 5562 * ``nghttp2_extension.payload`` will point to this struct. 5563 * 5564 * It has the following members: 5565 */ 5566 typedef struct { 5567 /** 5568 * The pointer to origin which this alternative service is 5569 * associated with. This is not necessarily NULL-terminated. 5570 */ 5571 uint8_t *origin; 5572 /** 5573 * The length of the |origin|. 5574 */ 5575 size_t origin_len; 5576 /** 5577 * The pointer to Alt-Svc field value contained in ALTSVC frame. 5578 * This is not necessarily NULL-terminated. 5579 */ 5580 uint8_t *field_value; 5581 /** 5582 * The length of the |field_value|. 5583 */ 5584 size_t field_value_len; 5585 } nghttp2_ext_altsvc; 5586 5587 /** 5588 * @function 5589 * 5590 * Submits ALTSVC frame. 5591 * 5592 * ALTSVC frame is a non-critical extension to HTTP/2, and defined in 5593 * `RFC 7383 <https://tools.ietf.org/html/rfc7838#section-4>`_. 5594 * 5595 * The |flags| is currently ignored and should be 5596 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5597 * 5598 * The |origin| points to the origin this alternative service is 5599 * associated with. The |origin_len| is the length of the origin. If 5600 * |stream_id| is 0, the origin must be specified. If |stream_id| is 5601 * not zero, the origin must be empty (in other words, |origin_len| 5602 * must be 0). 5603 * 5604 * The ALTSVC frame is only usable from server side. If this function 5605 * is invoked with client side session, this function returns 5606 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. 5607 * 5608 * This function returns 0 if it succeeds, or one of the following 5609 * negative error codes: 5610 * 5611 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5612 * Out of memory 5613 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5614 * The function is called from client side session 5615 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5616 * The sum of |origin_len| and |field_value_len| is larger than 5617 * 16382; or |origin_len| is 0 while |stream_id| is 0; or 5618 * |origin_len| is not 0 while |stream_id| is not 0. 5619 */ 5620 NGHTTP2_EXTERN int nghttp2_submit_altsvc(nghttp2_session *session, 5621 uint8_t flags, int32_t stream_id, 5622 const uint8_t *origin, 5623 size_t origin_len, 5624 const uint8_t *field_value, 5625 size_t field_value_len); 5626 5627 /** 5628 * @struct 5629 * 5630 * The single entry of an origin. 5631 */ 5632 typedef struct { 5633 /** 5634 * The pointer to origin. No validation is made against this field 5635 * by the library. This is not necessarily NULL-terminated. 5636 */ 5637 uint8_t *origin; 5638 /** 5639 * The length of the |origin|. 5640 */ 5641 size_t origin_len; 5642 } nghttp2_origin_entry; 5643 5644 /** 5645 * @struct 5646 * 5647 * The payload of ORIGIN frame. ORIGIN frame is a non-critical 5648 * extension to HTTP/2 and defined by `RFC 8336 5649 * <https://tools.ietf.org/html/rfc8336>`_. 5650 * 5651 * If this frame is received, and 5652 * `nghttp2_option_set_user_recv_extension_type()` is not set, and 5653 * `nghttp2_option_set_builtin_recv_extension_type()` is set for 5654 * :enum:`nghttp2_frame_type.NGHTTP2_ORIGIN`, 5655 * ``nghttp2_extension.payload`` will point to this struct. 5656 * 5657 * It has the following members: 5658 */ 5659 typedef struct { 5660 /** 5661 * The number of origins contained in |ov|. 5662 */ 5663 size_t nov; 5664 /** 5665 * The pointer to the array of origins contained in ORIGIN frame. 5666 */ 5667 nghttp2_origin_entry *ov; 5668 } nghttp2_ext_origin; 5669 5670 /** 5671 * @function 5672 * 5673 * Submits ORIGIN frame. 5674 * 5675 * ORIGIN frame is a non-critical extension to HTTP/2 and defined by 5676 * `RFC 8336 <https://tools.ietf.org/html/rfc8336>`_. 5677 * 5678 * The |flags| is currently ignored and should be 5679 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5680 * 5681 * The |ov| points to the array of origins. The |nov| specifies the 5682 * number of origins included in |ov|. This function creates copies 5683 * of all elements in |ov|. 5684 * 5685 * The ORIGIN frame is only usable by a server. If this function is 5686 * invoked with client side session, this function returns 5687 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. 5688 * 5689 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5690 * Out of memory 5691 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5692 * The function is called from client side session. 5693 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5694 * There are too many origins, or an origin is too large to fit 5695 * into a default frame payload. 5696 */ 5697 NGHTTP2_EXTERN int nghttp2_submit_origin(nghttp2_session *session, 5698 uint8_t flags, 5699 const nghttp2_origin_entry *ov, 5700 size_t nov); 5701 5702 /** 5703 * @struct 5704 * 5705 * The payload of PRIORITY_UPDATE frame. PRIORITY_UPDATE frame is a 5706 * non-critical extension to HTTP/2. If this frame is received, and 5707 * `nghttp2_option_set_user_recv_extension_type()` is not set, and 5708 * `nghttp2_option_set_builtin_recv_extension_type()` is set for 5709 * :enum:`nghttp2_frame_type.NGHTTP2_PRIORITY_UPDATE`, 5710 * ``nghttp2_extension.payload`` will point to this struct. 5711 * 5712 * It has the following members: 5713 */ 5714 typedef struct { 5715 /** 5716 * The stream ID of the stream whose priority is updated. 5717 */ 5718 int32_t stream_id; 5719 /** 5720 * The pointer to Priority field value. It is not necessarily 5721 * NULL-terminated. 5722 */ 5723 uint8_t *field_value; 5724 /** 5725 * The length of the :member:`field_value`. 5726 */ 5727 size_t field_value_len; 5728 } nghttp2_ext_priority_update; 5729 5730 /** 5731 * @function 5732 * 5733 * Submits PRIORITY_UPDATE frame. 5734 * 5735 * PRIORITY_UPDATE frame is a non-critical extension to HTTP/2, and 5736 * defined in :rfc:`9218#section-7.1`. 5737 * 5738 * The |flags| is currently ignored and should be 5739 * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. 5740 * 5741 * The |stream_id| is the ID of stream which is prioritized. The 5742 * |field_value| points to the Priority field value. The 5743 * |field_value_len| is the length of the Priority field value. 5744 * 5745 * If this function is called by server, 5746 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` is returned. 5747 * 5748 * If 5749 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 5750 * of value of 0 is received by a remote endpoint (or it is omitted), 5751 * this function does nothing and returns 0. 5752 * 5753 * This function returns 0 if it succeeds, or one of the following 5754 * negative error codes: 5755 * 5756 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5757 * Out of memory 5758 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5759 * The function is called from server side session 5760 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5761 * The |field_value_len| is larger than 16380; or |stream_id| is 5762 * 0. 5763 */ 5764 NGHTTP2_EXTERN int nghttp2_submit_priority_update(nghttp2_session *session, 5765 uint8_t flags, 5766 int32_t stream_id, 5767 const uint8_t *field_value, 5768 size_t field_value_len); 5769 5770 /** 5771 * @function 5772 * 5773 * Changes the priority of the existing stream denoted by |stream_id|. 5774 * The new priority is |extpri|. This function is meant to be used by 5775 * server for :rfc:`9218` extensible prioritization scheme. 5776 * 5777 * If |session| is initialized as client, this function returns 5778 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. For client, use 5779 * `nghttp2_submit_priority_update()` instead. 5780 * 5781 * If :member:`extpri->urgency <nghttp2_extpri.urgency>` is out of 5782 * bound, it is set to :macro:`NGHTTP2_EXTPRI_URGENCY_LOW`. 5783 * 5784 * If |ignore_client_signal| is nonzero, server starts to ignore 5785 * client priority signals for this stream. 5786 * 5787 * If 5788 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 5789 * of value of 1 is not submitted via `nghttp2_submit_settings()`, 5790 * this function does nothing and returns 0. 5791 * 5792 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 5793 * Out of memory. 5794 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5795 * The |session| is initialized as client. 5796 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5797 * |stream_id| is zero; or a stream denoted by |stream_id| is not 5798 * found. 5799 */ 5800 NGHTTP2_EXTERN int nghttp2_session_change_extpri_stream_priority( 5801 nghttp2_session *session, int32_t stream_id, const nghttp2_extpri *extpri, 5802 int ignore_client_signal); 5803 5804 /** 5805 * @function 5806 * 5807 * Stores the stream priority of the existing stream denoted by 5808 * |stream_id| in the object pointed by |extpri|. This function is 5809 * meant to be used by server for :rfc:`9218` extensible 5810 * prioritization scheme. 5811 * 5812 * If |session| is initialized as client, this function returns 5813 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`. 5814 * 5815 * If 5816 * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` 5817 * of value of 1 is not submitted via `nghttp2_submit_settings()`, 5818 * this function does nothing and returns 0. 5819 * 5820 * This function returns 0 if it succeeds, or one of the following 5821 * negative error codes: 5822 * 5823 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 5824 * The |session| is initialized as client. 5825 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5826 * |stream_id| is zero; or a stream denoted by |stream_id| is not 5827 * found. 5828 */ 5829 NGHTTP2_EXTERN int nghttp2_session_get_extpri_stream_priority( 5830 nghttp2_session *session, nghttp2_extpri *extpri, int32_t stream_id); 5831 5832 /** 5833 * @function 5834 * 5835 * Parses Priority header field value pointed by |value| of length 5836 * |len|, and stores the result in the object pointed by |extpri|. 5837 * Priority header field is defined in :rfc:`9218`. 5838 * 5839 * This function does not initialize the object pointed by |extpri| 5840 * before storing the result. It only assigns the values that the 5841 * parser correctly extracted to fields. 5842 * 5843 * This function returns 0 if it succeeds, or one of the following 5844 * negative error codes: 5845 * 5846 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` 5847 * Failed to parse the header field value. 5848 */ 5849 NGHTTP2_EXTERN int nghttp2_extpri_parse_priority(nghttp2_extpri *extpri, 5850 const uint8_t *value, 5851 size_t len); 5852 5853 /** 5854 * @function 5855 * 5856 * Compares ``lhs->name`` of length ``lhs->namelen`` bytes and 5857 * ``rhs->name`` of length ``rhs->namelen`` bytes. Returns negative 5858 * integer if ``lhs->name`` is found to be less than ``rhs->name``; or 5859 * returns positive integer if ``lhs->name`` is found to be greater 5860 * than ``rhs->name``; or returns 0 otherwise. 5861 */ 5862 NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs, 5863 const nghttp2_nv *rhs); 5864 5865 /** 5866 * @function 5867 * 5868 * .. warning:: 5869 * 5870 * Deprecated. Use `nghttp2_select_alpn` instead. 5871 * 5872 * A helper function for dealing with ALPN in server side. The |in| 5873 * contains peer's protocol list in preferable order. The format of 5874 * |in| is length-prefixed and not null-terminated. For example, 5875 * ``h2`` and ``http/1.1`` stored in |in| like this:: 5876 * 5877 * in[0] = 2 5878 * in[1..2] = "h2" 5879 * in[3] = 8 5880 * in[4..11] = "http/1.1" 5881 * inlen = 12 5882 * 5883 * The selection algorithm is as follows: 5884 * 5885 * 1. If peer's list contains HTTP/2 protocol the library supports, 5886 * it is selected and returns 1. The following step is not taken. 5887 * 5888 * 2. If peer's list contains ``http/1.1``, this function selects 5889 * ``http/1.1`` and returns 0. The following step is not taken. 5890 * 5891 * 3. This function selects nothing and returns -1 (So called 5892 * non-overlap case). In this case, |out| and |outlen| are left 5893 * untouched. 5894 * 5895 * Selecting ``h2`` means that ``h2`` is written into |*out| and its 5896 * length (which is 2) is assigned to |*outlen|. 5897 * 5898 * For ALPN, refer to https://tools.ietf.org/html/rfc7301 5899 * 5900 * To use this method you should do something like:: 5901 * 5902 * static int alpn_select_proto_cb(SSL* ssl, 5903 * const unsigned char **out, 5904 * unsigned char *outlen, 5905 * const unsigned char *in, 5906 * unsigned int inlen, 5907 * void *arg) 5908 * { 5909 * int rv; 5910 * rv = nghttp2_select_next_protocol((unsigned char**)out, outlen, 5911 * in, inlen); 5912 * if (rv == -1) { 5913 * return SSL_TLSEXT_ERR_NOACK; 5914 * } 5915 * if (rv == 1) { 5916 * ((MyType*)arg)->http2_selected = 1; 5917 * } 5918 * return SSL_TLSEXT_ERR_OK; 5919 * } 5920 * ... 5921 * SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, my_obj); 5922 * 5923 */ 5924 NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out, 5925 unsigned char *outlen, 5926 const unsigned char *in, 5927 unsigned int inlen); 5928 5929 /** 5930 * @function 5931 * 5932 * A helper function for dealing with ALPN in server side. The |in| 5933 * contains peer's protocol list in preferable order. The format of 5934 * |in| is length-prefixed and not null-terminated. For example, 5935 * ``h2`` and ``http/1.1`` stored in |in| like this:: 5936 * 5937 * in[0] = 2 5938 * in[1..2] = "h2" 5939 * in[3] = 8 5940 * in[4..11] = "http/1.1" 5941 * inlen = 12 5942 * 5943 * The selection algorithm is as follows: 5944 * 5945 * 1. If peer's list contains HTTP/2 protocol the library supports, 5946 * it is selected and returns 1. The following step is not taken. 5947 * 5948 * 2. If peer's list contains ``http/1.1``, this function selects 5949 * ``http/1.1`` and returns 0. The following step is not taken. 5950 * 5951 * 3. This function selects nothing and returns -1 (So called 5952 * non-overlap case). In this case, |out| and |outlen| are left 5953 * untouched. 5954 * 5955 * Selecting ``h2`` means that ``h2`` is written into |*out| and its 5956 * length (which is 2) is assigned to |*outlen|. 5957 * 5958 * For ALPN, refer to https://tools.ietf.org/html/rfc7301 5959 * 5960 * To use this method you should do something like:: 5961 * 5962 * static int alpn_select_proto_cb(SSL* ssl, 5963 * const unsigned char **out, 5964 * unsigned char *outlen, 5965 * const unsigned char *in, 5966 * unsigned int inlen, 5967 * void *arg) 5968 * { 5969 * int rv; 5970 * rv = nghttp2_select_alpn(out, outlen, in, inlen); 5971 * if (rv == -1) { 5972 * return SSL_TLSEXT_ERR_NOACK; 5973 * } 5974 * if (rv == 1) { 5975 * ((MyType*)arg)->http2_selected = 1; 5976 * } 5977 * return SSL_TLSEXT_ERR_OK; 5978 * } 5979 * ... 5980 * SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, my_obj); 5981 * 5982 */ 5983 NGHTTP2_EXTERN int nghttp2_select_alpn(const unsigned char **out, 5984 unsigned char *outlen, 5985 const unsigned char *in, 5986 unsigned int inlen); 5987 5988 /** 5989 * @function 5990 * 5991 * Returns a pointer to a nghttp2_info struct with version information 5992 * about the run-time library in use. The |least_version| argument 5993 * can be set to a 24 bit numerical value for the least accepted 5994 * version number and if the condition is not met, this function will 5995 * return a ``NULL``. Pass in 0 to skip the version checking. 5996 */ 5997 NGHTTP2_EXTERN nghttp2_info *nghttp2_version(int least_version); 5998 5999 /** 6000 * @function 6001 * 6002 * Returns nonzero if the :type:`nghttp2_error` library error code 6003 * |lib_error| is fatal. 6004 */ 6005 NGHTTP2_EXTERN int nghttp2_is_fatal(int lib_error_code); 6006 6007 /** 6008 * @function 6009 * 6010 * Returns nonzero if HTTP header field name |name| of length |len| is 6011 * valid according to http://tools.ietf.org/html/rfc7230#section-3.2 6012 * 6013 * Because this is a header field name in HTTP2, the upper cased alphabet 6014 * is treated as error. 6015 */ 6016 NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len); 6017 6018 /** 6019 * @function 6020 * 6021 * Returns nonzero if HTTP header field value |value| of length |len| 6022 * is valid according to 6023 * http://tools.ietf.org/html/rfc7230#section-3.2 6024 * 6025 * This function is considered obsolete, and application should 6026 * consider to use `nghttp2_check_header_value_rfc9113()` instead. 6027 */ 6028 NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len); 6029 6030 /** 6031 * @function 6032 * 6033 * Returns nonzero if HTTP header field value |value| of length |len| 6034 * is valid according to 6035 * http://tools.ietf.org/html/rfc7230#section-3.2, plus 6036 * https://datatracker.ietf.org/doc/html/rfc9113#section-8.2.1 6037 */ 6038 NGHTTP2_EXTERN int nghttp2_check_header_value_rfc9113(const uint8_t *value, 6039 size_t len); 6040 6041 /** 6042 * @function 6043 * 6044 * Returns nonzero if the |value| which is supposed to be the value of 6045 * the :method header field is valid according to 6046 * https://datatracker.ietf.org/doc/html/rfc7231#section-4 and 6047 * https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6 6048 */ 6049 NGHTTP2_EXTERN int nghttp2_check_method(const uint8_t *value, size_t len); 6050 6051 /** 6052 * @function 6053 * 6054 * Returns nonzero if the |value| which is supposed to be the value of 6055 * the :path header field is valid according to 6056 * https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3 6057 * 6058 * |value| is valid if it merely consists of the allowed characters. 6059 * In particular, it does not check whether |value| follows the syntax 6060 * of path. The allowed characters are all characters valid by 6061 * `nghttp2_check_header_value` minus SPC and HT. 6062 */ 6063 NGHTTP2_EXTERN int nghttp2_check_path(const uint8_t *value, size_t len); 6064 6065 /** 6066 * @function 6067 * 6068 * Returns nonzero if the |value| which is supposed to be the value of the 6069 * :authority or host header field is valid according to 6070 * https://tools.ietf.org/html/rfc3986#section-3.2 6071 * 6072 * |value| is valid if it merely consists of the allowed characters. 6073 * In particular, it does not check whether |value| follows the syntax 6074 * of authority. 6075 */ 6076 NGHTTP2_EXTERN int nghttp2_check_authority(const uint8_t *value, size_t len); 6077 6078 /* HPACK API */ 6079 6080 struct nghttp2_hd_deflater; 6081 6082 /** 6083 * @struct 6084 * 6085 * HPACK deflater object. 6086 */ 6087 typedef struct nghttp2_hd_deflater nghttp2_hd_deflater; 6088 6089 /** 6090 * @function 6091 * 6092 * Initializes |*deflater_ptr| for deflating name/values pairs. 6093 * 6094 * The |max_deflate_dynamic_table_size| is the upper bound of header 6095 * table size the deflater will use. 6096 * 6097 * If this function fails, |*deflater_ptr| is left untouched. 6098 * 6099 * This function returns 0 if it succeeds, or one of the following 6100 * negative error codes: 6101 * 6102 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6103 * Out of memory. 6104 */ 6105 NGHTTP2_EXTERN int 6106 nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr, 6107 size_t max_deflate_dynamic_table_size); 6108 6109 /** 6110 * @function 6111 * 6112 * Like `nghttp2_hd_deflate_new()`, but with additional custom memory 6113 * allocator specified in the |mem|. 6114 * 6115 * The |mem| can be ``NULL`` and the call is equivalent to 6116 * `nghttp2_hd_deflate_new()`. 6117 * 6118 * This function does not take ownership |mem|. The application is 6119 * responsible for freeing |mem|. 6120 * 6121 * The library code does not refer to |mem| pointer after this 6122 * function returns, so the application can safely free it. 6123 */ 6124 NGHTTP2_EXTERN int 6125 nghttp2_hd_deflate_new2(nghttp2_hd_deflater **deflater_ptr, 6126 size_t max_deflate_dynamic_table_size, 6127 nghttp2_mem *mem); 6128 6129 /** 6130 * @function 6131 * 6132 * Deallocates any resources allocated for |deflater|. 6133 */ 6134 NGHTTP2_EXTERN void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater); 6135 6136 /** 6137 * @function 6138 * 6139 * Changes header table size of the |deflater| to 6140 * |settings_max_dynamic_table_size| bytes. This may trigger eviction 6141 * in the dynamic table. 6142 * 6143 * The |settings_max_dynamic_table_size| should be the value received 6144 * in SETTINGS_HEADER_TABLE_SIZE. 6145 * 6146 * The deflater never uses more memory than 6147 * ``max_deflate_dynamic_table_size`` bytes specified in 6148 * `nghttp2_hd_deflate_new()`. Therefore, if 6149 * |settings_max_dynamic_table_size| > 6150 * ``max_deflate_dynamic_table_size``, resulting maximum table size 6151 * becomes ``max_deflate_dynamic_table_size``. 6152 * 6153 * This function returns 0 if it succeeds, or one of the following 6154 * negative error codes: 6155 * 6156 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6157 * Out of memory. 6158 */ 6159 NGHTTP2_EXTERN int 6160 nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater, 6161 size_t settings_max_dynamic_table_size); 6162 6163 #ifndef NGHTTP2_NO_SSIZE_T 6164 /** 6165 * @function 6166 * 6167 * .. warning:: 6168 * 6169 * Deprecated. Use `nghttp2_hd_deflate_hd2()` instead. 6170 * 6171 * Deflates the |nva|, which has the |nvlen| name/value pairs, into 6172 * the |buf| of length |buflen|. 6173 * 6174 * If |buf| is not large enough to store the deflated header block, 6175 * this function fails with 6176 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller 6177 * should use `nghttp2_hd_deflate_bound()` to know the upper bound of 6178 * buffer size required to deflate given header name/value pairs. 6179 * 6180 * Once this function fails, subsequent call of this function always 6181 * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. 6182 * 6183 * After this function returns, it is safe to delete the |nva|. 6184 * 6185 * This function returns the number of bytes written to |buf| if it 6186 * succeeds, or one of the following negative error codes: 6187 * 6188 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6189 * Out of memory. 6190 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6191 * Deflation process has failed. 6192 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 6193 * The provided |buflen| size is too small to hold the output. 6194 */ 6195 NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, 6196 uint8_t *buf, size_t buflen, 6197 const nghttp2_nv *nva, 6198 size_t nvlen); 6199 6200 #endif /* NGHTTP2_NO_SSIZE_T */ 6201 6202 /** 6203 * @function 6204 * 6205 * Deflates the |nva|, which has the |nvlen| name/value pairs, into 6206 * the |buf| of length |buflen|. 6207 * 6208 * If |buf| is not large enough to store the deflated header block, 6209 * this function fails with 6210 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller 6211 * should use `nghttp2_hd_deflate_bound()` to know the upper bound of 6212 * buffer size required to deflate given header name/value pairs. 6213 * 6214 * Once this function fails, subsequent call of this function always 6215 * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. 6216 * 6217 * After this function returns, it is safe to delete the |nva|. 6218 * 6219 * This function returns the number of bytes written to |buf| if it 6220 * succeeds, or one of the following negative error codes: 6221 * 6222 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6223 * Out of memory. 6224 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6225 * Deflation process has failed. 6226 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 6227 * The provided |buflen| size is too small to hold the output. 6228 */ 6229 NGHTTP2_EXTERN nghttp2_ssize 6230 nghttp2_hd_deflate_hd2(nghttp2_hd_deflater *deflater, uint8_t *buf, 6231 size_t buflen, const nghttp2_nv *nva, size_t nvlen); 6232 6233 #ifndef NGHTTP2_NO_SSIZE_T 6234 /** 6235 * @function 6236 * 6237 * .. warning:: 6238 * 6239 * Deprecated. Use `nghttp2_hd_deflate_hd_vec2()` instead. 6240 * 6241 * Deflates the |nva|, which has the |nvlen| name/value pairs, into 6242 * the |veclen| size of buf vector |vec|. The each size of buffer 6243 * must be set in len field of :type:`nghttp2_vec`. If and only if 6244 * one chunk is filled up completely, next chunk will be used. If 6245 * |vec| is not large enough to store the deflated header block, this 6246 * function fails with 6247 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller 6248 * should use `nghttp2_hd_deflate_bound()` to know the upper bound of 6249 * buffer size required to deflate given header name/value pairs. 6250 * 6251 * Once this function fails, subsequent call of this function always 6252 * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. 6253 * 6254 * After this function returns, it is safe to delete the |nva|. 6255 * 6256 * This function returns the number of bytes written to |vec| if it 6257 * succeeds, or one of the following negative error codes: 6258 * 6259 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6260 * Out of memory. 6261 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6262 * Deflation process has failed. 6263 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 6264 * The provided |buflen| size is too small to hold the output. 6265 */ 6266 NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater, 6267 const nghttp2_vec *vec, 6268 size_t veclen, 6269 const nghttp2_nv *nva, 6270 size_t nvlen); 6271 6272 #endif /* NGHTTP2_NO_SSIZE_T */ 6273 6274 /** 6275 * @function 6276 * 6277 * Deflates the |nva|, which has the |nvlen| name/value pairs, into 6278 * the |veclen| size of buf vector |vec|. The each size of buffer 6279 * must be set in len field of :type:`nghttp2_vec`. If and only if 6280 * one chunk is filled up completely, next chunk will be used. If 6281 * |vec| is not large enough to store the deflated header block, this 6282 * function fails with 6283 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller 6284 * should use `nghttp2_hd_deflate_bound()` to know the upper bound of 6285 * buffer size required to deflate given header name/value pairs. 6286 * 6287 * Once this function fails, subsequent call of this function always 6288 * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. 6289 * 6290 * After this function returns, it is safe to delete the |nva|. 6291 * 6292 * This function returns the number of bytes written to |vec| if it 6293 * succeeds, or one of the following negative error codes: 6294 * 6295 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6296 * Out of memory. 6297 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6298 * Deflation process has failed. 6299 * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` 6300 * The provided |buflen| size is too small to hold the output. 6301 */ 6302 NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_deflate_hd_vec2( 6303 nghttp2_hd_deflater *deflater, const nghttp2_vec *vec, size_t veclen, 6304 const nghttp2_nv *nva, size_t nvlen); 6305 6306 /** 6307 * @function 6308 * 6309 * Returns an upper bound on the compressed size after deflation of 6310 * |nva| of length |nvlen|. 6311 */ 6312 NGHTTP2_EXTERN size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater, 6313 const nghttp2_nv *nva, 6314 size_t nvlen); 6315 6316 /** 6317 * @function 6318 * 6319 * Returns the number of entries that header table of |deflater| 6320 * contains. This is the sum of the number of static table and 6321 * dynamic table, so the return value is at least 61. 6322 */ 6323 NGHTTP2_EXTERN 6324 size_t nghttp2_hd_deflate_get_num_table_entries(nghttp2_hd_deflater *deflater); 6325 6326 /** 6327 * @function 6328 * 6329 * Returns the table entry denoted by |idx| from header table of 6330 * |deflater|. The |idx| is 1-based, and idx=1 returns first entry of 6331 * static table. idx=62 returns first entry of dynamic table if it 6332 * exists. Specifying idx=0 is error, and this function returns NULL. 6333 * If |idx| is strictly greater than the number of entries the tables 6334 * contain, this function returns NULL. 6335 */ 6336 NGHTTP2_EXTERN 6337 const nghttp2_nv * 6338 nghttp2_hd_deflate_get_table_entry(nghttp2_hd_deflater *deflater, size_t idx); 6339 6340 /** 6341 * @function 6342 * 6343 * Returns the used dynamic table size, including the overhead 32 6344 * bytes per entry described in RFC 7541. 6345 */ 6346 NGHTTP2_EXTERN 6347 size_t nghttp2_hd_deflate_get_dynamic_table_size(nghttp2_hd_deflater *deflater); 6348 6349 /** 6350 * @function 6351 * 6352 * Returns the maximum dynamic table size. 6353 */ 6354 NGHTTP2_EXTERN 6355 size_t 6356 nghttp2_hd_deflate_get_max_dynamic_table_size(nghttp2_hd_deflater *deflater); 6357 6358 struct nghttp2_hd_inflater; 6359 6360 /** 6361 * @struct 6362 * 6363 * HPACK inflater object. 6364 */ 6365 typedef struct nghttp2_hd_inflater nghttp2_hd_inflater; 6366 6367 /** 6368 * @function 6369 * 6370 * Initializes |*inflater_ptr| for inflating name/values pairs. 6371 * 6372 * If this function fails, |*inflater_ptr| is left untouched. 6373 * 6374 * This function returns 0 if it succeeds, or one of the following 6375 * negative error codes: 6376 * 6377 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6378 * Out of memory. 6379 */ 6380 NGHTTP2_EXTERN int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr); 6381 6382 /** 6383 * @function 6384 * 6385 * Like `nghttp2_hd_inflate_new()`, but with additional custom memory 6386 * allocator specified in the |mem|. 6387 * 6388 * The |mem| can be ``NULL`` and the call is equivalent to 6389 * `nghttp2_hd_inflate_new()`. 6390 * 6391 * This function does not take ownership |mem|. The application is 6392 * responsible for freeing |mem|. 6393 * 6394 * The library code does not refer to |mem| pointer after this 6395 * function returns, so the application can safely free it. 6396 */ 6397 NGHTTP2_EXTERN int nghttp2_hd_inflate_new2(nghttp2_hd_inflater **inflater_ptr, 6398 nghttp2_mem *mem); 6399 6400 /** 6401 * @function 6402 * 6403 * Deallocates any resources allocated for |inflater|. 6404 */ 6405 NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater); 6406 6407 /** 6408 * @function 6409 * 6410 * Changes header table size in the |inflater|. This may trigger 6411 * eviction in the dynamic table. 6412 * 6413 * The |settings_max_dynamic_table_size| should be the value 6414 * transmitted in SETTINGS_HEADER_TABLE_SIZE. 6415 * 6416 * This function must not be called while header block is being 6417 * inflated. In other words, this function must be called after 6418 * initialization of |inflater|, but before calling 6419 * `nghttp2_hd_inflate_hd3()`, or after 6420 * `nghttp2_hd_inflate_end_headers()`. Otherwise, 6421 * `NGHTTP2_ERR_INVALID_STATE` was returned. 6422 * 6423 * This function returns 0 if it succeeds, or one of the following 6424 * negative error codes: 6425 * 6426 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6427 * Out of memory. 6428 * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` 6429 * The function is called while header block is being inflated. 6430 * Probably, application missed to call 6431 * `nghttp2_hd_inflate_end_headers()`. 6432 */ 6433 NGHTTP2_EXTERN int 6434 nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater, 6435 size_t settings_max_dynamic_table_size); 6436 6437 /** 6438 * @enum 6439 * 6440 * The flags for header inflation. 6441 */ 6442 typedef enum { 6443 /** 6444 * No flag set. 6445 */ 6446 NGHTTP2_HD_INFLATE_NONE = 0, 6447 /** 6448 * Indicates all headers were inflated. 6449 */ 6450 NGHTTP2_HD_INFLATE_FINAL = 0x01, 6451 /** 6452 * Indicates a header was emitted. 6453 */ 6454 NGHTTP2_HD_INFLATE_EMIT = 0x02 6455 } nghttp2_hd_inflate_flag; 6456 6457 #ifndef NGHTTP2_NO_SSIZE_T 6458 /** 6459 * @function 6460 * 6461 * .. warning:: 6462 * 6463 * Deprecated. Use `nghttp2_hd_inflate_hd2()` instead. 6464 * 6465 * Inflates name/value block stored in |in| with length |inlen|. This 6466 * function performs decompression. For each successful emission of 6467 * header name/value pair, 6468 * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in 6469 * |*inflate_flags| and name/value pair is assigned to the |nv_out| 6470 * and the function returns. The caller must not free the members of 6471 * |nv_out|. 6472 * 6473 * The |nv_out| may include pointers to the memory region in the |in|. 6474 * The caller must retain the |in| while the |nv_out| is used. 6475 * 6476 * The application should call this function repeatedly until the 6477 * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and 6478 * return value is non-negative. This means the all input values are 6479 * processed successfully. Then the application must call 6480 * `nghttp2_hd_inflate_end_headers()` to prepare for the next header 6481 * block input. 6482 * 6483 * The caller can feed complete compressed header block. It also can 6484 * feed it in several chunks. The caller must set |in_final| to 6485 * nonzero if the given input is the last block of the compressed 6486 * header. 6487 * 6488 * This function returns the number of bytes processed if it succeeds, 6489 * or one of the following negative error codes: 6490 * 6491 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6492 * Out of memory. 6493 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6494 * Inflation process has failed. 6495 * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR` 6496 * The header field name or value is too large. 6497 * 6498 * Example follows:: 6499 * 6500 * int inflate_header_block(nghttp2_hd_inflater *hd_inflater, 6501 * uint8_t *in, size_t inlen, int final) 6502 * { 6503 * ssize_t rv; 6504 * 6505 * for(;;) { 6506 * nghttp2_nv nv; 6507 * int inflate_flags = 0; 6508 * 6509 * rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags, 6510 * in, inlen, final); 6511 * 6512 * if(rv < 0) { 6513 * fprintf(stderr, "inflate failed with error code %zd", rv); 6514 * return -1; 6515 * } 6516 * 6517 * in += rv; 6518 * inlen -= rv; 6519 * 6520 * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { 6521 * fwrite(nv.name, nv.namelen, 1, stderr); 6522 * fprintf(stderr, ": "); 6523 * fwrite(nv.value, nv.valuelen, 1, stderr); 6524 * fprintf(stderr, "\n"); 6525 * } 6526 * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { 6527 * nghttp2_hd_inflate_end_headers(hd_inflater); 6528 * break; 6529 * } 6530 * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 && 6531 * inlen == 0) { 6532 * break; 6533 * } 6534 * } 6535 * 6536 * return 0; 6537 * } 6538 * 6539 */ 6540 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, 6541 nghttp2_nv *nv_out, 6542 int *inflate_flags, uint8_t *in, 6543 size_t inlen, int in_final); 6544 6545 #endif /* NGHTTP2_NO_SSIZE_T */ 6546 6547 #ifndef NGHTTP2_NO_SSIZE_T 6548 /** 6549 * @function 6550 * 6551 * .. warning:: 6552 * 6553 * Deprecated. Use `nghttp2_hd_inflate_hd3()` instead. 6554 * 6555 * Inflates name/value block stored in |in| with length |inlen|. This 6556 * function performs decompression. For each successful emission of 6557 * header name/value pair, 6558 * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in 6559 * |*inflate_flags| and name/value pair is assigned to the |nv_out| 6560 * and the function returns. The caller must not free the members of 6561 * |nv_out|. 6562 * 6563 * The |nv_out| may include pointers to the memory region in the |in|. 6564 * The caller must retain the |in| while the |nv_out| is used. 6565 * 6566 * The application should call this function repeatedly until the 6567 * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and 6568 * return value is non-negative. If that happens, all given input 6569 * data (|inlen| bytes) are processed successfully. Then the 6570 * application must call `nghttp2_hd_inflate_end_headers()` to prepare 6571 * for the next header block input. 6572 * 6573 * In other words, if |in_final| is nonzero, and this function returns 6574 * |inlen|, you can assert that 6575 * :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in 6576 * |*inflate_flags|. 6577 * 6578 * The caller can feed complete compressed header block. It also can 6579 * feed it in several chunks. The caller must set |in_final| to 6580 * nonzero if the given input is the last block of the compressed 6581 * header. 6582 * 6583 * This function returns the number of bytes processed if it succeeds, 6584 * or one of the following negative error codes: 6585 * 6586 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6587 * Out of memory. 6588 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6589 * Inflation process has failed. 6590 * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR` 6591 * The header field name or value is too large. 6592 * 6593 * Example follows:: 6594 * 6595 * int inflate_header_block(nghttp2_hd_inflater *hd_inflater, 6596 * uint8_t *in, size_t inlen, int final) 6597 * { 6598 * ssize_t rv; 6599 * 6600 * for(;;) { 6601 * nghttp2_nv nv; 6602 * int inflate_flags = 0; 6603 * 6604 * rv = nghttp2_hd_inflate_hd2(hd_inflater, &nv, &inflate_flags, 6605 * in, inlen, final); 6606 * 6607 * if(rv < 0) { 6608 * fprintf(stderr, "inflate failed with error code %zd", rv); 6609 * return -1; 6610 * } 6611 * 6612 * in += rv; 6613 * inlen -= rv; 6614 * 6615 * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { 6616 * fwrite(nv.name, nv.namelen, 1, stderr); 6617 * fprintf(stderr, ": "); 6618 * fwrite(nv.value, nv.valuelen, 1, stderr); 6619 * fprintf(stderr, "\n"); 6620 * } 6621 * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { 6622 * nghttp2_hd_inflate_end_headers(hd_inflater); 6623 * break; 6624 * } 6625 * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 && 6626 * inlen == 0) { 6627 * break; 6628 * } 6629 * } 6630 * 6631 * return 0; 6632 * } 6633 * 6634 */ 6635 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, 6636 nghttp2_nv *nv_out, 6637 int *inflate_flags, 6638 const uint8_t *in, size_t inlen, 6639 int in_final); 6640 6641 #endif /* NGHTTP2_NO_SSIZE_T */ 6642 6643 /** 6644 * @function 6645 * 6646 * Inflates name/value block stored in |in| with length |inlen|. This 6647 * function performs decompression. For each successful emission of 6648 * header name/value pair, 6649 * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in 6650 * |*inflate_flags| and name/value pair is assigned to the |nv_out| 6651 * and the function returns. The caller must not free the members of 6652 * |nv_out|. 6653 * 6654 * The |nv_out| may include pointers to the memory region in the |in|. 6655 * The caller must retain the |in| while the |nv_out| is used. 6656 * 6657 * The application should call this function repeatedly until the 6658 * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and 6659 * return value is non-negative. If that happens, all given input 6660 * data (|inlen| bytes) are processed successfully. Then the 6661 * application must call `nghttp2_hd_inflate_end_headers()` to prepare 6662 * for the next header block input. 6663 * 6664 * In other words, if |in_final| is nonzero, and this function returns 6665 * |inlen|, you can assert that 6666 * :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in 6667 * |*inflate_flags|. 6668 * 6669 * The caller can feed complete compressed header block. It also can 6670 * feed it in several chunks. The caller must set |in_final| to 6671 * nonzero if the given input is the last block of the compressed 6672 * header. 6673 * 6674 * This function returns the number of bytes processed if it succeeds, 6675 * or one of the following negative error codes: 6676 * 6677 * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` 6678 * Out of memory. 6679 * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` 6680 * Inflation process has failed. 6681 * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR` 6682 * The header field name or value is too large. 6683 * 6684 * Example follows:: 6685 * 6686 * int inflate_header_block(nghttp2_hd_inflater *hd_inflater, 6687 * uint8_t *in, size_t inlen, int final) 6688 * { 6689 * nghttp2_ssize rv; 6690 * 6691 * for(;;) { 6692 * nghttp2_nv nv; 6693 * int inflate_flags = 0; 6694 * 6695 * rv = nghttp2_hd_inflate_hd3(hd_inflater, &nv, &inflate_flags, 6696 * in, inlen, final); 6697 * 6698 * if(rv < 0) { 6699 * fprintf(stderr, "inflate failed with error code %td", rv); 6700 * return -1; 6701 * } 6702 * 6703 * in += rv; 6704 * inlen -= rv; 6705 * 6706 * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { 6707 * fwrite(nv.name, nv.namelen, 1, stderr); 6708 * fprintf(stderr, ": "); 6709 * fwrite(nv.value, nv.valuelen, 1, stderr); 6710 * fprintf(stderr, "\n"); 6711 * } 6712 * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { 6713 * nghttp2_hd_inflate_end_headers(hd_inflater); 6714 * break; 6715 * } 6716 * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 && 6717 * inlen == 0) { 6718 * break; 6719 * } 6720 * } 6721 * 6722 * return 0; 6723 * } 6724 * 6725 */ 6726 NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_inflate_hd3( 6727 nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags, 6728 const uint8_t *in, size_t inlen, int in_final); 6729 6730 /** 6731 * @function 6732 * 6733 * Signals the end of decompression for one header block. 6734 * 6735 * This function returns 0 if it succeeds. Currently this function 6736 * always succeeds. 6737 */ 6738 NGHTTP2_EXTERN int 6739 nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater); 6740 6741 /** 6742 * @function 6743 * 6744 * Returns the number of entries that header table of |inflater| 6745 * contains. This is the sum of the number of static table and 6746 * dynamic table, so the return value is at least 61. 6747 */ 6748 NGHTTP2_EXTERN 6749 size_t nghttp2_hd_inflate_get_num_table_entries(nghttp2_hd_inflater *inflater); 6750 6751 /** 6752 * @function 6753 * 6754 * Returns the table entry denoted by |idx| from header table of 6755 * |inflater|. The |idx| is 1-based, and idx=1 returns first entry of 6756 * static table. idx=62 returns first entry of dynamic table if it 6757 * exists. Specifying idx=0 is error, and this function returns NULL. 6758 * If |idx| is strictly greater than the number of entries the tables 6759 * contain, this function returns NULL. 6760 */ 6761 NGHTTP2_EXTERN 6762 const nghttp2_nv * 6763 nghttp2_hd_inflate_get_table_entry(nghttp2_hd_inflater *inflater, size_t idx); 6764 6765 /** 6766 * @function 6767 * 6768 * Returns the used dynamic table size, including the overhead 32 6769 * bytes per entry described in RFC 7541. 6770 */ 6771 NGHTTP2_EXTERN 6772 size_t nghttp2_hd_inflate_get_dynamic_table_size(nghttp2_hd_inflater *inflater); 6773 6774 /** 6775 * @function 6776 * 6777 * Returns the maximum dynamic table size. 6778 */ 6779 NGHTTP2_EXTERN 6780 size_t 6781 nghttp2_hd_inflate_get_max_dynamic_table_size(nghttp2_hd_inflater *inflater); 6782 6783 struct nghttp2_stream; 6784 6785 /** 6786 * @struct 6787 * 6788 * The structure to represent HTTP/2 stream. The details of this 6789 * structure are intentionally hidden from the public API. 6790 */ 6791 typedef struct nghttp2_stream nghttp2_stream; 6792 6793 /** 6794 * @function 6795 * 6796 * Returns pointer to :type:`nghttp2_stream` object denoted by 6797 * |stream_id|. If stream was not found, returns NULL. 6798 * 6799 * Returns imaginary root stream (see 6800 * `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|. 6801 * 6802 * Unless |stream_id| == 0, the returned pointer is valid until next 6803 * call of `nghttp2_session_send()`, `nghttp2_session_mem_send2()`, 6804 * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv2()`. 6805 */ 6806 NGHTTP2_EXTERN nghttp2_stream * 6807 nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id); 6808 6809 /** 6810 * @enum 6811 * 6812 * State of stream as described in RFC 7540. 6813 */ 6814 typedef enum { 6815 /** 6816 * idle state. 6817 */ 6818 NGHTTP2_STREAM_STATE_IDLE = 1, 6819 /** 6820 * open state. 6821 */ 6822 NGHTTP2_STREAM_STATE_OPEN, 6823 /** 6824 * reserved (local) state. 6825 */ 6826 NGHTTP2_STREAM_STATE_RESERVED_LOCAL, 6827 /** 6828 * reserved (remote) state. 6829 */ 6830 NGHTTP2_STREAM_STATE_RESERVED_REMOTE, 6831 /** 6832 * half closed (local) state. 6833 */ 6834 NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL, 6835 /** 6836 * half closed (remote) state. 6837 */ 6838 NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE, 6839 /** 6840 * closed state. 6841 */ 6842 NGHTTP2_STREAM_STATE_CLOSED 6843 } nghttp2_stream_proto_state; 6844 6845 /** 6846 * @function 6847 * 6848 * Returns state of |stream|. The root stream retrieved by 6849 * `nghttp2_session_get_root_stream()` will have stream state 6850 * :enum:`nghttp2_stream_proto_state.NGHTTP2_STREAM_STATE_IDLE`. 6851 */ 6852 NGHTTP2_EXTERN nghttp2_stream_proto_state 6853 nghttp2_stream_get_state(nghttp2_stream *stream); 6854 6855 /** 6856 * @function 6857 * 6858 * .. warning:: 6859 * 6860 * Deprecated. :rfc:`7540` priorities are deprecated by 6861 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6862 * prioritization scheme. 6863 * 6864 * Returns root of dependency tree, which is imaginary stream with 6865 * stream ID 0. The returned pointer is valid until |session| is 6866 * freed by `nghttp2_session_del()`. 6867 */ 6868 NGHTTP2_EXTERN nghttp2_stream * 6869 nghttp2_session_get_root_stream(nghttp2_session *session); 6870 6871 /** 6872 * @function 6873 * 6874 * .. warning:: 6875 * 6876 * Deprecated. :rfc:`7540` priorities are deprecated by 6877 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6878 * prioritization scheme. In the future release after the end of 6879 * 2024, this function will always return NULL. 6880 * 6881 * Returns the parent stream of |stream| in dependency tree. Returns 6882 * NULL if there is no such stream. 6883 */ 6884 NGHTTP2_EXTERN nghttp2_stream * 6885 nghttp2_stream_get_parent(nghttp2_stream *stream); 6886 6887 NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream); 6888 6889 /** 6890 * @function 6891 * 6892 * .. warning:: 6893 * 6894 * Deprecated. :rfc:`7540` priorities are deprecated by 6895 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6896 * prioritization scheme. In the future release after the end of 6897 * 2024, this function will always return NULL. 6898 * 6899 * Returns the next sibling stream of |stream| in dependency tree. 6900 * Returns NULL if there is no such stream. 6901 */ 6902 NGHTTP2_EXTERN nghttp2_stream * 6903 nghttp2_stream_get_next_sibling(nghttp2_stream *stream); 6904 6905 /** 6906 * @function 6907 * 6908 * .. warning:: 6909 * 6910 * Deprecated. :rfc:`7540` priorities are deprecated by 6911 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6912 * prioritization scheme. In the future release after the end of 6913 * 2024, this function will always return NULL. 6914 * 6915 * Returns the previous sibling stream of |stream| in dependency tree. 6916 * Returns NULL if there is no such stream. 6917 */ 6918 NGHTTP2_EXTERN nghttp2_stream * 6919 nghttp2_stream_get_previous_sibling(nghttp2_stream *stream); 6920 6921 /** 6922 * @function 6923 * 6924 * .. warning:: 6925 * 6926 * Deprecated. :rfc:`7540` priorities are deprecated by 6927 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6928 * prioritization scheme. In the future release after the end of 6929 * 2024, this function will always return NULL. 6930 * 6931 * Returns the first child stream of |stream| in dependency tree. 6932 * Returns NULL if there is no such stream. 6933 */ 6934 NGHTTP2_EXTERN nghttp2_stream * 6935 nghttp2_stream_get_first_child(nghttp2_stream *stream); 6936 6937 /** 6938 * @function 6939 * 6940 * .. warning:: 6941 * 6942 * Deprecated. :rfc:`7540` priorities are deprecated by 6943 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6944 * prioritization scheme. In the future release after the end of 6945 * 2024, this function will always return 6946 * :macro:`NGHTTP2_DEFAULT_WEIGHT`. 6947 * 6948 * Returns dependency weight to the parent stream of |stream|. 6949 */ 6950 NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream); 6951 6952 /** 6953 * @function 6954 * 6955 * .. warning:: 6956 * 6957 * Deprecated. :rfc:`7540` priorities are deprecated by 6958 * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible 6959 * prioritization scheme. In the future release after the end of 6960 * 2024, this function will always return 0. 6961 * 6962 * Returns the sum of the weight for |stream|'s children. 6963 */ 6964 NGHTTP2_EXTERN int32_t 6965 nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream); 6966 6967 /** 6968 * @functypedef 6969 * 6970 * Callback function invoked when the library outputs debug logging. 6971 * The function is called with arguments suitable for ``vfprintf(3)`` 6972 * 6973 * The debug output is only enabled if the library is built with 6974 * ``DEBUGBUILD`` macro defined. 6975 */ 6976 typedef void (*nghttp2_debug_vprintf_callback)(const char *format, 6977 va_list args); 6978 6979 /** 6980 * @function 6981 * 6982 * Sets a debug output callback called by the library when built with 6983 * ``DEBUGBUILD`` macro defined. If this option is not used, debug 6984 * log is written into standard error output. 6985 * 6986 * For builds without ``DEBUGBUILD`` macro defined, this function is 6987 * noop. 6988 * 6989 * Note that building with ``DEBUGBUILD`` may cause significant 6990 * performance penalty to libnghttp2 because of extra processing. It 6991 * should be used for debugging purpose only. 6992 * 6993 * .. Warning:: 6994 * 6995 * Building with ``DEBUGBUILD`` may cause significant performance 6996 * penalty to libnghttp2 because of extra processing. It should be 6997 * used for debugging purpose only. We write this two times because 6998 * this is important. 6999 */ 7000 NGHTTP2_EXTERN void nghttp2_set_debug_vprintf_callback( 7001 nghttp2_debug_vprintf_callback debug_vprintf_callback); 7002 7003 #ifdef __cplusplus 7004 } 7005 #endif 7006 7007 #endif /* NGHTTP2_H */ 7008