Search in sources :

Example 26 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class CrtHttpRequestConverter method requestToCrt.

public HttpRequest requestToCrt(SdkHttpFullRequest inputRequest) {
    String method = inputRequest.method().name();
    String encodedPath = encodedPathToCrtFormat(inputRequest.encodedPath());
    String encodedQueryString = SdkHttpUtils.encodeAndFlattenQueryParameters(inputRequest.rawQueryParameters()).map(value -> "?" + value).orElse("");
    HttpHeader[] crtHeaderArray = createHttpHeaderArray(inputRequest);
    Optional<ContentStreamProvider> contentProvider = inputRequest.contentStreamProvider();
    HttpRequestBodyStream crtInputStream = null;
    if (contentProvider.isPresent()) {
        crtInputStream = new CrtHttpRequestConverter.CrtInputStream(contentProvider.get());
    }
    return new HttpRequest(method, encodedPath + encodedQueryString, crtHeaderArray, crtInputStream);
}
Also used : StringUtils(software.amazon.awssdk.utils.StringUtils) SdkHttpUtils(software.amazon.awssdk.utils.http.SdkHttpUtils) URISyntaxException(java.net.URISyntaxException) ContentStreamProvider(software.amazon.awssdk.http.ContentStreamProvider) IOException(java.io.IOException) Math.min(java.lang.Math.min) HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) CollectionUtils.isNullOrEmpty(software.amazon.awssdk.utils.CollectionUtils.isNullOrEmpty) Map(java.util.Map) HttpRequestBodyStream(software.amazon.awssdk.crt.http.HttpRequestBodyStream) AwsSigningResult(software.amazon.awssdk.crt.auth.signing.AwsSigningResult) Optional(java.util.Optional) URI(java.net.URI) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) InputStream(java.io.InputStream) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) HttpRequestBodyStream(software.amazon.awssdk.crt.http.HttpRequestBodyStream) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) ContentStreamProvider(software.amazon.awssdk.http.ContentStreamProvider)

Example 27 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class AwsCrtV4aSignerTest method hostHeaderIncludesNonStandardPorts.

@Test
public void hostHeaderIncludesNonStandardPorts() {
    SigningTestCase testCase = SignerTestUtils.createBasicHeaderSigningTestCase();
    ExecutionAttributes executionAttributes = SignerTestUtils.buildBasicExecutionAttributes(testCase);
    SdkHttpFullRequest request = testCase.requestBuilder.protocol("http").port(443).build();
    SdkHttpFullRequest signed = v4aSigner.sign(request, executionAttributes);
    assertThat(signed.firstMatchingHeader("Host")).hasValue("demo.us-east-1.amazonaws.com:443");
}
Also used : ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Test(org.junit.Test)

Example 28 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class QueryParametersToBodyInterceptorTest method nonPostRequestsUnaltered.

private void nonPostRequestsUnaltered(SdkHttpMethod method) {
    SdkHttpFullRequest request = requestBuilder.method(method).build();
    SdkHttpFullRequest output = (SdkHttpFullRequest) interceptor.modifyHttpRequest(new HttpRequestOnlyContext(request, null), executionAttributes);
    assertThat(output.rawQueryParameters()).hasSize(1);
    assertThat(output.headers()).hasSize(0);
    assertThat(output.contentStreamProvider()).isEmpty();
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest)

Example 29 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class QueryParametersToBodyInterceptorTest method onlyAlterRequestsIfParamsArePresent.

@Test
public void onlyAlterRequestsIfParamsArePresent() throws Exception {
    SdkHttpFullRequest request = requestBuilder.clearQueryParameters().build();
    SdkHttpFullRequest output = (SdkHttpFullRequest) interceptor.modifyHttpRequest(new HttpRequestOnlyContext(request, null), executionAttributes);
    assertThat(output.rawQueryParameters()).hasSize(0);
    assertThat(output.headers()).hasSize(0);
    assertThat(output.contentStreamProvider()).isEmpty();
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Test(org.junit.jupiter.api.Test)

Example 30 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class AsyncStreamingRequestMarshallerTest method transferEncodingIsUsed_OverHttp1.

@Test
public void transferEncodingIsUsed_OverHttp1() {
    when(requestBody.contentLength()).thenReturn(Optional.empty());
    AsyncStreamingRequestMarshaller marshaller = createMarshaller(false, true, false);
    SdkHttpFullRequest httpFullRequest = marshaller.marshall(object);
    assertThat(httpFullRequest.firstMatchingHeader(Header.CONTENT_LENGTH)).isEmpty();
    assertThat(httpFullRequest.firstMatchingHeader(Header.TRANSFER_ENCODING)).isPresent();
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Test(org.junit.Test)

Aggregations

SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)178 Test (org.junit.Test)70 Test (org.junit.jupiter.api.Test)50 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)43 URI (java.net.URI)25 SigningTestCase (software.amazon.awssdk.authcrt.signer.SigningTestCase)23 ByteArrayInputStream (java.io.ByteArrayInputStream)18 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)16 List (java.util.List)13 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)13 RequestExecutionContext (software.amazon.awssdk.core.internal.http.RequestExecutionContext)12 ByteBuffer (java.nio.ByteBuffer)11 AsyncRequestBody (software.amazon.awssdk.core.async.AsyncRequestBody)11 Map (java.util.Map)10 ContentStreamProvider (software.amazon.awssdk.http.ContentStreamProvider)10 Instant (java.time.Instant)9 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)9 Aws4SignerParams (software.amazon.awssdk.auth.signer.params.Aws4SignerParams)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8