1e18a033bSKonstantin Ananyev/*
2e18a033bSKonstantin Ananyev * Copyright (C) Nginx, Inc.
3e18a033bSKonstantin Ananyev * Copyright (C) Valentin V. Bartenev
4e18a033bSKonstantin Ananyev */
5e18a033bSKonstantin Ananyev
6e18a033bSKonstantin Ananyev
7e18a033bSKonstantin Ananyev#ifndef _NGX_HTTP_V2_H_INCLUDED_
8e18a033bSKonstantin Ananyev#define _NGX_HTTP_V2_H_INCLUDED_
9e18a033bSKonstantin Ananyev
10e18a033bSKonstantin Ananyev
11e18a033bSKonstantin Ananyev#include <ngx_config.h>
12e18a033bSKonstantin Ananyev#include <ngx_core.h>
13e18a033bSKonstantin Ananyev#include <ngx_http.h>
14e18a033bSKonstantin Ananyev
15e18a033bSKonstantin Ananyev
16e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_ALPN_ADVERTISE       "\x02h2"
17e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_NPN_ADVERTISE        NGX_HTTP_V2_ALPN_ADVERTISE
18e18a033bSKonstantin Ananyev
19e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_STATE_BUFFER_SIZE    16
20e18a033bSKonstantin Ananyev
21e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_MAX_FRAME_SIZE       ((1 << 24) - 1)
22e18a033bSKonstantin Ananyev
23e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_INT_OCTETS           4
24e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_MAX_FIELD                                                 \
25e18a033bSKonstantin Ananyev    (127 + (1 << (NGX_HTTP_V2_INT_OCTETS - 1) * 7) - 1)
26e18a033bSKonstantin Ananyev
27e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_FRAME_HEADER_SIZE    9
28e18a033bSKonstantin Ananyev
29e18a033bSKonstantin Ananyev/* frame types */
30e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_DATA_FRAME           0x0
31e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_HEADERS_FRAME        0x1
32e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_PRIORITY_FRAME       0x2
33e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_RST_STREAM_FRAME     0x3
34e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_SETTINGS_FRAME       0x4
35e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_PUSH_PROMISE_FRAME   0x5
36e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_PING_FRAME           0x6
37e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_GOAWAY_FRAME         0x7
38e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_WINDOW_UPDATE_FRAME  0x8
39e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_CONTINUATION_FRAME   0x9
40e18a033bSKonstantin Ananyev
41e18a033bSKonstantin Ananyev/* frame flags */
42e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_NO_FLAG              0x00
43e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_ACK_FLAG             0x01
44e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_END_STREAM_FLAG      0x01
45e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_END_HEADERS_FLAG     0x04
46e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_PADDED_FLAG          0x08
47e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_PRIORITY_FLAG        0x20
48e18a033bSKonstantin Ananyev
49e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_MAX_WINDOW           ((1U << 31) - 1)
50e18a033bSKonstantin Ananyev#define NGX_HTTP_V2_DEFAULT_WINDOW       65535
51e18a033bSKonstantin Ananyev
52e18a033bSKonstantin Ananyev
53e18a033bSKonstantin Ananyevtypedef struct ngx_http_v2_connection_s   ngx_http_v2_connection_t;
54e18a033bSKonstantin Ananyevtypedef struct ngx_http_v2_node_s         ngx_http_v2_node_t;
55e18a033bSKonstantin Ananyevtypedef struct ngx_http_v2_out_frame_s    ngx_http_v2_out_frame_t;
56e18a033bSKonstantin Ananyev
57e18a033bSKonstantin Ananyev
58e18a033bSKonstantin Ananyevtypedef u_char *(*ngx_http_v2_handler_pt) (ngx_http_v2_connection_t *h2c,
59e18a033bSKonstantin Ananyev    u_char *pos, u_char *end);
60e18a033bSKonstantin Ananyev
61e18a033bSKonstantin Ananyev
62e18a033bSKonstantin Ananyevtypedef struct {
63e18a033bSKonstantin Ananyev    ngx_str_t                        name;
64e18a033bSKonstantin Ananyev    ngx_str_t                        value;
65e18a033bSKonstantin Ananyev} ngx_http_v2_header_t;
66e18a033bSKonstantin Ananyev
67e18a033bSKonstantin Ananyev
68e18a033bSKonstantin Ananyevtypedef struct {
69e18a033bSKonstantin Ananyev    ngx_uint_t                       sid;
70e18a033bSKonstantin Ananyev    size_t                           length;
71e18a033bSKonstantin Ananyev    size_t                           padding;
72e18a033bSKonstantin Ananyev    unsigned                         flags:8;
73e18a033bSKonstantin Ananyev
74e18a033bSKonstantin Ananyev    unsigned                         incomplete:1;
75e18a033bSKonstantin Ananyev    unsigned                         keep_pool:1;
76e18a033bSKonstantin Ananyev
77e18a033bSKonstantin Ananyev    /* HPACK */
78e18a033bSKonstantin Ananyev    unsigned                         parse_name:1;
79e18a033bSKonstantin Ananyev    unsigned                         parse_value:1;
80e18a033bSKonstantin Ananyev    unsigned                         index:1;
81e18a033bSKonstantin Ananyev    ngx_http_v2_header_t             header;
82e18a033bSKonstantin Ananyev    size_t                           header_limit;
83e18a033bSKonstantin Ananyev    u_char                           field_state;
84e18a033bSKonstantin Ananyev    u_char                          *field_start;
85e18a033bSKonstantin Ananyev    u_char                          *field_end;
86e18a033bSKonstantin Ananyev    size_t                           field_rest;
87e18a033bSKonstantin Ananyev    ngx_pool_t                      *pool;
88e18a033bSKonstantin Ananyev
89e18a033bSKonstantin Ananyev    ngx_http_v2_stream_t            *stream;
90e18a033bSKonstantin Ananyev
91e18a033bSKonstantin Ananyev    u_char                           buffer[NGX_HTTP_V2_STATE_BUFFER_SIZE];
92e18a033bSKonstantin Ananyev    size_t                           buffer_used;
93e18a033bSKonstantin Ananyev    ngx_http_v2_handler_pt           handler;
94e18a033bSKonstantin Ananyev} ngx_http_v2_state_t;
95e18a033bSKonstantin Ananyev
96e18a033bSKonstantin Ananyev
97e18a033bSKonstantin Ananyev
98e18a033bSKonstantin Ananyevtypedef struct {
99e18a033bSKonstantin Ananyev    ngx_http_v2_header_t           **entries;
100e18a033bSKonstantin Ananyev
101e18a033bSKonstantin Ananyev    ngx_uint_t                       added;
102e18a033bSKonstantin Ananyev    ngx_uint_t                       deleted;
103e18a033bSKonstantin Ananyev    ngx_uint_t                       reused;
104e18a033bSKonstantin Ananyev    ngx_uint_t                       allocated;
105e18a033bSKonstantin Ananyev
106e18a033bSKonstantin Ananyev    size_t                           size;
107e18a033bSKonstantin Ananyev    size_t                           free;
108e18a033bSKonstantin Ananyev    u_char                          *storage;
109e18a033bSKonstantin Ananyev    u_char                          *pos;
110e18a033bSKonstantin Ananyev} ngx_http_v2_hpack_t;
111e18a033bSKonstantin Ananyev
112e18a033bSKonstantin Ananyev
113e18a033bSKonstantin Ananyevstruct ngx_http_v2_connection_s {
114e18a033bSKonstantin Ananyev    ngx_connection_t                *connection;
115e18a033bSKonstantin Ananyev    ngx_http_connection_t           *http_connection;
116e18a033bSKonstantin Ananyev
117e18a033bSKonstantin Ananyev    ngx_uint_t                       processing;
118e18a033bSKonstantin Ananyev
119e18a033bSKonstantin Ananyev    size_t                           send_window;
120e18a033bSKonstantin Ananyev    size_t                           recv_window;
121e18a033bSKonstantin Ananyev    size_t                           init_window;
122e18a033bSKonstantin Ananyev
123e18a033bSKonstantin Ananyev    size_t                           frame_size;
124e18a033bSKonstantin Ananyev
125e18a033bSKonstantin Ananyev    ngx_queue_t                      waiting;
126e18a033bSKonstantin Ananyev
127e18a033bSKonstantin Ananyev    ngx_http_v2_state_t              state;
128e18a033bSKonstantin Ananyev
129e18a033bSKonstantin Ananyev    ngx_http_v2_hpack_t              hpack;
130e18a033bSKonstantin Ananyev
131e18a033bSKonstantin Ananyev    ngx_pool_t                      *pool;
132e18a033bSKonstantin Ananyev
133e18a033bSKonstantin Ananyev    ngx_http_v2_out_frame_t         *free_frames;
134e18a033bSKonstantin Ananyev    ngx_connection_t                *free_fake_connections;
135e18a033bSKonstantin Ananyev
136e18a033bSKonstantin Ananyev    ngx_http_v2_node_t             **streams_index;
137e18a033bSKonstantin Ananyev
138e18a033bSKonstantin Ananyev    ngx_http_v2_out_frame_t         *last_out;
139e18a033bSKonstantin Ananyev
140e18a033bSKonstantin Ananyev    ngx_queue_t                      dependencies;
141e18a033bSKonstantin Ananyev    ngx_queue_t                      closed;
142e18a033bSKonstantin Ananyev
143e18a033bSKonstantin Ananyev    ngx_uint_t                       last_sid;
144e18a033bSKonstantin Ananyev
145e18a033bSKonstantin Ananyev    unsigned                         closed_nodes:8;
146e18a033bSKonstantin Ananyev    unsigned                         settings_ack:1;
147e18a033bSKonstantin Ananyev    unsigned                         blocked:1;
148e18a033bSKonstantin Ananyev    unsigned                         goaway:1;
149e18a033bSKonstantin Ananyev};
150e18a033bSKonstantin Ananyev
151e18a033bSKonstantin Ananyev
152e18a033bSKonstantin Ananyevstruct ngx_http_v2_node_s {
153e18a033bSKonstantin Ananyev    ngx_uint_t                       id;
154e18a033bSKonstantin Ananyev    ngx_http_v2_node_t              *index;
155e18a033bSKonstantin Ananyev    ngx_http_v2_node_t              *parent;
156e18a033bSKonstantin Ananyev    ngx_queue_t                      queue;
157e18a033bSKonstantin Ananyev    ngx_queue_t                      children;
158e18a033bSKonstantin Ananyev    ngx_queue_t                      reuse;
159e18a033bSKonstantin Ananyev    ngx_uint_t                       rank;
160e18a033bSKonstantin Ananyev    ngx_uint_t                       weight;
161e18a033bSKonstantin Ananyev    double                           rel_weight;
162e18a033bSKonstantin Ananyev    ngx_http_v2_stream_t            *stream;
163e18a033bSKonstantin Ananyev};
164e18a033bSKonstantin Ananyev
165e18a033bSKonstantin Ananyev
166e18a033bSKonstantin Ananyevstruct ngx_http_v2_stream_s {
167e18a033bSKonstantin Ananyev    ngx_http_request_t              *request;
168e18a033bSKonstantin Ananyev    ngx_http_v2_connection_t        *connection;
169e18a033bSKonstantin Ananyev    ngx_http_v2_node_t              *node;
170e18a033bSKonstantin Ananyev
171e18a033bSKonstantin Ananyev    ngx_uint_t                       queued;
172e18a033bSKonstantin Ananyev
173e18a033bSKonstantin Ananyev    /*
174e18a033bSKonstantin Ananyev     * A change to SETTINGS_INITIAL_WINDOW_SIZE could cause the
175e18a033bSKonstantin Ananyev     * send_window to become negative, hence it's signed.
176e18a033bSKonstantin Ananyev     */
177e18a033bSKonstantin Ananyev    ssize_t                          send_window;
178e18a033bSKonstantin Ananyev    size_t                           recv_window;
179e18a033bSKonstantin Ananyev
180e18a033bSKonstantin Ananyev    ngx_buf_t                       *preread;
181e18a033bSKonstantin Ananyev
182e18a033bSKonstantin Ananyev    ngx_http_v2_out_frame_t         *free_frames;
183e18a033bSKonstantin Ananyev    ngx_chain_t                     *free_frame_headers;
184e18a033bSKonstantin Ananyev    ngx_chain_t                     *free_bufs;
185e18a033bSKonstantin Ananyev
186e18a033bSKonstantin Ananyev    ngx_queue_t                      queue;
187e18a033bSKonstantin Ananyev
188e18a033bSKonstantin Ananyev    ngx_array_t                     *cookies;
189e18a033bSKonstantin Ananyev
190e18a033bSKonstantin Ananyev    size_t                           header_limit;
191e18a033bSKonstantin Ananyev
192e18a033bSKonstantin Ananyev    ngx_pool_t                      *pool;
193e18a033bSKonstantin Ananyev
194e18a033bSKonstantin Ananyev    unsigned                         waiting:1;
195e18a033bSKonstantin Ananyev    unsigned                         blocked:1;
196e18a033bSKonstantin Ananyev    unsigned                         exhausted:1;
197e18a033bSKonstantin Ananyev    unsigned                         in_closed:1;
198e18a033bSKonstantin Ananyev    unsigned                         out_closed:1;
199e18a033bSKonstantin Ananyev    unsigned                         rst_sent:1;
200e18a033bSKonstantin Ananyev    unsigned                         no_flow_control:1;
201e18a033bSKonstantin Ananyev    unsigned                         skip_data:1;
202e18a033bSKonstantin Ananyev};
203e18a033bSKonstantin Ananyev
204e18a033bSKonstantin Ananyev
205e18a033bSKonstantin Ananyevstruct ngx_http_v2_out_frame_s {
206e18a033bSKonstantin Ananyev    ngx_http_v2_out_frame_t         *next;
207e18a033bSKonstantin Ananyev    ngx_chain_t                     *first;
208e18a033bSKonstantin Ananyev    ngx_chain_t                     *last;
209e18a033bSKonstantin Ananyev    ngx_int_t                      (*handler)(ngx_http_v2_connection_t *h2c,
210e18a033bSKonstantin Ananyev                                        ngx_http_v2_out_frame_t *frame);
211e18a033bSKonstantin Ananyev
212e18a033bSKonstantin Ananyev    ngx_http_v2_stream_t            *stream;
213e18a033bSKonstantin Ananyev    size_t                           length;
214e18a033bSKonstantin Ananyev
215e18a033bSKonstantin Ananyev    unsigned                         blocked:1;
216e18a033bSKonstantin Ananyev    unsigned                         fin:1;
217e18a033bSKonstantin Ananyev};
218e18a033bSKonstantin Ananyev
219e18a033bSKonstantin Ananyev
220e18a033bSKonstantin Ananyevstatic ngx_inline void
221e18a033bSKonstantin Ananyevngx_http_v2_queue_frame(ngx_http_v2_connection_t *h2c,
222e18a033bSKonstantin Ananyev    ngx_http_v2_out_frame_t *frame)
223e18a033bSKonstantin Ananyev{
224e18a033bSKonstantin Ananyev    ngx_http_v2_out_frame_t  **out;
225e18a033bSKonstantin Ananyev
226e18a033bSKonstantin Ananyev    for (out = &h2c->last_out; *out; out = &(*out)->next) {
227e18a033bSKonstantin Ananyev
228e18a033bSKonstantin Ananyev        if ((*out)->blocked || (*out)->stream == NULL) {
229e18a033bSKonstantin Ananyev            break;
230e18a033bSKonstantin Ananyev        }
231e18a033bSKonstantin Ananyev
232e18a033bSKonstantin Ananyev        if ((*out)->stream->node->rank < frame->stream->node->rank
233e18a033bSKonstantin Ananyev            || ((*out)->stream->node->rank == frame->stream->node->rank
234e18a033bSKonstantin Ananyev                && (*out)->stream->node->rel_weight
235e18a033bSKonstantin Ananyev                   >= frame->stream->node->rel_weight))
236e18a033bSKonstantin Ananyev        {
237e18a033bSKonstantin Ananyev            break;
238e18a033bSKonstantin Ananyev        }
239e18a033bSKonstantin Ananyev    }
240e18a033bSKonstantin Ananyev
241e18a033bSKonstantin Ananyev    frame->next = *out;
242e18a033bSKonstantin Ananyev    *out = frame;
243e18a033bSKonstantin Ananyev}
244e18a033bSKonstantin Ananyev
245e18a033bSKonstantin Ananyev
246e18a033bSKonstantin Ananyevstatic ngx_inline void
247e18a033bSKonstantin Ananyevngx_http_v2_queue_blocked_frame(ngx_http_v2_connection_t *h2c,
248e18a033bSKonstantin Ananyev    ngx_http_v2_out_frame_t *frame)
249e18a033bSKonstantin Ananyev{
250e18a033bSKonstantin Ananyev    ngx_http_v2_out_frame_t  **out;
251e18a033bSKonstantin Ananyev
252e18a033bSKonstantin Ananyev    for (out = &h2c->last_out; *out; out = &(*out)->next) {
253e18a033bSKonstantin Ananyev
254e18a033bSKonstantin Ananyev        if ((*out)->blocked || (*out)->stream == NULL) {
255e18a033bSKonstantin Ananyev            break;
256e18a033bSKonstantin Ananyev        }
257e18a033bSKonstantin Ananyev    }
258e18a033bSKonstantin Ananyev
259e18a033bSKonstantin Ananyev    frame->next = *out;
260e18a033bSKonstantin Ananyev    *out = frame;
261e18a033bSKonstantin Ananyev}
262e18a033bSKonstantin Ananyev
263e18a033bSKonstantin Ananyev
264e18a033bSKonstantin Ananyevvoid ngx_http_v2_init(ngx_event_t *rev);
265e18a033bSKonstantin Ananyevvoid ngx_http_v2_request_headers_init(void);
266e18a033bSKonstantin Ananyev
267e18a033bSKonstantin Ananyevngx_int_t ngx_http_v2_read_request_body(ngx_http_request_t *r,
268e18a033bSKonstantin Ananyev    ngx_http_client_body_handler_pt post_handler);
269e18a033bSKonstantin Ananyevngx_int_t ngx_http_v2_read_unbuffered_request_body(ngx_http_request_t *r);
270e18a033bSKonstantin Ananyev
271e18a033bSKonstantin Ananyevvoid ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc);
272e18a033bSKonstantin Ananyev
273e18a033bSKonstantin Ananyevngx_int_t ngx_http_v2_send_output_queue(ngx_http_v2_connection_t *h2c);
274e18a033bSKonstantin Ananyev
275e18a033bSKonstantin Ananyev
276e18a033bSKonstantin Ananyevngx_int_t ngx_http_v2_get_indexed_header(ngx_http_v2_connection_t *h2c,
277e18a033bSKonstantin Ananyev    ngx_uint_t index, ngx_uint_t name_only);
278e18a033bSKonstantin Ananyevngx_int_t ngx_http_v2_add_header(ngx_http_v2_connection_t *h2c,
279e18a033bSKonstantin Ananyev    ngx_http_v2_header_t *header);
280e18a033bSKonstantin Ananyevngx_int_t ngx_http_v2_table_size(ngx_http_v2_connection_t *h2c, size_t size);
281e18a033bSKonstantin Ananyev
282e18a033bSKonstantin Ananyev
283e18a033bSKonstantin Ananyevngx_int_t ngx_http_v2_huff_decode(u_char *state, u_char *src, size_t len,
284e18a033bSKonstantin Ananyev    u_char **dst, ngx_uint_t last, ngx_log_t *log);
285e18a033bSKonstantin Ananyevsize_t ngx_http_v2_huff_encode(u_char *src, size_t len, u_char *dst,
286e18a033bSKonstantin Ananyev    ngx_uint_t lower);
287e18a033bSKonstantin Ananyev
288e18a033bSKonstantin Ananyev
289e18a033bSKonstantin Ananyev#define ngx_http_v2_prefix(bits)  ((1 << (bits)) - 1)
290e18a033bSKonstantin Ananyev
291e18a033bSKonstantin Ananyev
292e18a033bSKonstantin Ananyev#if (NGX_HAVE_NONALIGNED)
293e18a033bSKonstantin Ananyev
294e18a033bSKonstantin Ananyev#define ngx_http_v2_parse_uint16(p)  ntohs(*(uint16_t *) (p))
295e18a033bSKonstantin Ananyev#define ngx_http_v2_parse_uint32(p)  ntohl(*(uint32_t *) (p))
296e18a033bSKonstantin Ananyev
297e18a033bSKonstantin Ananyev#else
298e18a033bSKonstantin Ananyev
299e18a033bSKonstantin Ananyev#define ngx_http_v2_parse_uint16(p)  ((p)[0] << 8 | (p)[1])
300e18a033bSKonstantin Ananyev#define ngx_http_v2_parse_uint32(p)                                           \
301e18a033bSKonstantin Ananyev    ((uint32_t) (p)[0] << 24 | (p)[1] << 16 | (p)[2] << 8 | (p)[3])
302e18a033bSKonstantin Ananyev
303e18a033bSKonstantin Ananyev#endif
304e18a033bSKonstantin Ananyev
305e18a033bSKonstantin Ananyev#define ngx_http_v2_parse_length(p)  ((p) >> 8)
306e18a033bSKonstantin Ananyev#define ngx_http_v2_parse_type(p)    ((p) & 0xff)
307e18a033bSKonstantin Ananyev#define ngx_http_v2_parse_sid(p)     (ngx_http_v2_parse_uint32(p) & 0x7fffffff)
308e18a033bSKonstantin Ananyev#define ngx_http_v2_parse_window(p)  (ngx_http_v2_parse_uint32(p) & 0x7fffffff)
309e18a033bSKonstantin Ananyev
310e18a033bSKonstantin Ananyev
311e18a033bSKonstantin Ananyev#define ngx_http_v2_write_uint16_aligned(p, s)                                \
312e18a033bSKonstantin Ananyev    (*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t))
313e18a033bSKonstantin Ananyev#define ngx_http_v2_write_uint32_aligned(p, s)                                \
314e18a033bSKonstantin Ananyev    (*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t))
315e18a033bSKonstantin Ananyev
316e18a033bSKonstantin Ananyev#if (NGX_HAVE_NONALIGNED)
317e18a033bSKonstantin Ananyev
318e18a033bSKonstantin Ananyev#define ngx_http_v2_write_uint16  ngx_http_v2_write_uint16_aligned
319e18a033bSKonstantin Ananyev#define ngx_http_v2_write_uint32  ngx_http_v2_write_uint32_aligned
320e18a033bSKonstantin Ananyev
321e18a033bSKonstantin Ananyev#else
322e18a033bSKonstantin Ananyev
323e18a033bSKonstantin Ananyev#define ngx_http_v2_write_uint16(p, s)                                        \
324e18a033bSKonstantin Ananyev    ((p)[0] = (u_char) ((s) >> 8),                                            \
325e18a033bSKonstantin Ananyev     (p)[1] = (u_char)  (s),                                                  \
326e18a033bSKonstantin Ananyev     (p) + sizeof(uint16_t))
327e18a033bSKonstantin Ananyev
328e18a033bSKonstantin Ananyev#define ngx_http_v2_write_uint32(p, s)                                        \
329e18a033bSKonstantin Ananyev    ((p)[0] = (u_char) ((s) >> 24),                                           \
330e18a033bSKonstantin Ananyev     (p)[1] = (u_char) ((s) >> 16),                                           \
331e18a033bSKonstantin Ananyev     (p)[2] = (u_char) ((s) >> 8),                                            \
332e18a033bSKonstantin Ananyev     (p)[3] = (u_char)  (s),                                                  \
333e18a033bSKonstantin Ananyev     (p) + sizeof(uint32_t))
334e18a033bSKonstantin Ananyev
335e18a033bSKonstantin Ananyev#endif
336e18a033bSKonstantin Ananyev
337e18a033bSKonstantin Ananyev#define ngx_http_v2_write_len_and_type(p, l, t)                               \
338e18a033bSKonstantin Ananyev    ngx_http_v2_write_uint32_aligned(p, (l) << 8 | (t))
339e18a033bSKonstantin Ananyev
340e18a033bSKonstantin Ananyev#define ngx_http_v2_write_sid  ngx_http_v2_write_uint32
341e18a033bSKonstantin Ananyev
342e18a033bSKonstantin Ananyev#endif /* _NGX_HTTP_V2_H_INCLUDED_ */
343