Java Code Examples for software.amazon.awssdk.http.SdkHttpRequest#Builder

The following examples show how to use software.amazon.awssdk.http.SdkHttpRequest#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateMultipartUploadRequestInterceptor.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public SdkHttpRequest modifyHttpRequest(Context.ModifyHttpRequest context,
                                        ExecutionAttributes executionAttributes) {
    if (context.request() instanceof CreateMultipartUploadRequest) {
        SdkHttpRequest.Builder builder = context.httpRequest()
                                                .toBuilder()
                                                .putHeader(CONTENT_LENGTH, String.valueOf(0));

        if (!context.httpRequest().firstMatchingHeader(CONTENT_TYPE).isPresent()) {
            builder.putHeader(CONTENT_TYPE, "binary/octet-stream");
        }

        return builder.build();
    }

    return context.httpRequest();
}
 
Example 2
Source File: GlacierExecutionInterceptor.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private SdkHttpRequest.Builder beforeRequest(Object originalRequest, SdkHttpRequest.Builder mutableRequest) {
    mutableRequest.putHeader("x-amz-glacier-version", "2012-06-01");

    //  "x-amz-content-sha256" header is required for sig v4 for some streaming operations
    mutableRequest.putHeader("x-amz-content-sha256", "required");

    if (originalRequest instanceof UploadMultipartPartRequest) {
        mutableRequest.firstMatchingHeader("Content-Range")
                      .ifPresent(range -> mutableRequest.putHeader("Content-Length",
                                                                   Long.toString(parseContentLengthFromRange(range))));

    } else if (originalRequest instanceof GetJobOutputRequest || originalRequest instanceof DescribeJobRequest) {
        String resourcePath = mutableRequest.encodedPath();
        if (resourcePath != null) {
            String newResourcePath = resourcePath.replace("{jobType}", "archive-retrievals");
            mutableRequest.encodedPath(newResourcePath);
        }
    }
    return mutableRequest;
}
 
Example 3
Source File: DefaultS3Presigner.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private void addRequestLevelHeaders(SdkHttpRequest.Builder builder, SdkRequest request) {
    request.overrideConfiguration().ifPresent(overrideConfig -> {
        if (!overrideConfig.headers().isEmpty()) {
            overrideConfig.headers().forEach(builder::putHeader);
        }
    });
}
 
Example 4
Source File: DefaultS3Presigner.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private void addRequestLeveQueryParameters(SdkHttpRequest.Builder builder, SdkRequest request) {
    request.overrideConfiguration().ifPresent(overrideConfig -> {
        if (!overrideConfig.rawQueryParameters().isEmpty()) {
            overrideConfig.rawQueryParameters().forEach(builder::putRawQueryParameter);
        }
    });
}
 
Example 5
Source File: S3EndpointUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new instance of the given {@link SdkHttpRequest} by applying any endpoint changes based on
 * the given {@link S3Configuration} options.
 */
public static ConfiguredS3SdkHttpRequest applyEndpointConfiguration(SdkHttpRequest request,
                                                                    SdkRequest originalRequest,
                                                                    Region region,
                                                                    S3Configuration serviceConfiguration,
                                                                    boolean endpointOverridden) {
    String bucketName = originalRequest.getValueForField("Bucket", String.class).orElse(null);
    String key = originalRequest.getValueForField("Key", String.class).orElse(null);

    if (bucketName != null && isArn(bucketName)) {
        return applyEndpointConfigurationForAccessPointArn(request, region, endpointOverridden,
                                                           serviceConfiguration, bucketName, key);
    }

    SdkHttpRequest.Builder mutableRequest = request.toBuilder();

    URI endpoint = resolveEndpoint(request, originalRequest, region, serviceConfiguration);
    mutableRequest.uri(endpoint);

    if (serviceConfiguration == null || !serviceConfiguration.pathStyleAccessEnabled()) {
        if (bucketName != null) {
            if (BucketUtils.isVirtualAddressingCompatibleBucketName(bucketName, false)) {
                changeToDnsEndpoint(mutableRequest, bucketName);
            }
        }
    }

    return ConfiguredS3SdkHttpRequest.builder()
                                     .sdkHttpRequest(mutableRequest.build())
                                     .build();
}
 
Example 6
Source File: S3EndpointUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Changes from path style addressing (which the marshallers produce by default, to DNS style or 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);
    }
}
 
Example 7
Source File: ChecksumsEnabledValidatorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private SdkHttpRequest.Builder emptyHttpRequest() {
    return SdkHttpFullRequest.builder()
                             .method(SdkHttpMethod.GET)
                             .protocol("https")
                             .host("localhost")
                             .port(80);
}