Skip to content

Commit 3ae6418

Browse files
authored
Implement H2 decoder (#151)
* Implement H2 decoder * Implement new H2 decoder vtable * Implement the H2 decoder state machine * NOTE: Header blocks are not implemented yet, and as such the HEADERS, CONTINUATION, and PUSH_PROMISE frames are incomplete * Make global states const * f_ -> frame_ * Appease the MSVC type conversion gods * Henso PR feedback * CI Fixes * Split goaway into 2 states * Improve error handling and end of state detection * Handle leftover scratch into streaming state case * Handle custom frames * Misc. PR feedback * uint32_t pass * Add error handling strategy (don't) to the decoder * More PR feedback * Decrement payload_len in unknown frame state
1 parent b4f26ae commit 3ae6418

File tree

6 files changed

+789
-16
lines changed

6 files changed

+789
-16
lines changed

include/aws/http/http.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum aws_http_errors {
4848
AWS_ERROR_HTTP_CONNECTION_MANAGER_SHUTTING_DOWN,
4949
AWS_ERROR_HTTP_PROTOCOL_ERROR,
5050
AWS_ERROR_HTTP_STREAM_CLOSED,
51+
AWS_ERROR_HTTP_INVALID_FRAME_SIZE,
5152

5253
AWS_ERROR_HTTP_END_RANGE = 0x0C00,
5354
};

include/aws/http/private/h2_decoder.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,30 @@
1818

1919
#include <aws/http/private/http_impl.h>
2020

21+
struct aws_h2_decoder_vtable {
22+
23+
int (*on_headers)(uint32_t stream_id, void *userdata);
24+
int (*on_end_headers)(uint32_t stream_id, void *userdata);
25+
26+
int (*on_data)(uint32_t stream_id, const struct aws_byte_cursor *data, void *userdata);
27+
28+
int (*on_rst_stream)(uint32_t stream_id, uint32_t error_code, void *userdata);
29+
30+
int (*on_ping)(bool ack, uint8_t opaque_data[8], void *userdata);
31+
int (*on_setting)(uint16_t setting, uint32_t value, void *userdata);
32+
int (*on_settings_ack)(void *userdata);
33+
int (*on_goaway)(uint32_t last_stream, uint32_t error_code, uint32_t debug_data_length, void *userdata);
34+
int (*on_goaway_debug_data)(const struct aws_byte_cursor *data, void *userdata);
35+
};
36+
2137
/**
2238
* Structure used to initialize an `aws_h2_decoder`.
2339
*/
2440
struct aws_h2_decoder_params {
2541
struct aws_allocator *alloc;
2642
void *user_data;
27-
struct aws_http_decoder_vtable vtable;
43+
struct aws_h2_decoder_vtable vtable;
44+
void *userdata;
2845
};
2946

3047
struct aws_h2_decoder;

source/h2_connection.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ static struct aws_http_connection_vtable s_h2_connection_vtable = {
4949
.update_window = NULL,
5050
};
5151

52-
static const struct aws_http_decoder_vtable s_h2_decoder_vtable = {
53-
.on_request = NULL,
54-
.on_response = NULL,
55-
.on_header = NULL,
56-
.on_body = NULL,
57-
.on_done = NULL,
52+
static const struct aws_h2_decoder_vtable s_h2_decoder_vtable = {
53+
.on_data = NULL,
5854
};
5955

6056
/* Common new() logic for server & client */

0 commit comments

Comments
 (0)