/
nghttp2.h
5463 lines (5214 loc) Β· 186 KB
/
nghttp2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2013, 2014 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_H
#define NGHTTP2_H
/* Define WIN32 when build target is Win32 API (borrowed from
libcurl) */
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
/* Compatibility for non-Clang compilers */
#ifndef __has_declspec_attribute
# define __has_declspec_attribute(x) 0
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#if defined(_MSC_VER) && (_MSC_VER < 1800)
/* MSVC < 2013 does not have inttypes.h because it is not C99
compliant. See compiler macros and version number in
https://sourceforge.net/p/predef/wiki/Compilers/ */
# include <stdint.h>
#else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
# include <inttypes.h>
#endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
#include <sys/types.h>
#include <stdarg.h>
#include <nghttp2/nghttp2ver.h>
#ifdef NGHTTP2_STATICLIB
# define NGHTTP2_EXTERN
#elif defined(WIN32) || (__has_declspec_attribute(dllexport) && \
__has_declspec_attribute(dllimport))
# ifdef BUILDING_NGHTTP2
# define NGHTTP2_EXTERN __declspec(dllexport)
# else /* !BUILDING_NGHTTP2 */
# define NGHTTP2_EXTERN __declspec(dllimport)
# endif /* !BUILDING_NGHTTP2 */
#else /* !defined(WIN32) */
# ifdef BUILDING_NGHTTP2
# define NGHTTP2_EXTERN __attribute__((visibility("default")))
# else /* !BUILDING_NGHTTP2 */
# define NGHTTP2_EXTERN
# endif /* !BUILDING_NGHTTP2 */
#endif /* !defined(WIN32) */
/**
* @macro
*
* The protocol version identification string of this library
* supports. This identifier is used if HTTP/2 is used over TLS.
*/
#define NGHTTP2_PROTO_VERSION_ID "h2"
/**
* @macro
*
* The length of :macro:`NGHTTP2_PROTO_VERSION_ID`.
*/
#define NGHTTP2_PROTO_VERSION_ID_LEN 2
/**
* @macro
*
* The serialized form of ALPN protocol identifier this library
* supports. Notice that first byte is the length of following
* protocol identifier. This is the same wire format of `TLS ALPN
* extension <https://tools.ietf.org/html/rfc7301>`_. This is useful
* to process incoming ALPN tokens in wire format.
*/
#define NGHTTP2_PROTO_ALPN "\x2h2"
/**
* @macro
*
* The length of :macro:`NGHTTP2_PROTO_ALPN`.
*/
#define NGHTTP2_PROTO_ALPN_LEN (sizeof(NGHTTP2_PROTO_ALPN) - 1)
/**
* @macro
*
* The protocol version identification string of this library
* supports. This identifier is used if HTTP/2 is used over cleartext
* TCP.
*/
#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c"
/**
* @macro
*
* The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`.
*/
#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 3
struct nghttp2_session;
/**
* @struct
*
* The primary structure to hold the resources needed for a HTTP/2
* session. The details of this structure are intentionally hidden
* from the public API.
*/
typedef struct nghttp2_session nghttp2_session;
/**
* @macro
*
* The age of :type:`nghttp2_info`
*/
#define NGHTTP2_VERSION_AGE 1
/**
* @struct
*
* This struct is what `nghttp2_version()` returns. It holds
* information about the particular nghttp2 version.
*/
typedef struct {
/**
* Age of this struct. This instance of nghttp2 sets it to
* :macro:`NGHTTP2_VERSION_AGE` but a future version may bump it and
* add more struct fields at the bottom
*/
int age;
/**
* the :macro:`NGHTTP2_VERSION_NUM` number (since age ==1)
*/
int version_num;
/**
* points to the :macro:`NGHTTP2_VERSION` string (since age ==1)
*/
const char *version_str;
/**
* points to the :macro:`NGHTTP2_PROTO_VERSION_ID` string this
* instance implements (since age ==1)
*/
const char *proto_str;
/* -------- the above fields all exist when age == 1 */
} nghttp2_info;
/**
* @macro
*
* The default weight of stream dependency.
*/
#define NGHTTP2_DEFAULT_WEIGHT 16
/**
* @macro
*
* The maximum weight of stream dependency.
*/
#define NGHTTP2_MAX_WEIGHT 256
/**
* @macro
*
* The minimum weight of stream dependency.
*/
#define NGHTTP2_MIN_WEIGHT 1
/**
* @macro
*
* The maximum window size
*/
#define NGHTTP2_MAX_WINDOW_SIZE ((int32_t)((1U << 31) - 1))
/**
* @macro
*
* The initial window size for stream level flow control.
*/
#define NGHTTP2_INITIAL_WINDOW_SIZE ((1 << 16) - 1)
/**
* @macro
*
* The initial window size for connection level flow control.
*/
#define NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE ((1 << 16) - 1)
/**
* @macro
*
* The default header table size.
*/
#define NGHTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12)
/**
* @macro
*
* The client magic string, which is the first 24 bytes byte string of
* client connection preface.
*/
#define NGHTTP2_CLIENT_MAGIC "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
/**
* @macro
*
* The length of :macro:`NGHTTP2_CLIENT_MAGIC`.
*/
#define NGHTTP2_CLIENT_MAGIC_LEN 24
/**
* @enum
*
* Error codes used in this library. The code range is [-999, -500],
* inclusive. The following values are defined:
*/
typedef enum {
/**
* Invalid argument passed.
*/
NGHTTP2_ERR_INVALID_ARGUMENT = -501,
/**
* Out of buffer space.
*/
NGHTTP2_ERR_BUFFER_ERROR = -502,
/**
* The specified protocol version is not supported.
*/
NGHTTP2_ERR_UNSUPPORTED_VERSION = -503,
/**
* Used as a return value from :type:`nghttp2_send_callback`,
* :type:`nghttp2_recv_callback` and
* :type:`nghttp2_send_data_callback` to indicate that the operation
* would block.
*/
NGHTTP2_ERR_WOULDBLOCK = -504,
/**
* General protocol error
*/
NGHTTP2_ERR_PROTO = -505,
/**
* The frame is invalid.
*/
NGHTTP2_ERR_INVALID_FRAME = -506,
/**
* The peer performed a shutdown on the connection.
*/
NGHTTP2_ERR_EOF = -507,
/**
* Used as a return value from
* :func:`nghttp2_data_source_read_callback` to indicate that data
* transfer is postponed. See
* :func:`nghttp2_data_source_read_callback` for details.
*/
NGHTTP2_ERR_DEFERRED = -508,
/**
* Stream ID has reached the maximum value. Therefore no stream ID
* is available.
*/
NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509,
/**
* The stream is already closed; or the stream ID is invalid.
*/
NGHTTP2_ERR_STREAM_CLOSED = -510,
/**
* RST_STREAM has been added to the outbound queue. The stream is
* in closing state.
*/
NGHTTP2_ERR_STREAM_CLOSING = -511,
/**
* The transmission is not allowed for this stream (e.g., a frame
* with END_STREAM flag set has already sent).
*/
NGHTTP2_ERR_STREAM_SHUT_WR = -512,
/**
* The stream ID is invalid.
*/
NGHTTP2_ERR_INVALID_STREAM_ID = -513,
/**
* The state of the stream is not valid (e.g., DATA cannot be sent
* to the stream if response HEADERS has not been sent).
*/
NGHTTP2_ERR_INVALID_STREAM_STATE = -514,
/**
* Another DATA frame has already been deferred.
*/
NGHTTP2_ERR_DEFERRED_DATA_EXIST = -515,
/**
* Starting new stream is not allowed (e.g., GOAWAY has been sent
* and/or received).
*/
NGHTTP2_ERR_START_STREAM_NOT_ALLOWED = -516,
/**
* GOAWAY has already been sent.
*/
NGHTTP2_ERR_GOAWAY_ALREADY_SENT = -517,
/**
* The received frame contains the invalid header block (e.g., There
* are duplicate header names; or the header names are not encoded
* in US-ASCII character set and not lower cased; or the header name
* is zero-length string; or the header value contains multiple
* in-sequence NUL bytes).
*/
NGHTTP2_ERR_INVALID_HEADER_BLOCK = -518,
/**
* Indicates that the context is not suitable to perform the
* requested operation.
*/
NGHTTP2_ERR_INVALID_STATE = -519,
/**
* The user callback function failed due to the temporal error.
*/
NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE = -521,
/**
* The length of the frame is invalid, either too large or too small.
*/
NGHTTP2_ERR_FRAME_SIZE_ERROR = -522,
/**
* Header block inflate/deflate error.
*/
NGHTTP2_ERR_HEADER_COMP = -523,
/**
* Flow control error
*/
NGHTTP2_ERR_FLOW_CONTROL = -524,
/**
* Insufficient buffer size given to function.
*/
NGHTTP2_ERR_INSUFF_BUFSIZE = -525,
/**
* Callback was paused by the application
*/
NGHTTP2_ERR_PAUSE = -526,
/**
* There are too many in-flight SETTING frame and no more
* transmission of SETTINGS is allowed.
*/
NGHTTP2_ERR_TOO_MANY_INFLIGHT_SETTINGS = -527,
/**
* The server push is disabled.
*/
NGHTTP2_ERR_PUSH_DISABLED = -528,
/**
* DATA or HEADERS frame for a given stream has been already
* submitted and has not been fully processed yet. Application
* should wait for the transmission of the previously submitted
* frame before submitting another.
*/
NGHTTP2_ERR_DATA_EXIST = -529,
/**
* The current session is closing due to a connection error or
* `nghttp2_session_terminate_session()` is called.
*/
NGHTTP2_ERR_SESSION_CLOSING = -530,
/**
* Invalid HTTP header field was received and stream is going to be
* closed.
*/
NGHTTP2_ERR_HTTP_HEADER = -531,
/**
* Violation in HTTP messaging rule.
*/
NGHTTP2_ERR_HTTP_MESSAGING = -532,
/**
* Stream was refused.
*/
NGHTTP2_ERR_REFUSED_STREAM = -533,
/**
* Unexpected internal error, but recovered.
*/
NGHTTP2_ERR_INTERNAL = -534,
/**
* Indicates that a processing was canceled.
*/
NGHTTP2_ERR_CANCEL = -535,
/**
* When a local endpoint expects to receive SETTINGS frame, it
* receives an other type of frame.
*/
NGHTTP2_ERR_SETTINGS_EXPECTED = -536,
/**
* The errors < :enum:`NGHTTP2_ERR_FATAL` mean that the library is
* under unexpected condition and processing was terminated (e.g.,
* out of memory). If application receives this error code, it must
* stop using that :type:`nghttp2_session` object and only allowed
* operation for that object is deallocate it using
* `nghttp2_session_del()`.
*/
NGHTTP2_ERR_FATAL = -900,
/**
* Out of memory. This is a fatal error.
*/
NGHTTP2_ERR_NOMEM = -901,
/**
* The user callback function failed. This is a fatal error.
*/
NGHTTP2_ERR_CALLBACK_FAILURE = -902,
/**
* Invalid client magic (see :macro:`NGHTTP2_CLIENT_MAGIC`) was
* received and further processing is not possible.
*/
NGHTTP2_ERR_BAD_CLIENT_MAGIC = -903,
/**
* Possible flooding by peer was detected in this HTTP/2 session.
* Flooding is measured by how many PING and SETTINGS frames with
* ACK flag set are queued for transmission. These frames are
* response for the peer initiated frames, and peer can cause memory
* exhaustion on server side to send these frames forever and does
* not read network.
*/
NGHTTP2_ERR_FLOODED = -904
} nghttp2_error;
/**
* @struct
*
* The object representing single contiguous buffer.
*/
typedef struct {
/**
* The pointer to the buffer.
*/
uint8_t *base;
/**
* The length of the buffer.
*/
size_t len;
} nghttp2_vec;
struct nghttp2_rcbuf;
/**
* @struct
*
* The object representing reference counted buffer. The details of
* this structure are intentionally hidden from the public API.
*/
typedef struct nghttp2_rcbuf nghttp2_rcbuf;
/**
* @function
*
* Increments the reference count of |rcbuf| by 1.
*/
NGHTTP2_EXTERN void nghttp2_rcbuf_incref(nghttp2_rcbuf *rcbuf);
/**
* @function
*
* Decrements the reference count of |rcbuf| by 1. If the reference
* count becomes zero, the object pointed by |rcbuf| will be freed.
* In this case, application must not use |rcbuf| again.
*/
NGHTTP2_EXTERN void nghttp2_rcbuf_decref(nghttp2_rcbuf *rcbuf);
/**
* @function
*
* Returns the underlying buffer managed by |rcbuf|.
*/
NGHTTP2_EXTERN nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf);
/**
* @function
*
* Returns nonzero if the underlying buffer is statically allocated,
* and 0 otherwise. This can be useful for language bindings that wish
* to avoid creating duplicate strings for these buffers.
*/
NGHTTP2_EXTERN int nghttp2_rcbuf_is_static(const nghttp2_rcbuf *rcbuf);
/**
* @enum
*
* The flags for header field name/value pair.
*/
typedef enum {
/**
* No flag set.
*/
NGHTTP2_NV_FLAG_NONE = 0,
/**
* Indicates that this name/value pair must not be indexed ("Literal
* Header Field never Indexed" representation must be used in HPACK
* encoding). Other implementation calls this bit as "sensitive".
*/
NGHTTP2_NV_FLAG_NO_INDEX = 0x01,
/**
* This flag is set solely by application. If this flag is set, the
* library does not make a copy of header field name. This could
* improve performance.
*/
NGHTTP2_NV_FLAG_NO_COPY_NAME = 0x02,
/**
* This flag is set solely by application. If this flag is set, the
* library does not make a copy of header field value. This could
* improve performance.
*/
NGHTTP2_NV_FLAG_NO_COPY_VALUE = 0x04
} nghttp2_nv_flag;
/**
* @struct
*
* The name/value pair, which mainly used to represent header fields.
*/
typedef struct {
/**
* The |name| byte string. If this struct is presented from library
* (e.g., :type:`nghttp2_on_frame_recv_callback`), |name| is
* guaranteed to be NULL-terminated. For some callbacks
* (:type:`nghttp2_before_frame_send_callback`,
* :type:`nghttp2_on_frame_send_callback`, and
* :type:`nghttp2_on_frame_not_send_callback`), it may not be
* NULL-terminated if header field is passed from application with
* the flag :enum:`NGHTTP2_NV_FLAG_NO_COPY_NAME`). When application
* is constructing this struct, |name| is not required to be
* NULL-terminated.
*/
uint8_t *name;
/**
* The |value| byte string. If this struct is presented from
* library (e.g., :type:`nghttp2_on_frame_recv_callback`), |value|
* is guaranteed to be NULL-terminated. For some callbacks
* (:type:`nghttp2_before_frame_send_callback`,
* :type:`nghttp2_on_frame_send_callback`, and
* :type:`nghttp2_on_frame_not_send_callback`), it may not be
* NULL-terminated if header field is passed from application with
* the flag :enum:`NGHTTP2_NV_FLAG_NO_COPY_VALUE`). When
* application is constructing this struct, |value| is not required
* to be NULL-terminated.
*/
uint8_t *value;
/**
* The length of the |name|, excluding terminating NULL.
*/
size_t namelen;
/**
* The length of the |value|, excluding terminating NULL.
*/
size_t valuelen;
/**
* Bitwise OR of one or more of :type:`nghttp2_nv_flag`.
*/
uint8_t flags;
} nghttp2_nv;
/**
* @enum
*
* The frame types in HTTP/2 specification.
*/
typedef enum {
/**
* The DATA frame.
*/
NGHTTP2_DATA = 0,
/**
* The HEADERS frame.
*/
NGHTTP2_HEADERS = 0x01,
/**
* The PRIORITY frame.
*/
NGHTTP2_PRIORITY = 0x02,
/**
* The RST_STREAM frame.
*/
NGHTTP2_RST_STREAM = 0x03,
/**
* The SETTINGS frame.
*/
NGHTTP2_SETTINGS = 0x04,
/**
* The PUSH_PROMISE frame.
*/
NGHTTP2_PUSH_PROMISE = 0x05,
/**
* The PING frame.
*/
NGHTTP2_PING = 0x06,
/**
* The GOAWAY frame.
*/
NGHTTP2_GOAWAY = 0x07,
/**
* The WINDOW_UPDATE frame.
*/
NGHTTP2_WINDOW_UPDATE = 0x08,
/**
* The CONTINUATION frame. This frame type won't be passed to any
* callbacks because the library processes this frame type and its
* preceding HEADERS/PUSH_PROMISE as a single frame.
*/
NGHTTP2_CONTINUATION = 0x09,
/**
* The ALTSVC frame, which is defined in `RFC 7383
* <https://tools.ietf.org/html/rfc7838#section-4>`_.
*/
NGHTTP2_ALTSVC = 0x0a,
/**
* The ORIGIN frame, which is defined by `RFC 8336
* <https://tools.ietf.org/html/rfc8336>`_.
*/
NGHTTP2_ORIGIN = 0x0c
} nghttp2_frame_type;
/**
* @enum
*
* The flags for HTTP/2 frames. This enum defines all flags for all
* frames.
*/
typedef enum {
/**
* No flag set.
*/
NGHTTP2_FLAG_NONE = 0,
/**
* The END_STREAM flag.
*/
NGHTTP2_FLAG_END_STREAM = 0x01,
/**
* The END_HEADERS flag.
*/
NGHTTP2_FLAG_END_HEADERS = 0x04,
/**
* The ACK flag.
*/
NGHTTP2_FLAG_ACK = 0x01,
/**
* The PADDED flag.
*/
NGHTTP2_FLAG_PADDED = 0x08,
/**
* The PRIORITY flag.
*/
NGHTTP2_FLAG_PRIORITY = 0x20
} nghttp2_flag;
/**
* @enum
* The SETTINGS ID.
*/
typedef enum {
/**
* SETTINGS_HEADER_TABLE_SIZE
*/
NGHTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x01,
/**
* SETTINGS_ENABLE_PUSH
*/
NGHTTP2_SETTINGS_ENABLE_PUSH = 0x02,
/**
* SETTINGS_MAX_CONCURRENT_STREAMS
*/
NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x03,
/**
* SETTINGS_INITIAL_WINDOW_SIZE
*/
NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x04,
/**
* SETTINGS_MAX_FRAME_SIZE
*/
NGHTTP2_SETTINGS_MAX_FRAME_SIZE = 0x05,
/**
* SETTINGS_MAX_HEADER_LIST_SIZE
*/
NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x06,
/**
* SETTINGS_ENABLE_CONNECT_PROTOCOL
* (`RFC 8441 <https://tools.ietf.org/html/rfc8441>`_)
*/
NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL = 0x08
} nghttp2_settings_id;
/* Note: If we add SETTINGS, update the capacity of
NGHTTP2_INBOUND_NUM_IV as well */
/**
* @macro
*
* .. warning::
*
* Deprecated. The initial max concurrent streams is 0xffffffffu.
*
* Default maximum number of incoming concurrent streams. Use
* `nghttp2_submit_settings()` with
* :enum:`NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS` to change the
* maximum number of incoming concurrent streams.
*
* .. note::
*
* The maximum number of outgoing concurrent streams is 100 by
* default.
*/
#define NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1)
/**
* @enum
* The status codes for the RST_STREAM and GOAWAY frames.
*/
typedef enum {
/**
* No errors.
*/
NGHTTP2_NO_ERROR = 0x00,
/**
* PROTOCOL_ERROR
*/
NGHTTP2_PROTOCOL_ERROR = 0x01,
/**
* INTERNAL_ERROR
*/
NGHTTP2_INTERNAL_ERROR = 0x02,
/**
* FLOW_CONTROL_ERROR
*/
NGHTTP2_FLOW_CONTROL_ERROR = 0x03,
/**
* SETTINGS_TIMEOUT
*/
NGHTTP2_SETTINGS_TIMEOUT = 0x04,
/**
* STREAM_CLOSED
*/
NGHTTP2_STREAM_CLOSED = 0x05,
/**
* FRAME_SIZE_ERROR
*/
NGHTTP2_FRAME_SIZE_ERROR = 0x06,
/**
* REFUSED_STREAM
*/
NGHTTP2_REFUSED_STREAM = 0x07,
/**
* CANCEL
*/
NGHTTP2_CANCEL = 0x08,
/**
* COMPRESSION_ERROR
*/
NGHTTP2_COMPRESSION_ERROR = 0x09,
/**
* CONNECT_ERROR
*/
NGHTTP2_CONNECT_ERROR = 0x0a,
/**
* ENHANCE_YOUR_CALM
*/
NGHTTP2_ENHANCE_YOUR_CALM = 0x0b,
/**
* INADEQUATE_SECURITY
*/
NGHTTP2_INADEQUATE_SECURITY = 0x0c,
/**
* HTTP_1_1_REQUIRED
*/
NGHTTP2_HTTP_1_1_REQUIRED = 0x0d
} nghttp2_error_code;
/**
* @struct
* The frame header.
*/
typedef struct {
/**
* The length field of this frame, excluding frame header.
*/
size_t length;
/**
* The stream identifier (aka, stream ID)
*/
int32_t stream_id;
/**
* The type of this frame. See `nghttp2_frame_type`.
*/
uint8_t type;
/**
* The flags.
*/
uint8_t flags;
/**
* Reserved bit in frame header. Currently, this is always set to 0
* and application should not expect something useful in here.
*/
uint8_t reserved;
} nghttp2_frame_hd;
/**
* @union
*
* This union represents the some kind of data source passed to
* :type:`nghttp2_data_source_read_callback`.
*/
typedef union {
/**
* The integer field, suitable for a file descriptor.
*/
int fd;
/**
* The pointer to an arbitrary object.
*/
void *ptr;
} nghttp2_data_source;
/**
* @enum
*
* The flags used to set in |data_flags| output parameter in
* :type:`nghttp2_data_source_read_callback`.
*/
typedef enum {
/**
* No flag set.
*/
NGHTTP2_DATA_FLAG_NONE = 0,
/**
* Indicates EOF was sensed.
*/
NGHTTP2_DATA_FLAG_EOF = 0x01,
/**
* Indicates that END_STREAM flag must not be set even if
* NGHTTP2_DATA_FLAG_EOF is set. Usually this flag is used to send
* trailer fields with `nghttp2_submit_request()` or
* `nghttp2_submit_response()`.
*/
NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02,
/**
* Indicates that application will send complete DATA frame in
* :type:`nghttp2_send_data_callback`.
*/
NGHTTP2_DATA_FLAG_NO_COPY = 0x04
} nghttp2_data_flag;
/**
* @functypedef
*
* Callback function invoked when the library wants to read data from
* the |source|. The read data is sent in the stream |stream_id|.
* The implementation of this function must read at most |length|
* bytes of data from |source| (or possibly other places) and store
* them in |buf| and return number of data stored in |buf|. If EOF is
* reached, set :enum:`NGHTTP2_DATA_FLAG_EOF` flag in |*data_flags|.
*
* Sometime it is desirable to avoid copying data into |buf| and let
* application to send data directly. To achieve this, set
* :enum:`NGHTTP2_DATA_FLAG_NO_COPY` to |*data_flags| (and possibly
* other flags, just like when we do copy), and return the number of
* bytes to send without copying data into |buf|. The library, seeing
* :enum:`NGHTTP2_DATA_FLAG_NO_COPY`, will invoke
* :type:`nghttp2_send_data_callback`. The application must send
* complete DATA frame in that callback.
*
* If this callback is set by `nghttp2_submit_request()`,
* `nghttp2_submit_response()` or `nghttp2_submit_headers()` and
* `nghttp2_submit_data()` with flag parameter
* :enum:`NGHTTP2_FLAG_END_STREAM` set, and
* :enum:`NGHTTP2_DATA_FLAG_EOF` flag is set to |*data_flags|, DATA
* frame will have END_STREAM flag set. Usually, this is expected
* behaviour and all are fine. One exception is send trailer fields.
* You cannot send trailer fields after sending frame with END_STREAM
* set. To avoid this problem, one can set
* :enum:`NGHTTP2_DATA_FLAG_NO_END_STREAM` along with
* :enum:`NGHTTP2_DATA_FLAG_EOF` to signal the library not to set
* END_STREAM in DATA frame. Then application can use
* `nghttp2_submit_trailer()` to send trailer fields.
* `nghttp2_submit_trailer()` can be called inside this callback.
*
* If the application wants to postpone DATA frames (e.g.,
* asynchronous I/O, or reading data blocks for long time), it is
* achieved by returning :enum:`NGHTTP2_ERR_DEFERRED` without reading
* any data in this invocation. The library removes DATA frame from
* the outgoing queue temporarily. To move back deferred DATA frame
* to outgoing queue, call `nghttp2_session_resume_data()`.
*
* By default, |length| is limited to 16KiB at maximum. If peer
* allows larger frames, application can enlarge transmission buffer
* size. See :type:`nghttp2_data_source_read_length_callback` for
* more details.
*
* If the application just wants to return from
* `nghttp2_session_send()` or `nghttp2_session_mem_send()` without
* sending anything, return :enum:`NGHTTP2_ERR_PAUSE`.
*
* In case of error, there are 2 choices. Returning
* :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close the stream
* by issuing RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. If a
* different error code is desirable, use
* `nghttp2_submit_rst_stream()` with a desired error code and then
* return :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. Returning
* :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the entire session
* failure.
*/
typedef ssize_t (*nghttp2_data_source_read_callback)(
nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length,
uint32_t *data_flags, nghttp2_data_source *source, void *user_data);
/**
* @struct
*
* This struct represents the data source and the way to read a chunk
* of data from it.
*/
typedef struct {
/**
* The data source.
*/
nghttp2_data_source source;
/**
* The callback function to read a chunk of data from the |source|.
*/
nghttp2_data_source_read_callback read_callback;
} nghttp2_data_provider;
/**
* @struct
*
* The DATA frame. The received data is delivered via
* :type:`nghttp2_on_data_chunk_recv_callback`.
*/
typedef struct {
nghttp2_frame_hd hd;
/**
* The length of the padding in this frame. This includes PAD_HIGH
* and PAD_LOW.
*/
size_t padlen;
} nghttp2_data;
/**
* @enum
*
* The category of HEADERS, which indicates the role of the frame. In
* HTTP/2 spec, request, response, push response and other arbitrary
* headers (e.g., trailer fields) are all called just HEADERS. To
* give the application the role of incoming HEADERS frame, we define
* several categories.
*/
typedef enum {
/**
* The HEADERS frame is opening new stream, which is analogous to
* SYN_STREAM in SPDY.
*/
NGHTTP2_HCAT_REQUEST = 0,
/**
* The HEADERS frame is the first response headers, which is
* analogous to SYN_REPLY in SPDY.
*/
NGHTTP2_HCAT_RESPONSE = 1,
/**
* The HEADERS frame is the first headers sent against reserved
* stream.
*/
NGHTTP2_HCAT_PUSH_RESPONSE = 2,
/**
* The HEADERS frame which does not apply for the above categories,
* which is analogous to HEADERS in SPDY. If non-final response
* (e.g., status 1xx) is used, final response HEADERS frame will be
* categorized here.
*/
NGHTTP2_HCAT_HEADERS = 3
} nghttp2_headers_category;
/**
* @struct
*
* The structure to specify stream dependency.
*/
typedef struct {
/**
* The stream ID of the stream to depend on. Specifying 0 makes
* stream not depend any other stream.
*/
int32_t stream_id;
/**
* The weight of this dependency.
*/
int32_t weight;
/**
* nonzero means exclusive dependency