diff --git a/include/aws/http/http.h b/include/aws/http/http.h index babdc8e3e..173d12c6e 100644 --- a/include/aws/http/http.h +++ b/include/aws/http/http.h @@ -62,6 +62,7 @@ enum aws_http_errors { AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT, AWS_ERROR_HTTP_CONNECTION_MANAGER_ACQUISITION_TIMEOUT, AWS_ERROR_HTTP_CONNECTION_MANAGER_MAX_PENDING_ACQUISITIONS_EXCEEDED, + AWS_ERROR_HTTP_STREAM_CANCELLED, AWS_ERROR_HTTP_END_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_HTTP_PACKAGE_ID) }; diff --git a/include/aws/http/request_response.h b/include/aws/http/request_response.h index c323db428..8f8746e53 100644 --- a/include/aws/http/request_response.h +++ b/include/aws/http/request_response.h @@ -1230,6 +1230,12 @@ uint32_t aws_http_stream_get_id(const struct aws_http_stream *stream); */ AWS_HTTP_API void aws_http_stream_cancel(struct aws_http_stream *stream, int error_code); +/** + * Cancel the stream with default error code. + * Equivalent to invoke aws_http_stream_cancel with AWS_ERROR_HTTP_STREAM_CANCELLED. + */ +AWS_HTTP_API +void aws_http_stream_cancel_default_error(struct aws_http_stream *stream); /** * Reset the HTTP/2 stream (HTTP/2 only). diff --git a/source/http.c b/source/http.c index 979ae3484..4cf1f6d3c 100644 --- a/source/http.c +++ b/source/http.c @@ -157,6 +157,9 @@ static struct aws_error_info s_errors[] = { AWS_DEFINE_ERROR_INFO_HTTP( AWS_ERROR_HTTP_CONNECTION_MANAGER_MAX_PENDING_ACQUISITIONS_EXCEEDED, "Max pending acquisitions reached"), + AWS_DEFINE_ERROR_INFO_HTTP( + AWS_ERROR_HTTP_STREAM_CANCELLED, + "In-flight HTTP-stream has been cancelled by user."), }; /* clang-format on */ diff --git a/source/request_response.c b/source/request_response.c index e2d21ba5b..6e4cabe6a 100644 --- a/source/request_response.c +++ b/source/request_response.c @@ -1218,6 +1218,10 @@ void aws_http_stream_cancel(struct aws_http_stream *stream, int error_code) { stream->vtable->cancel(stream, error_code); } +void aws_http_stream_cancel_default_error(struct aws_http_stream *stream) { + stream->vtable->cancel(stream, AWS_ERROR_HTTP_STREAM_CANCELLED); +} + int aws_http2_stream_reset(struct aws_http_stream *http2_stream, uint32_t http2_error) { AWS_PRECONDITION(http2_stream); AWS_PRECONDITION(http2_stream->vtable); diff --git a/tests/test_h2_client.c b/tests/test_h2_client.c index a5a90af6e..3cc5855d7 100644 --- a/tests/test_h2_client.c +++ b/tests/test_h2_client.c @@ -4542,12 +4542,12 @@ TEST_CASE(h2_client_stream_cancel_stream) { testing_channel_drain_queued_tasks(&s_tester.testing_channel); /* Cancel the request */ - aws_http_stream_cancel(stream_tester.stream, AWS_ERROR_COND_VARIABLE_ERROR_UNKNOWN); + aws_http_stream_cancel_default_error(stream_tester.stream); testing_channel_drain_queued_tasks(&s_tester.testing_channel); ASSERT_TRUE(aws_http_connection_is_open(s_tester.connection)); ASSERT_TRUE(stream_tester.complete); - ASSERT_INT_EQUALS(AWS_ERROR_COND_VARIABLE_ERROR_UNKNOWN, stream_tester.on_complete_error_code); + ASSERT_INT_EQUALS(AWS_ERROR_HTTP_STREAM_CANCELLED, stream_tester.on_complete_error_code); /* validate that stream sent RST_STREAM */ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer)); struct h2_decoded_frame *rst_stream_frame =