use of software.amazon.awssdk.crt.http.HttpRequest in project aws-crt-java by awslabs.
the class SigningTest method createSimpleRequest.
private HttpRequest createSimpleRequest(String endpoint, String method, String path, String body) throws Exception {
URI uri = new URI(endpoint);
HttpHeader[] requestHeaders = new HttpHeader[] { new HttpHeader("Host", uri.getHost()), new HttpHeader("Content-Length", Integer.toString(body.getBytes(StandardCharsets.UTF_8).length)) };
return new HttpRequest(method, path, requestHeaders, makeBodyStreamFromString(body));
}
use of software.amazon.awssdk.crt.http.HttpRequest in project aws-crt-java by awslabs.
the class SigningTest method createChunkedTrailerTestRequest.
private HttpRequest createChunkedTrailerTestRequest() throws Exception {
URI uri = new URI("https://s3.amazonaws.com/examplebucket/chunkObject.txt");
HttpHeader[] requestHeaders = new HttpHeader[] { new HttpHeader("Host", uri.getHost()), new HttpHeader("x-amz-storage-class", "REDUCED_REDUNDANCY"), new HttpHeader("Content-Encoding", "aws-chunked"), new HttpHeader("x-amz-decoded-content-length", "66560"), new HttpHeader("Content-Length", "66824"), new HttpHeader("x-amz-trailer", "first,second,third") };
return new HttpRequest("PUT", uri.getPath(), requestHeaders, null);
}
use of software.amazon.awssdk.crt.http.HttpRequest in project aws-crt-java by awslabs.
the class SigningTest method createBadBodyStreamRequest.
private HttpRequest createBadBodyStreamRequest(String method, String path) throws Exception {
HttpHeader[] requestHeaders = new HttpHeader[] { new HttpHeader("Something", "else") };
HttpRequestBodyStream badBodyStream = new HttpRequestBodyStream() {
@Override
public boolean sendRequestBody(ByteBuffer bodyBytesOut) {
throw new RuntimeException("Doh");
}
@Override
public boolean resetPosition() {
return true;
}
};
return new HttpRequest(method, path, requestHeaders, badBodyStream);
}
use of software.amazon.awssdk.crt.http.HttpRequest in project aws-crt-java by awslabs.
the class S3NativeClientTest method customQueryParametersTestCase.
/*
* Runs the given test lambda for custom query parameters, passing it the
* appropriate arguments, then validating the output.
*/
public void customQueryParametersTestCase(CustomQueryParametersTestLambda customQueryParametersTestLambda, String key, String customQueryParameters) {
final S3Client mockInternalClient = mock(S3Client.class);
final S3MetaRequest request = new S3MetaRequest();
when(mockInternalClient.makeMetaRequest(any(S3MetaRequestOptions.class))).thenReturn(request);
final S3NativeClient nativeClient = new S3NativeClient(REGION, mockInternalClient);
customQueryParametersTestLambda.run(nativeClient, key, customQueryParameters);
ArgumentCaptor<S3MetaRequestOptions> optionsArgument = ArgumentCaptor.forClass(S3MetaRequestOptions.class);
verify(mockInternalClient).makeMetaRequest(optionsArgument.capture());
List<S3MetaRequestOptions> optionsList = optionsArgument.getAllValues();
assertEquals(optionsList.size(), 1);
S3MetaRequestOptions options = optionsList.get(0);
HttpRequest httpRequest = options.getHttpRequest();
if (customQueryParameters == null || customQueryParameters.trim().equals("")) {
assertTrue(httpRequest.getEncodedPath().equals("/" + key));
} else {
assertTrue(httpRequest.getEncodedPath().equals("/" + key + "?" + customQueryParameters));
}
reset(mockInternalClient);
request.close();
}
use of software.amazon.awssdk.crt.http.HttpRequest in project aws-crt-java by awslabs.
the class HttpRequestResponseTest method testHttpRequestUnActivated.
@Test
public void testHttpRequestUnActivated() throws Exception {
skipIfNetworkUnavailable();
URI uri = new URI("https://httpbin.org");
HttpHeader[] requestHeaders = new HttpHeader[] { new HttpHeader("Host", uri.getHost()) };
HttpRequest request = new HttpRequest("GET", "/get", requestHeaders, null);
CompletableFuture<Void> shutdownComplete = null;
try (HttpClientConnectionManager connPool = createConnectionPoolManager(uri)) {
shutdownComplete = connPool.getShutdownCompleteFuture();
try (HttpClientConnection conn = connPool.acquireConnection().get(60, TimeUnit.SECONDS)) {
HttpStreamResponseHandler streamHandler = new HttpStreamResponseHandler() {
@Override
public void onResponseHeaders(HttpStream stream, int responseStatusCode, int blockType, HttpHeader[] nextHeaders) {
// do nothing
}
@Override
public void onResponseHeadersDone(HttpStream stream, int blockType) {
// do nothing
}
@Override
public int onResponseBody(HttpStream stream, byte[] bodyBytesIn) {
// do nothing
return bodyBytesIn.length;
}
@Override
public void onResponseComplete(HttpStream stream, int errorCode) {
// do nothing.
}
};
HttpStream stream = conn.makeRequest(request, streamHandler);
stream.close();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
if (shutdownComplete != null) {
shutdownComplete.get();
}
CrtResource.waitForNoResources();
}
Aggregations