1616 * permissions and limitations under the License.
1717 */
1818
19- #include <aws/http/private/hpack.h>
2019#include <aws/http/request_response.h>
2120
2221#include <aws/common/byte_buf.h>
@@ -81,6 +80,12 @@ enum aws_h2_settings {
8180#define AWS_H2_WINDOW_UPDATE_MAX (0x7FFFFFFF)
8281#define AWS_H2_STREAM_ID_MAX (0x7FFFFFFF)
8382
83+ /* Legal min(inclusive) and max(inclusive) for each setting */
84+ extern const uint32_t aws_h2_settings_bounds [AWS_H2_SETTINGS_END_RANGE ][2 ];
85+
86+ /* Initial values for settings RFC-7540 6.5.2 */
87+ extern const uint32_t aws_h2_settings_initial [AWS_H2_SETTINGS_END_RANGE ];
88+
8489/* This magic string must be the very first thing a client sends to the server.
8590 * See RFC-7540 3.5 - HTTP/2 Connection Preface */
8691extern const struct aws_byte_cursor aws_h2_connection_preface_client_string ;
@@ -101,23 +106,6 @@ struct aws_h2_frame_priority_settings {
101106 uint8_t weight ;
102107};
103108
104- struct aws_h2_frame_header_block {
105- const struct aws_http_headers * headers ;
106-
107- /* state */
108-
109- enum {
110- AWS_H2_HEADER_BLOCK_STATE_INIT ,
111- AWS_H2_HEADER_BLOCK_STATE_FIRST_FRAME ,
112- AWS_H2_HEADER_BLOCK_STATE_CONTINUATION ,
113- AWS_H2_HEADER_BLOCK_STATE_COMPLETE ,
114- AWS_H2_HEADER_BLOCK_STATE_ERROR ,
115- } state ;
116-
117- struct aws_byte_buf whole_encoded_block ; /* entire header block is encoded here */
118- struct aws_byte_cursor encoded_block_cursor ; /* tracks progress sending encoded header-block in fragments */
119- };
120-
121109/**
122110 * A frame to be encoded.
123111 * (in the case of HEADERS and PUSH_PROMISE, it might turn into multiple frames due to CONTINUATION)
@@ -130,19 +118,33 @@ struct aws_h2_frame {
130118 struct aws_linked_list_node node ;
131119};
132120
133- /* Represents a HEADERS header-block.
134- * (HEADERS frame followed 0 or more CONTINUATION frames) */
121+ /* Represents a HEADERS or PUSH_PROMISE frame (followed by zero or more CONTINUATION frames) */
135122struct aws_h2_frame_headers {
136123 struct aws_h2_frame base ;
137124
138- /* Flags */
125+ /* Common data */
126+ const struct aws_http_headers * headers ;
127+ uint8_t pad_length ; /* Set to 0 to disable AWS_H2_FRAME_F_PADDED */
128+
129+ /* HEADERS-only data */
139130 bool end_stream ; /* AWS_H2_FRAME_F_END_STREAM */
140131 bool has_priority ; /* AWS_H2_FRAME_F_PRIORITY */
141-
142- /* Payload */
143- uint8_t pad_length ; /* Set to 0 to disable AWS_H2_FRAME_F_PADDED */
144132 struct aws_h2_frame_priority_settings priority ;
145- struct aws_h2_frame_header_block header_block ;
133+
134+ /* PUSH_PROMISE-only data */
135+ uint32_t promised_stream_id ;
136+
137+ /* State */
138+ enum {
139+ AWS_H2_HEADERS_STATE_INIT ,
140+ AWS_H2_HEADERS_STATE_FIRST_FRAME ,
141+ AWS_H2_HEADERS_STATE_CONTINUATION ,
142+ AWS_H2_HEADERS_STATE_COMPLETE ,
143+ AWS_H2_HEADERS_STATE_ERROR ,
144+ } state ;
145+
146+ struct aws_byte_buf whole_encoded_header_block ;
147+ struct aws_byte_cursor header_block_cursor ; /* tracks progress sending encoded header-block in fragments */
146148};
147149
148150/* Represents a PRIORITY frame */
@@ -179,17 +181,6 @@ struct aws_h2_frame_settings {
179181 size_t settings_count ;
180182};
181183
182- /* Represents a PUSH_PROMISE header-block.
183- * (PUSH_PROMISE frame followed by 0 or more CONTINUATION frames) */
184- struct aws_h2_frame_push_promise {
185- struct aws_h2_frame base ;
186-
187- /* Payload */
188- uint8_t pad_length ; /* Set to 0 to disable AWS_H2_FRAME_F_PADDED */
189- uint32_t promised_stream_id ;
190- struct aws_h2_frame_header_block header_block ;
191- };
192-
193184#define AWS_H2_PING_DATA_SIZE (8)
194185
195186/* Represents a PING frame */
@@ -223,12 +214,11 @@ struct aws_h2_frame_window_update {
223214
224215/* Used to encode a frame */
225216struct aws_h2_frame_encoder {
226- /* Larger state */
227217 struct aws_allocator * allocator ;
218+ const void * logging_id ;
228219 struct aws_hpack_context * hpack ;
229220 struct aws_h2_frame * current_frame ;
230221 bool has_errored ;
231- enum aws_hpack_huffman_mode huffman_mode ;
232222};
233223
234224typedef void aws_h2_frame_destroy_fn (struct aws_h2_frame * frame_base );
@@ -258,7 +248,8 @@ int aws_h2_validate_stream_id(uint32_t stream_id);
258248 * 2. Encode the frame using aws_h2_frame_*_encode
259249 */
260250AWS_HTTP_API
261- int aws_h2_frame_encoder_init (struct aws_h2_frame_encoder * encoder , struct aws_allocator * allocator );
251+ int aws_h2_frame_encoder_init (struct aws_h2_frame_encoder * encoder , struct aws_allocator * allocator , void * logging_id );
252+
262253AWS_HTTP_API
263254void aws_h2_frame_encoder_clean_up (struct aws_h2_frame_encoder * encoder );
264255
0 commit comments