Skip to content

Commit 4c2bf2d

Browse files
authored
Merge branch 'main' into byte-buf-fix
2 parents 5e33c8c + a301c3d commit 4c2bf2d

15 files changed

Lines changed: 308 additions & 20 deletions

File tree

crt/aws-c-http

crt/aws-lc

crt/s2n

Submodule s2n updated from 3276a08 to f5e5e83

src/main/java/software/amazon/awssdk/crt/CRT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,16 +492,16 @@ private static native void awsCrtInit(int memoryTracingLevel, boolean debugWait,
492492
* Given an error code, get a boolean to check if an error is transient or not.
493493
*
494494
* Transient errors are defined as IO level errors where we are unable to read an HTTP response.
495-
* This can occur due to connect timeouts, read timeouts, or the server closing the connection without
495+
* This can occur due to connect timeouts, read timeouts, or the server closing the connection without
496496
* sending a response. This method helps identify CRT error codes that are not generic or widely adopted.
497497
*
498-
* This is not the complete logic to identify transient or retryable errors, this includes only IO level
498+
* This is not the complete logic to identify transient or retryable errors, this includes only IO level
499499
* errors that are transient.
500500
*
501501
* @param errorCode An error code returned from an exception or other native function call
502502
* @return A boolean for if the error is transient or not
503503
*/
504-
public static native Boolean awsIsTransientError(int errorCode);
504+
public static native boolean awsIsTransientError(int errorCode);
505505

506506
/**
507507
* @return The number of bytes allocated in native resources. If

src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManager.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ private HttpClientConnectionManager(HttpClientConnectionManagerOptions options)
6262
if (HTTPS.equals(uri.getScheme())) { port = DEFAULT_HTTPS_PORT; }
6363
}
6464
}
65+
/**
66+
* Per RFC 3986 Section 3.2.2, IPv6 addresses in URIs MUST be enclosed in square brackets
67+
* (e.g., "http://[2001:db8::1]:8080/path"). However, when connecting to a host, the brackets
68+
* must be removed to get the actual IPv6 address.
69+
*
70+
* Since Java's URI.getHost() returns IPv6 addresses WITH brackets (e.g., "[2001:db8::1]"),
71+
* but the underlying CRT library expects the hostname WITHOUT brackets (e.g., "2001:db8::1").
72+
* Manually strip the brackets before passing the hostname to CRT.
73+
*
74+
* Note: Different language implementations handle bracket stripping inconsistently eg: Python
75+
* (urlparse().hostname) strip brackets automatically, while Java (URI.getHost()) keeps brackets,
76+
* thus we strip the brackets based on the language behavior.
77+
*/
78+
79+
String host = uri.getHost();
80+
if (host.startsWith("[") && host.endsWith("]")) {
81+
host = host.substring(1, host.length() - 1);
82+
}
6583

6684
HttpProxyOptions proxyOptions = options.getProxyOptions();
6785

@@ -115,7 +133,7 @@ private HttpClientConnectionManager(HttpClientConnectionManagerOptions options)
115133
useTls && tlsContext!=null ? tlsContext.getNativeHandle() : 0,
116134
useTls && tlsConnectionOptions!=null ? tlsConnectionOptions.getNativeHandle() : 0,
117135
windowSize,
118-
uri.getHost().getBytes(UTF8),
136+
host.getBytes(UTF8),
119137
port,
120138
maxConnections,
121139
proxyConnectionType,

src/native/crt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ void JNICALL Java_software_amazon_awssdk_crt_CRT_awsCrtInit(
713713
}
714714

715715
JNIEXPORT
716-
bool JNICALL
716+
jboolean JNICALL
717717
Java_software_amazon_awssdk_crt_CRT_awsIsTransientError(JNIEnv *env, jclass jni_crt_class, jint error_code) {
718718
(void)env;
719719
(void)jni_crt_class;

src/native/http_connection_manager.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
9696
jlong jni_tls_ctx,
9797
jlong jni_tls_connection_options,
9898
jlong jni_window_size,
99-
jbyteArray jni_endpoint,
99+
jbyteArray jni_host,
100100
jint jni_port,
101101
jint jni_max_conns,
102102
jint jni_proxy_connection_type,
@@ -141,7 +141,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
141141
}
142142

143143
struct aws_allocator *allocator = aws_jni_get_allocator();
144-
struct aws_byte_cursor endpoint = aws_jni_byte_cursor_from_jbyteArray_acquire(env, jni_endpoint);
144+
struct aws_byte_cursor host = aws_jni_byte_cursor_from_jbyteArray_acquire(env, jni_host);
145145

146146
size_t window_size;
147147
if (aws_size_t_from_java(env, &window_size, jni_window_size, "Initial window size")) {
@@ -161,7 +161,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
161161
AWS_ZERO_STRUCT(tls_conn_options);
162162
if (new_tls_conn_opts) {
163163
aws_tls_connection_options_init_from_ctx(&tls_conn_options, tls_ctx);
164-
aws_tls_connection_options_set_server_name(&tls_conn_options, allocator, &endpoint);
164+
aws_tls_connection_options_set_server_name(&tls_conn_options, allocator, &host);
165165
tls_connection_options = &tls_conn_options;
166166
}
167167

@@ -180,7 +180,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
180180
manager_options.initial_window_size = window_size;
181181
manager_options.socket_options = socket_options;
182182
manager_options.tls_connection_options = tls_connection_options;
183-
manager_options.host = endpoint;
183+
manager_options.host = host;
184184
manager_options.port = port;
185185
manager_options.max_connections = (size_t)jni_max_conns;
186186
manager_options.shutdown_complete_callback = &s_on_http_conn_manager_shutdown_complete_callback;
@@ -257,7 +257,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
257257
}
258258

259259
cleanup:
260-
aws_jni_byte_cursor_from_jbyteArray_release(env, jni_endpoint, endpoint);
260+
aws_jni_byte_cursor_from_jbyteArray_release(env, jni_host, host);
261261

262262
if (binding->manager == NULL) {
263263
s_destroy_manager_binding(binding, env);

0 commit comments

Comments
 (0)