Skip to content

Commit 30c53f6

Browse files
authored
Merge branch 'main' into try-automate-it
2 parents 90ce4af + 1fbeb2e commit 30c53f6

4 files changed

Lines changed: 54 additions & 0 deletions

File tree

include/aws/http/http.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ void aws_http_library_init(struct aws_allocator *alloc);
123123
AWS_HTTP_API
124124
void 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"

source/http.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
559572
const struct aws_byte_cursor aws_http_method_get = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("GET");
560573
const struct aws_byte_cursor aws_http_method_head = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("HEAD");
561574
const struct aws_byte_cursor aws_http_method_post = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("POST");

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ macro(add_h2_decoder_test_set NAME)
1818
add_test_case("${NAME}_one_byte_at_a_time")
1919
endmacro()
2020

21+
add_test_case(test_http_error_code_is_retryable)
22+
2123
add_test_case(headers_add)
2224
add_test_case(headers_add_array)
2325
add_test_case(headers_set)

tests/test_http.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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);

0 commit comments

Comments
 (0)