Skip to content

Use virtual host style on customizing endpoint #2333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ConfiguredS3SdkHttpRequest applyEndpointConfiguration(S3EndpointResolverC

String bucketName = context.originalRequest().getValueForField("Bucket", String.class).orElse(null);
if (canUseVirtualAddressing(context.serviceConfiguration(), bucketName)) {
changeToDnsEndpoint(mutableRequest, bucketName);
S3EndpointUtils.changeToDnsEndpoint(mutableRequest, bucketName);
}

return ConfiguredS3SdkHttpRequest.builder()
Expand Down Expand Up @@ -87,20 +87,4 @@ private static boolean canUseVirtualAddressing(S3Configuration serviceConfigurat
return !isPathStyleAccessEnabled(serviceConfiguration) && bucketName != null &&
BucketUtils.isVirtualAddressingCompatibleBucketName(bucketName, false);
}

/**
* Changes from path style addressing (which the marshallers produce by default), to DNS style/virtual style addressing,
* where the bucket name is prepended to the host. DNS style addressing is preferred due to the better load balancing
* qualities it provides; path style is an option mainly for proxy based situations and alternative S3 implementations.
*
* @param mutableRequest Marshalled HTTP request we are modifying.
* @param bucketName Bucket name for this particular operation.
*/
private static void changeToDnsEndpoint(SdkHttpRequest.Builder mutableRequest, String bucketName) {
if (mutableRequest.host().startsWith("s3")) {
String newHost = mutableRequest.host().replaceFirst("s3", bucketName + "." + "s3");
String newPath = mutableRequest.encodedPath().replaceFirst("/" + bucketName, "");
mutableRequest.host(newHost).encodedPath(newPath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ public static boolean isArnRegionEnabled(S3Configuration serviceConfiguration) {
* @param bucketName Bucket name for this particular operation.
*/
public static void changeToDnsEndpoint(SdkHttpRequest.Builder mutableRequest, String bucketName) {
String newHost;
if (mutableRequest.host().startsWith("s3")) {
String newHost = mutableRequest.host().replaceFirst("s3", bucketName + "." + "s3");
String newPath = mutableRequest.encodedPath().replaceFirst("/" + bucketName, "");

mutableRequest.host(newHost).encodedPath(newPath);
newHost = mutableRequest.host().replaceFirst("s3", bucketName + "." + "s3");
} else {
newHost = bucketName + "." + mutableRequest.host();
}
String newPath = mutableRequest.encodedPath().replaceFirst("/" + bucketName, "");
mutableRequest.host(newHost).encodedPath(newPath);
}

public static boolean isArn(String s) {
Expand Down