File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -123,6 +123,14 @@ void aws_http_library_init(struct aws_allocator *alloc);
123123AWS_HTTP_API
124124void aws_http_library_clean_up (void );
125125
126+ /*
127+ * This API provides a recommendation on whether an error code should be considered retryable for transient
128+ * errors like host resolution, sockets, and TLS.
129+ * Note: This is a recommendation only. Retry behavior should be determined based on your specific use case.
130+ */
131+ AWS_HTTP_API
132+ bool aws_http_error_code_is_retryable (int error_code );
133+
126134/**
127135 * Returns the description of common status codes.
128136 * Ex: 404 -> "Not Found"
Original file line number Diff line number Diff line change @@ -556,6 +556,19 @@ void aws_http_fatal_assert_library_initialized(void) {
556556 }
557557}
558558
559+ /*
560+ * This might need to get updated with more http error codes based on consensus.
561+ */
562+ bool aws_http_error_code_is_retryable (int error_code ) {
563+ switch (error_code ) {
564+ case AWS_ERROR_HTTP_CONNECTION_CLOSED :
565+ case AWS_ERROR_HTTP_SERVER_CLOSED :
566+ case AWS_ERROR_HTTP_PROXY_CONNECT_FAILED_RETRYABLE :
567+ return true;
568+ }
569+ return aws_io_error_code_is_retryable (error_code );
570+ }
571+
559572const struct aws_byte_cursor aws_http_method_get = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL ("GET" );
560573const struct aws_byte_cursor aws_http_method_head = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL ("HEAD" );
561574const struct aws_byte_cursor aws_http_method_post = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL ("POST" );
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ macro(add_h2_decoder_test_set NAME)
1818 add_test_case ("${NAME} _one_byte_at_a_time" )
1919endmacro ()
2020
21+ add_test_case (test_http_error_code_is_retryable )
22+
2123add_test_case (headers_add )
2224add_test_case (headers_add_array )
2325add_test_case (headers_set )
Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+ * SPDX-License-Identifier: Apache-2.0.
4+ */
5+
6+ #include <aws/http/http.h>
7+ #include <aws/testing/aws_test_harness.h>
8+
9+ static int s_test_http_error_code_is_retryable (struct aws_allocator * allocator , void * ctx ) {
10+ (void )allocator ;
11+ (void )ctx ;
12+
13+ int error_code = 0 ;
14+ ASSERT_FALSE (aws_http_error_code_is_retryable (error_code ));
15+
16+ {
17+ error_code = AWS_ERROR_HTTP_CONNECTION_CLOSED ;
18+ ASSERT_TRUE (aws_http_error_code_is_retryable (error_code ));
19+ }
20+ {
21+ error_code = AWS_ERROR_HTTP_SERVER_CLOSED ;
22+ ASSERT_TRUE (aws_http_error_code_is_retryable (error_code ));
23+ }
24+
25+ error_code = AWS_ERROR_SUCCESS ;
26+ ASSERT_FALSE (aws_http_error_code_is_retryable (error_code ));
27+
28+ return AWS_OP_SUCCESS ;
29+ }
30+
31+ AWS_TEST_CASE (test_http_error_code_is_retryable , s_test_http_error_code_is_retryable );
You can’t perform that action at this time.
0 commit comments