Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/client-http/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ dependencies {
testImplementation(project(":aws:client:aws-client-awsjson"))
testImplementation(project(":client:dynamic-client"))
}

tasks.withType<Test> {
systemProperty("jdk.httpclient.allowRestrictedHeaders", "host")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package software.amazon.smithy.java.client.http;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpConnectTimeoutException;
import java.nio.ByteBuffer;
Expand All @@ -31,6 +32,8 @@
*/
public class JavaHttpClientTransport implements ClientTransport<HttpRequest, HttpResponse> {

private static URI DUMMY_URI = URI.create("http://localhost");

private static final InternalLogger LOGGER = InternalLogger.getLogger(JavaHttpClientTransport.class);
private final HttpClient client;

Expand All @@ -47,6 +50,17 @@ private static void setHostProperties() {
} else if (!containsHost(currentValues)) {
System.setProperty("jdk.httpclient.allowRestrictedHeaders", currentValues + ",host");
}
try {
java.net.http.HttpRequest.newBuilder()
.uri(DUMMY_URI)
.setHeader("host", "localhost")
.build();
} catch (IllegalArgumentException e) {
throw new RuntimeException("Unable to add host header. " +
"This means that the HttpClient was initialized before we could allowlist it. " +
"You need to explicitly set allow `host` via the system property `jdk.httpclient.allowRestrictedHeaders`",
e);
}
}

public JavaHttpClientTransport() {
Expand Down