Skip to content

Commit 47ec7b4

Browse files
authored
log errors in decoder (#26)
* log errors in decoder * slight modifications to decoder, while we're in here thinking about what might go wrong.
1 parent 35a9067 commit 47ec7b4

File tree

7 files changed

+491
-155
lines changed

7 files changed

+491
-155
lines changed

include/aws/http/private/decode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ AWS_HTTP_API int aws_http_decode(
9696
size_t data_bytes,
9797
size_t *bytes_read);
9898

99+
AWS_HTTP_API void aws_http_decoder_set_logging_id(struct aws_http_decoder *decoder, void *id);
100+
99101
/* RFC-7230 section 4.2 Message Format */
100102
#define AWS_HTTP_TRANSFER_ENCODING_CHUNKED (1 << 0)
101103
#define AWS_HTTP_TRANSFER_ENCODING_GZIP (1 << 1)

source/connection_h1.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,9 @@ static int s_handler_process_read_message(
11681168
}
11691169

11701170
/* Decoder will invoke the internal s_decoder_X callbacks, which in turn invoke user callbacks */
1171+
aws_http_decoder_set_logging_id(
1172+
connection->thread_data.incoming_stream_decoder, connection->thread_data.incoming_stream);
1173+
11711174
size_t decoded_len = 0;
11721175
err = aws_http_decode(
11731176
connection->thread_data.incoming_stream_decoder, message_cursor.ptr, message_cursor.len, &decoded_len);

source/decode.c

Lines changed: 258 additions & 71 deletions
Large diffs are not rendered by default.

source/http.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,20 @@ static struct aws_log_subject_info_list s_log_subject_list = {
8383
* Key is aws_byte_cursor* (pointing into cursor from array) and comparisons are case-insensitive.
8484
* Value is the array index cast to a void*.
8585
*/
86-
static void s_init_case_insensitive_hash_table(
86+
static void s_init_str_to_enum_hash_table(
8787
struct aws_hash_table *table,
8888
struct aws_allocator *alloc,
8989
struct aws_byte_cursor *str_array,
9090
int start_index,
91-
int end_index) {
91+
int end_index,
92+
bool ignore_case) {
9293

9394
int err = aws_hash_table_init(
9495
table,
9596
alloc,
9697
end_index - start_index,
97-
aws_hash_byte_cursor_ptr_ignore_case,
98-
(aws_hash_callback_eq_fn *)aws_byte_cursor_eq_ignore_case,
98+
ignore_case ? aws_hash_byte_cursor_ptr_ignore_case : aws_hash_byte_cursor_ptr,
99+
(aws_hash_callback_eq_fn *)(ignore_case ? aws_byte_cursor_eq_ignore_case : aws_byte_cursor_eq),
99100
NULL,
100101
NULL);
101102
AWS_FATAL_ASSERT(!err);
@@ -108,10 +109,10 @@ static void s_init_case_insensitive_hash_table(
108109
}
109110

110111
/**
111-
* Given key, get value from table initialized by s_init_case_insensitive_hash_table().
112+
* Given key, get value from table initialized by s_init_str_to_enum_hash_table().
112113
* Returns -1 if key not found.
113114
*/
114-
static int s_find_in_case_insensitive_hash_table(const struct aws_hash_table *table, struct aws_byte_cursor *key) {
115+
static int s_find_in_str_to_enum_hash_table(const struct aws_hash_table *table, struct aws_byte_cursor *key) {
115116
struct aws_hash_element *elem;
116117
aws_hash_table_find(table, key, &elem);
117118
if (elem) {
@@ -127,16 +128,21 @@ static struct aws_byte_cursor s_method_enum_to_str[AWS_HTTP_METHOD_COUNT]; /* fo
127128
static void s_methods_init(struct aws_allocator *alloc) {
128129
s_method_enum_to_str[AWS_HTTP_METHOD_HEAD] = aws_byte_cursor_from_c_str("HEAD");
129130

130-
s_init_case_insensitive_hash_table(
131-
&s_method_str_to_enum, alloc, s_method_enum_to_str, AWS_HTTP_METHOD_UNKNOWN + 1, AWS_HTTP_METHOD_COUNT);
131+
s_init_str_to_enum_hash_table(
132+
&s_method_str_to_enum,
133+
alloc,
134+
s_method_enum_to_str,
135+
AWS_HTTP_METHOD_UNKNOWN + 1,
136+
AWS_HTTP_METHOD_COUNT,
137+
false /* DO NOT ignore case of method */);
132138
}
133139

134140
static void s_methods_clean_up(void) {
135141
aws_hash_table_clean_up(&s_method_str_to_enum);
136142
}
137143

138144
enum aws_http_method aws_http_str_to_method(struct aws_byte_cursor cursor) {
139-
int method = s_find_in_case_insensitive_hash_table(&s_method_str_to_enum, &cursor);
145+
int method = s_find_in_str_to_enum_hash_table(&s_method_str_to_enum, &cursor);
140146
if (method >= 0) {
141147
return (enum aws_http_method)method;
142148
}
@@ -173,16 +179,21 @@ static void s_headers_init(struct aws_allocator *alloc) {
173179
s_header_enum_to_str[AWS_HTTP_HEADER_CONTENT_LENGTH] = aws_byte_cursor_from_c_str("content-length");
174180
s_header_enum_to_str[AWS_HTTP_HEADER_EXPECT] = aws_byte_cursor_from_c_str("expect");
175181

176-
s_init_case_insensitive_hash_table(
177-
&s_header_str_to_enum, alloc, s_header_enum_to_str, AWS_HTTP_HEADER_UNKNOWN + 1, AWS_HTTP_HEADER_COUNT);
182+
s_init_str_to_enum_hash_table(
183+
&s_header_str_to_enum,
184+
alloc,
185+
s_header_enum_to_str,
186+
AWS_HTTP_HEADER_UNKNOWN + 1,
187+
AWS_HTTP_HEADER_COUNT,
188+
true /* ignore case */);
178189
}
179190

180191
static void s_headers_clean_up(void) {
181192
aws_hash_table_clean_up(&s_header_str_to_enum);
182193
}
183194

184195
enum aws_http_header_name aws_http_str_to_header_name(struct aws_byte_cursor cursor) {
185-
int header = s_find_in_case_insensitive_hash_table(&s_header_str_to_enum, &cursor);
196+
int header = s_find_in_str_to_enum_hash_table(&s_header_str_to_enum, &cursor);
186197
if (header >= 0) {
187198
return (enum aws_http_header_name)header;
188199
}

tests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ add_test_case(http_test_body_chunked)
1818
add_test_case(http_decode_trailers)
1919
add_test_case(http_decode_one_byte_at_a_time)
2020
add_test_case(http_decode_messages_at_random_intervals)
21-
add_test_case(http_decode_bad_messages_and_assert_failure)
21+
add_test_case(http_decode_bad_requests_and_assert_failure)
22+
add_test_case(http_decode_bad_responses_and_assert_failure)
2223
add_test_case(http_test_extraneous_buffer_data_ensure_not_processed)
23-
add_test_case(http_test_ignore_transfer_extensions)
2424
add_test_case(http_test_ignore_chunk_extensions)
2525
add_test_case(server_new_destroy)
2626
# add_test_case(connection_setup_shutdown) TODO: diagnose occasional failures

0 commit comments

Comments
 (0)