Skip to content

Commit ad22604

Browse files
committed
a lot of change needed for the tests
1 parent f118ace commit ad22604

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

source/h1_connection.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,7 @@ static int s_try_process_next_stream_read_message(struct aws_h1_connection *conn
20292029
aws_h1_decoder_set_logging_id(connection->thread_data.incoming_stream_decoder, incoming_stream);
20302030

20312031
bool body_headers_ignored = incoming_stream->base.request_method == AWS_HTTP_METHOD_HEAD;
2032+
body_headers_ignored |= incoming_stream->base.request_method == AWS_HTTP_METHOD_CONNECT;
20322033
aws_h1_decoder_set_body_headers_ignored(connection->thread_data.incoming_stream_decoder, body_headers_ignored);
20332034
/**
20342035
* RFC-7230 3.3.3
@@ -2037,9 +2038,9 @@ static int s_try_process_next_stream_read_message(struct aws_h1_connection *conn
20372038
* line that concludes the header fields. A client MUST ignore any
20382039
* Content-Length or Transfer-Encoding header fields received in
20392040
* such a message. . */
2040-
aws_h1_decoder_set_body_headers_ignored_on_2xx(
2041-
connection->thread_data.incoming_stream_decoder,
2042-
incoming_stream->base.request_method == AWS_HTTP_METHOD_CONNECT);
2041+
// aws_h1_decoder_set_body_headers_ignored_on_2xx(
2042+
// connection->thread_data.incoming_stream_decoder,
2043+
// incoming_stream->base.request_method == AWS_HTTP_METHOD_CONNECT);
20432044

20442045
if (incoming_stream->base.metrics.receive_start_timestamp_ns == -1) {
20452046
/* That's the first time for the stream receives any message */

source/h1_decoder.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,13 @@ static int s_linestate_header(struct aws_h1_decoder *decoder, struct aws_byte_cu
380380
s_set_state(decoder, s_state_unchunked_body);
381381
} else if (
382382
!decoder->is_decoding_requests && !decoder->content_length_received &&
383-
!decoder->body_headers_forbidden) {
383+
!decoder->body_headers_forbidden && !decoder->body_headers_ignored_on_2xx) {
384384
/* RFC-7230 3.3.3: If a message is received without Transfer-Encoding and without Content-Length and NOT
385385
* determined by the response lien to have no body, then the message body length is determined by
386386
* reading the stream until connection closure. Note: This only applies to responses. A request without
387387
* Content-Length or Transfer-Encoding has no message body (per RFC 7230 section 3.3.3). */
388+
/* The failure response for CONNECT with body is undefined, and since the clinet will handle the CONNECT
389+
* request, don't read the body to keep it simple. */
388390
decoder->response_body_indeterminate_length = true;
389391
s_set_state(decoder, s_state_indeterminate_length_body);
390392
AWS_LOGF_DEBUG(

tests/test_h1_client.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_get_headers) {
22712271
&tester.testing_channel,
22722272
"HTTP/1.1 308 Permanent Redirect\r\n"
22732273
"Date: Fri, 01 Mar 2019 17:18:55 GMT\r\n"
2274+
"Content-Length: 0\r\n"
22742275
"Location: /index.html\r\n"
22752276
"\r\n"));
22762277

@@ -2722,7 +2723,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_done_sending_is_ok
27222723
aws_input_stream_release(body_stream);
27232724

27242725
/* send response */
2725-
ASSERT_SUCCESS(testing_channel_push_read_str(&tester.testing_channel, "HTTP/1.1 200 OK\r\n\r\n"));
2726+
ASSERT_SUCCESS(
2727+
testing_channel_push_read_str(&tester.testing_channel, "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
27262728

27272729
/* tick loop until body finishes sending.*/
27282730
while (body_sender.cursor.len > 0) {
@@ -2745,7 +2747,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_done_sending_is_ok
27452747
ASSERT_TRUE(stream_tester.complete);
27462748
ASSERT_INT_EQUALS(AWS_ERROR_SUCCESS, stream_tester.on_complete_error_code);
27472749
ASSERT_INT_EQUALS(200, stream_tester.response_status);
2748-
ASSERT_UINT_EQUALS(0, aws_http_headers_count(stream_tester.response_headers));
2750+
ASSERT_UINT_EQUALS(1, aws_http_headers_count(stream_tester.response_headers));
27492751
ASSERT_UINT_EQUALS(0, stream_tester.response_body.len);
27502752

27512753
/* clean up */
@@ -2788,7 +2790,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_chunks_done_sendin
27882790
testing_channel_run_currently_queued_tasks(&tester.testing_channel);
27892791

27902792
/* send response */
2791-
ASSERT_SUCCESS(testing_channel_push_read_str(&tester.testing_channel, "HTTP/1.1 200 OK\r\n\r\n"));
2793+
ASSERT_SUCCESS(
2794+
testing_channel_push_read_str(&tester.testing_channel, "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
27922795

27932796
testing_channel_run_currently_queued_tasks(&tester.testing_channel);
27942797

@@ -2826,7 +2829,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_arrives_before_request_chunks_done_sendin
28262829
ASSERT_TRUE(stream_tester.complete);
28272830
ASSERT_INT_EQUALS(AWS_ERROR_SUCCESS, stream_tester.on_complete_error_code);
28282831
ASSERT_INT_EQUALS(200, stream_tester.response_status);
2829-
ASSERT_UINT_EQUALS(0, aws_http_headers_count(stream_tester.response_headers));
2832+
ASSERT_UINT_EQUALS(1, aws_http_headers_count(stream_tester.response_headers));
28302833
ASSERT_UINT_EQUALS(0, stream_tester.response_body.len);
28312834

28322835
/* clean up */
@@ -2841,7 +2844,8 @@ H1_CLIENT_TEST_CASE(h1_client_response_without_request_shuts_down_connection) {
28412844
struct tester tester;
28422845
ASSERT_SUCCESS(s_tester_init(&tester, allocator));
28432846

2844-
ASSERT_SUCCESS(testing_channel_push_read_str_ignore_errors(&tester.testing_channel, "HTTP/1.1 200 OK\r\n\r\n"));
2847+
ASSERT_SUCCESS(testing_channel_push_read_str_ignore_errors(
2848+
&tester.testing_channel, "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
28452849
testing_channel_drain_queued_tasks(&tester.testing_channel);
28462850

28472851
ASSERT_TRUE(testing_channel_is_shutdown_completed(&tester.testing_channel));
@@ -2874,6 +2878,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_close_header_ends_connection) {
28742878
ASSERT_SUCCESS(testing_channel_push_read_str(
28752879
&tester.testing_channel,
28762880
"HTTP/1.1 200 OK\r\n"
2881+
"Content-Length: 0\r\n"
28772882
"Connection: close\r\n"
28782883
"\r\n"));
28792884

@@ -2938,6 +2943,7 @@ H1_CLIENT_TEST_CASE(h1_client_request_close_header_ends_connection) {
29382943
ASSERT_SUCCESS(testing_channel_push_read_str(
29392944
&tester.testing_channel,
29402945
"HTTP/1.1 200 OK\r\n"
2946+
"Content-Length: 0\r\n"
29412947
"\r\n"));
29422948

29432949
testing_channel_drain_queued_tasks(&tester.testing_channel);
@@ -2983,9 +2989,11 @@ H1_CLIENT_TEST_CASE(h1_client_response_close_header_with_pipelining) {
29832989
&tester.testing_channel,
29842990
/* Response 1 */
29852991
"HTTP/1.1 200 OK\r\n"
2992+
"Content-Length: 0\r\n"
29862993
"\r\n"
29872994
/* Response 2 */
29882995
"HTTP/1.1 200 OK\r\n"
2996+
"Content-Length: 0\r\n"
29892997
"Connection: close\r\n"
29902998
"\r\n"));
29912999

@@ -3069,9 +3077,11 @@ H1_CLIENT_TEST_CASE(h1_client_request_close_header_with_pipelining) {
30693077
&tester.testing_channel,
30703078
/* Response 1 */
30713079
"HTTP/1.1 200 OK\r\n"
3080+
"Content-Length: 0\r\n"
30723081
"\r\n"
30733082
/* Response 2 */
30743083
"HTTP/1.1 200 OK\r\n"
3084+
"Content-Length: 0\r\n"
30753085
"\r\n"));
30763086

30773087
testing_channel_drain_queued_tasks(&tester.testing_channel);
@@ -3175,9 +3185,11 @@ H1_CLIENT_TEST_CASE(h1_client_request_close_header_with_chunked_encoding_and_pip
31753185
&tester.testing_channel,
31763186
/* Response 1 */
31773187
"HTTP/1.1 200 OK\r\n"
3188+
"Content-Length: 0\r\n"
31783189
"\r\n"
31793190
/* Response 2 */
31803191
"HTTP/1.1 200 OK\r\n"
3192+
"Content-Length: 0\r\n"
31813193
"\r\n"));
31823194

31833195
testing_channel_drain_queued_tasks(&tester.testing_channel);
@@ -4786,6 +4798,7 @@ H1_CLIENT_TEST_CASE(h1_client_response_close_connection_before_request_finishes)
47864798
&tester.testing_channel,
47874799
"HTTP/1.1 404 Not Found\r\n"
47884800
"Date: Fri, 01 Mar 2019 17:18:55 GMT\r\n"
4801+
"Content-Length: 0\r\n"
47894802
"Connection: close\r\n"
47904803
"\r\n"));
47914804

0 commit comments

Comments
 (0)