Skip to content

Commit 8c3e1a9

Browse files
authored
aws_http_header_type -> aws_http_header_block (#143)
1 parent 6e44a23 commit 8c3e1a9

File tree

10 files changed

+68
-62
lines changed

10 files changed

+68
-62
lines changed

bin/elasticurl/main.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,19 @@ static int s_on_incoming_body_fn(struct aws_http_stream *stream, const struct aw
334334

335335
static int s_on_incoming_headers_fn(
336336
struct aws_http_stream *stream,
337-
enum aws_http_header_type header_type,
337+
enum aws_http_header_block header_block,
338338
const struct aws_http_header *header_array,
339339
size_t num_headers,
340340
void *user_data) {
341+
341342
struct elasticurl_ctx *app_ctx = user_data;
342343
(void)app_ctx;
343344
(void)stream;
344-
(void)header_type;
345+
346+
/* Ignore informational headers */
347+
if (header_block == AWS_HTTP_HEADER_BLOCK_INFORMATIONAL) {
348+
return AWS_OP_SUCCESS;
349+
}
345350

346351
if (app_ctx->include_headers) {
347352
if (!app_ctx->response_code_written) {
@@ -364,10 +369,10 @@ static int s_on_incoming_headers_fn(
364369

365370
static int s_on_incoming_header_block_done_fn(
366371
struct aws_http_stream *stream,
367-
enum aws_http_header_type header_type,
372+
enum aws_http_header_block header_block,
368373
void *user_data) {
369374
(void)stream;
370-
(void)header_type;
375+
(void)header_block;
371376
(void)user_data;
372377

373378
return AWS_OP_SUCCESS;

include/aws/http/private/h1_decoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ AWS_HTTP_API int aws_h1_decoder_get_encoding_flags(const struct aws_h1_decoder *
5151

5252
AWS_HTTP_API size_t aws_h1_decoder_get_content_length(const struct aws_h1_decoder *decoder);
5353
AWS_HTTP_API bool aws_h1_decoder_get_body_headers_ignored(const struct aws_h1_decoder *decoder);
54-
AWS_HTTP_API enum aws_http_header_type aws_h1_decoder_get_header_type(const struct aws_h1_decoder *decoder);
54+
AWS_HTTP_API enum aws_http_header_block aws_h1_decoder_get_header_block(const struct aws_h1_decoder *decoder);
5555

5656
AWS_EXTERN_C_END
5757

include/aws/http/request_response.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct aws_http_header {
4444
* MAIN: Main header block sent with request or response.
4545
* TRAILING: Headers sent after the body of a request or response.
4646
*/
47-
enum aws_http_header_type {
47+
enum aws_http_header_block {
4848
AWS_HTTP_HEADER_BLOCK_MAIN,
4949
AWS_HTTP_HEADER_BLOCK_INFORMATIONAL,
5050
AWS_HTTP_HEADER_BLOCK_TRAILING,
@@ -98,21 +98,21 @@ typedef void(aws_http_message_transform_fn)(
9898
*/
9999
typedef int(aws_http_on_incoming_headers_fn)(
100100
struct aws_http_stream *stream,
101-
enum aws_http_header_type header_type,
101+
enum aws_http_header_block header_block,
102102
const struct aws_http_header *header_array,
103103
size_t num_headers,
104104
void *user_data);
105105

106106
/**
107-
* Invoked when the incoming header block of this header_type(informational/normal/trailing) has been completely read.
107+
* Invoked when the incoming header block of this type(informational/main/trailing) has been completely read.
108108
* This is always invoked on the HTTP connection's event-loop thread.
109109
*
110110
* Return AWS_OP_SUCCESS to continue processing the stream.
111111
* Return AWS_OP_ERR to indicate failure and cancel the stream.
112112
*/
113113
typedef int(aws_http_on_incoming_header_block_done_fn)(
114114
struct aws_http_stream *stream,
115-
enum aws_http_header_type header_type,
115+
enum aws_http_header_block header_block,
116116
void *user_data);
117117

118118
/**

source/h1_connection.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -954,16 +954,16 @@ static int s_decoder_on_header(const struct aws_http_decoded_header *header, voi
954954
AWS_BYTE_CURSOR_PRI(header->name_data),
955955
AWS_BYTE_CURSOR_PRI(header->value_data));
956956

957-
enum aws_http_header_type header_type =
958-
aws_h1_decoder_get_header_type(connection->thread_data.incoming_stream_decoder);
957+
enum aws_http_header_block header_block =
958+
aws_h1_decoder_get_header_block(connection->thread_data.incoming_stream_decoder);
959959
if (incoming_stream->base.on_incoming_headers) {
960960
struct aws_http_header deliver = {
961961
.name = header->name_data,
962962
.value = header->value_data,
963963
};
964964

965965
int err = incoming_stream->base.on_incoming_headers(
966-
&incoming_stream->base, header_type, &deliver, 1, incoming_stream->base.user_data);
966+
&incoming_stream->base, header_block, &deliver, 1, incoming_stream->base.user_data);
967967

968968
if (err) {
969969
AWS_LOGF_TRACE(
@@ -989,13 +989,13 @@ static int s_mark_head_done(struct aws_h1_stream *incoming_stream) {
989989
struct h1_connection *connection =
990990
AWS_CONTAINER_OF(incoming_stream->base.owning_connection, struct h1_connection, base);
991991

992-
enum aws_http_header_type header_type =
993-
aws_h1_decoder_get_header_type(connection->thread_data.incoming_stream_decoder);
992+
enum aws_http_header_block header_block =
993+
aws_h1_decoder_get_header_block(connection->thread_data.incoming_stream_decoder);
994994

995-
if (header_type == AWS_HTTP_HEADER_BLOCK_MAIN) {
995+
if (header_block == AWS_HTTP_HEADER_BLOCK_MAIN) {
996996
AWS_LOGF_TRACE(AWS_LS_HTTP_STREAM, "id=%p: Incoming head is done.", (void *)&incoming_stream->base);
997997
incoming_stream->is_incoming_head_done = true;
998-
} else if (header_type == AWS_HTTP_HEADER_BLOCK_INFORMATIONAL) {
998+
} else if (header_block == AWS_HTTP_HEADER_BLOCK_INFORMATIONAL) {
999999
AWS_LOGF_TRACE(
10001000
AWS_LS_HTTP_STREAM,
10011001
"id=%p: Informational incoming head is done, keep waiting for a final response.",
@@ -1005,7 +1005,7 @@ static int s_mark_head_done(struct aws_h1_stream *incoming_stream) {
10051005
/* Invoke user cb */
10061006
if (incoming_stream->base.on_incoming_header_block_done) {
10071007
int err = incoming_stream->base.on_incoming_header_block_done(
1008-
&incoming_stream->base, header_type, incoming_stream->base.user_data);
1008+
&incoming_stream->base, header_block, incoming_stream->base.user_data);
10091009
if (err) {
10101010
AWS_LOGF_TRACE(
10111011
AWS_LS_HTTP_STREAM,
@@ -1069,9 +1069,9 @@ static int s_decoder_on_done(void *user_data) {
10691069
return AWS_OP_ERR;
10701070
}
10711071
/* If it is a informational response, we stop here, keep waiting for new response */
1072-
enum aws_http_header_type header_type =
1073-
aws_h1_decoder_get_header_type(connection->thread_data.incoming_stream_decoder);
1074-
if (header_type == AWS_HTTP_HEADER_BLOCK_INFORMATIONAL) {
1072+
enum aws_http_header_block header_block =
1073+
aws_h1_decoder_get_header_block(connection->thread_data.incoming_stream_decoder);
1074+
if (header_block == AWS_HTTP_HEADER_BLOCK_INFORMATIONAL) {
10751075
return AWS_OP_SUCCESS;
10761076
}
10771077

source/h1_decoder.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct aws_h1_decoder {
4848
bool is_done;
4949
bool body_headers_ignored;
5050
bool body_headers_forbidden;
51-
enum aws_http_header_type header_type;
51+
enum aws_http_header_block header_block;
5252
void *logging_id;
5353

5454
/* User callbacks and settings. */
@@ -328,7 +328,7 @@ static void s_reset_state(struct aws_h1_decoder *decoder) {
328328
decoder->body_headers_ignored = false;
329329
decoder->body_headers_forbidden = false;
330330
/* set to normal by default */
331-
decoder->header_type = AWS_HTTP_HEADER_BLOCK_MAIN;
331+
decoder->header_block = AWS_HTTP_HEADER_BLOCK_MAIN;
332332
}
333333

334334
static int s_state_unchunked_body(struct aws_h1_decoder *decoder, struct aws_byte_cursor *input) {
@@ -753,7 +753,7 @@ static int s_linestate_response(struct aws_h1_decoder *decoder, struct aws_byte_
753753
decoder->body_headers_forbidden = code_val == AWS_HTTP_STATUS_204_NO_CONTENT || code_val / 100 == 1;
754754

755755
if (s_check_info_response_status_code(code_val)) {
756-
decoder->header_type = AWS_HTTP_HEADER_BLOCK_INFORMATIONAL;
756+
decoder->header_block = AWS_HTTP_HEADER_BLOCK_INFORMATIONAL;
757757
}
758758

759759
err = decoder->vtable.on_response((int)code_val, decoder->user_data);
@@ -825,8 +825,8 @@ bool aws_h1_decoder_get_body_headers_ignored(const struct aws_h1_decoder *decode
825825
return decoder->body_headers_ignored;
826826
}
827827

828-
enum aws_http_header_type aws_h1_decoder_get_header_type(const struct aws_h1_decoder *decoder) {
829-
return decoder->header_type;
828+
enum aws_http_header_block aws_h1_decoder_get_header_block(const struct aws_h1_decoder *decoder) {
829+
return decoder->header_block;
830830
}
831831

832832
void aws_h1_decoder_set_logging_id(struct aws_h1_decoder *decoder, void *id) {

source/proxy_connection.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,21 @@ static struct aws_http_message *s_build_proxy_connect_request(struct aws_http_pr
368368
*/
369369
static int s_aws_http_on_incoming_header_block_done_tls_proxy(
370370
struct aws_http_stream *stream,
371-
enum aws_http_header_type header_type,
371+
enum aws_http_header_block header_block,
372372
void *user_data) {
373373

374-
(void)header_type;
375-
376374
struct aws_http_proxy_user_data *context = user_data;
377-
int status = 0;
378-
if (aws_http_stream_get_incoming_response_status(stream, &status) || status != 200) {
379-
AWS_LOGF_ERROR(
380-
AWS_LS_HTTP_CONNECTION,
381-
"(%p) Proxy CONNECT request failed with status code %d",
382-
(void *)context->connection,
383-
status);
384-
context->error_code = AWS_ERROR_HTTP_PROXY_TLS_CONNECT_FAILED;
375+
376+
if (header_block == AWS_HTTP_HEADER_BLOCK_MAIN) {
377+
int status = 0;
378+
if (aws_http_stream_get_incoming_response_status(stream, &status) || status != 200) {
379+
AWS_LOGF_ERROR(
380+
AWS_LS_HTTP_CONNECTION,
381+
"(%p) Proxy CONNECT request failed with status code %d",
382+
(void *)context->connection,
383+
status);
384+
context->error_code = AWS_ERROR_HTTP_PROXY_TLS_CONNECT_FAILED;
385+
}
385386
}
386387

387388
return AWS_OP_SUCCESS;

source/websocket_bootstrap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void s_ws_bootstrap_on_http_shutdown(
9595
void *user_data);
9696
static int s_ws_bootstrap_on_handshake_response_headers(
9797
struct aws_http_stream *stream,
98-
enum aws_http_header_type header_type,
98+
enum aws_http_header_block header_block,
9999
const struct aws_http_header *header_array,
100100
size_t num_headers,
101101
void *user_data);
@@ -395,11 +395,11 @@ static void s_ws_bootstrap_on_http_shutdown(
395395

396396
static int s_ws_bootstrap_on_handshake_response_headers(
397397
struct aws_http_stream *stream,
398-
enum aws_http_header_type header_type,
398+
enum aws_http_header_block header_block,
399399
const struct aws_http_header *header_array,
400400
size_t num_headers,
401401
void *user_data) {
402-
(void)header_type;
402+
(void)header_block;
403403

404404
struct aws_websocket_client_bootstrap *ws_bootstrap = user_data;
405405
int err;

tests/integration_test_proxy.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ static int s_response_status_code = 0;
2828

2929
static int s_aws_http_on_incoming_headers_proxy_test(
3030
struct aws_http_stream *stream,
31-
enum aws_http_header_type header_type,
31+
enum aws_http_header_block header_block,
3232
const struct aws_http_header *header_array,
3333
size_t num_headers,
3434
void *user_data) {
3535
(void)stream;
3636
(void)user_data;
37-
(void)header_type;
37+
(void)header_block;
3838

3939
for (size_t i = 0; i < num_headers; ++i) {
4040
const struct aws_byte_cursor *name = &header_array[i].name;
@@ -48,9 +48,9 @@ static int s_aws_http_on_incoming_headers_proxy_test(
4848

4949
static int s_aws_http_on_incoming_header_block_done_proxy_test(
5050
struct aws_http_stream *stream,
51-
enum aws_http_header_type header_type,
51+
enum aws_http_header_block header_block,
5252
void *user_data) {
53-
(void)header_type;
53+
(void)header_block;
5454

5555
struct proxy_tester *context = user_data;
5656
if (aws_http_stream_get_incoming_response_status(stream, &s_response_status_code) == AWS_OP_SUCCESS) {

tests/test_h1_client.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ struct response_tester {
485485

486486
static int s_response_tester_on_headers(
487487
struct aws_http_stream *stream,
488-
enum aws_http_header_type header_type,
488+
enum aws_http_header_block header_block,
489489
const struct aws_http_header *header_array,
490490
size_t num_headers,
491491
void *user_data) {
@@ -496,7 +496,7 @@ static int s_response_tester_on_headers(
496496

497497
struct aws_byte_buf *storage = &response->storage;
498498
const struct aws_http_header *in_header = header_array;
499-
struct aws_http_header *my_header = header_type == AWS_HTTP_HEADER_BLOCK_INFORMATIONAL
499+
struct aws_http_header *my_header = header_block == AWS_HTTP_HEADER_BLOCK_INFORMATIONAL
500500
? response->info_headers + response->num_info_headers
501501
: response->headers + response->num_headers;
502502
for (size_t i = 0; i < num_headers; ++i) {
@@ -512,9 +512,9 @@ static int s_response_tester_on_headers(
512512
in_header++;
513513
my_header++;
514514
}
515-
if (header_type == AWS_HTTP_HEADER_BLOCK_INFORMATIONAL) {
515+
if (header_block == AWS_HTTP_HEADER_BLOCK_INFORMATIONAL) {
516516
response->num_info_headers += num_headers;
517-
} else if (header_type == AWS_HTTP_HEADER_BLOCK_MAIN) {
517+
} else if (header_block == AWS_HTTP_HEADER_BLOCK_MAIN) {
518518
response->num_headers += num_headers;
519519
}
520520

@@ -523,10 +523,10 @@ static int s_response_tester_on_headers(
523523

524524
static int s_response_tester_on_header_block_done(
525525
struct aws_http_stream *stream,
526-
enum aws_http_header_type header_type,
526+
enum aws_http_header_block header_block,
527527
void *user_data) {
528528
(void)stream;
529-
(void)header_type;
529+
(void)header_block;
530530
struct response_tester *response = user_data;
531531

532532
response->on_response_header_block_done_cb_count++;
@@ -1489,24 +1489,24 @@ static struct aws_input_stream_vtable s_error_from_outgoing_body_vtable = {
14891489

14901490
static int s_error_from_incoming_headers(
14911491
struct aws_http_stream *stream,
1492-
enum aws_http_header_type header_type,
1492+
enum aws_http_header_block header_block,
14931493
const struct aws_http_header *header_array,
14941494
size_t num_headers,
14951495
void *user_data) {
14961496

14971497
(void)stream;
1498-
(void)header_type;
1498+
(void)header_block;
14991499
(void)header_array;
15001500
(void)num_headers;
15011501
return s_error_from_callback_common(user_data, REQUEST_CALLBACK_INCOMING_HEADERS);
15021502
}
15031503

15041504
static int s_error_from_incoming_headers_done(
15051505
struct aws_http_stream *stream,
1506-
enum aws_http_header_type header_type,
1506+
enum aws_http_header_block header_block,
15071507
void *user_data) {
15081508
(void)stream;
1509-
(void)header_type;
1509+
(void)header_block;
15101510
return s_error_from_callback_common(user_data, REQUEST_CALLBACK_INCOMING_HEADERS_DONE);
15111511
}
15121512

tests/test_h1_server.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ struct tester {
7777

7878
static int s_tester_on_request_header(
7979
struct aws_http_stream *stream,
80-
enum aws_http_header_type header_type,
80+
enum aws_http_header_block header_block,
8181
const struct aws_http_header *header_array,
8282
size_t num_headers,
8383
void *user_data) {
8484

8585
(void)stream;
86-
(void)header_type;
86+
(void)header_block;
8787
struct tester_request *request = user_data;
8888
struct aws_byte_buf *storage = &request->storage;
8989
const struct aws_http_header *in_header = header_array;
@@ -107,12 +107,12 @@ static int s_tester_on_request_header(
107107

108108
static int s_tester_on_request_header_block_done(
109109
struct aws_http_stream *stream,
110-
enum aws_http_header_type header_type,
110+
enum aws_http_header_block header_block,
111111
void *user_data) {
112112
(void)stream;
113-
(void)header_type;
113+
(void)header_block;
114114
struct tester_request *request = user_data;
115-
if (header_type == AWS_HTTP_HEADER_BLOCK_MAIN) {
115+
if (header_block == AWS_HTTP_HEADER_BLOCK_MAIN) {
116116
AWS_FATAL_ASSERT(request->header_done == false);
117117
request->header_done = true;
118118
}
@@ -1200,24 +1200,24 @@ static struct aws_input_stream_vtable s_error_from_outgoing_body_vtable = {
12001200

12011201
static int s_error_from_incoming_headers(
12021202
struct aws_http_stream *stream,
1203-
enum aws_http_header_type header_type,
1203+
enum aws_http_header_block header_block,
12041204
const struct aws_http_header *header_array,
12051205
size_t num_headers,
12061206
void *user_data) {
12071207

12081208
(void)stream;
1209-
(void)header_type;
1209+
(void)header_block;
12101210
(void)header_array;
12111211
(void)num_headers;
12121212
return s_error_from_callback_common(user_data, REQUEST_HANDLER_CALLBACK_INCOMING_HEADERS);
12131213
}
12141214

12151215
static int s_error_from_incoming_headers_done(
12161216
struct aws_http_stream *stream,
1217-
enum aws_http_header_type header_type,
1217+
enum aws_http_header_block header_block,
12181218
void *user_data) {
12191219
(void)stream;
1220-
(void)header_type;
1220+
(void)header_block;
12211221
return s_error_from_callback_common(user_data, REQUEST_HANDLER_CALLBACK_INCOMING_HEADERS_DONE);
12221222
}
12231223

0 commit comments

Comments
 (0)