use of software.amazon.awssdk.crt.http.HttpHeader 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.HttpHeader 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.HttpHeader in project aws-crt-java by awslabs.
the class S3NativeClientTest method validateCustomHeaders.
private void validateCustomHeaders(List<HttpHeader> generatedHeaders, HttpHeader[] customHeaders) {
if (customHeaders == null || customHeaders.length == 0) {
return;
}
for (HttpHeader customHeader : customHeaders) {
int numTimesFound = 0;
for (HttpHeader generatedHeader : generatedHeaders) {
if (generatedHeader.getName().equals(customHeader.getName())) {
assertEquals(generatedHeader.getValue(), customHeader.getValue());
++numTimesFound;
}
}
assertEquals(1, numTimesFound);
}
}
use of software.amazon.awssdk.crt.http.HttpHeader 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();
}
use of software.amazon.awssdk.crt.http.HttpHeader in project aws-crt-java by awslabs.
the class HttpRequestResponseTest method testRequest.
public TestHttpResponse testRequest(String method, String endpoint, String path, String requestBody, boolean useChunkedEncoding, int expectedStatus) throws Exception {
URI uri = new URI(endpoint);
HttpHeader[] requestHeaders = null;
if (!useChunkedEncoding) {
requestHeaders = new HttpHeader[] { new HttpHeader("Host", uri.getHost()), new HttpHeader("Content-Length", Integer.toString(requestBody.getBytes(UTF8).length)) };
} else {
requestHeaders = new HttpHeader[] { new HttpHeader("Host", uri.getHost()), new HttpHeader("Transfer-Encoding", "chunked") };
}
HttpRequestBodyStream bodyStream = null;
if (!useChunkedEncoding) {
final ByteBuffer bodyBytesIn = ByteBuffer.wrap(requestBody.getBytes(UTF8));
bodyStream = new HttpRequestBodyStream() {
@Override
public boolean sendRequestBody(ByteBuffer bodyBytesOut) {
transferData(bodyBytesIn, bodyBytesOut);
return bodyBytesIn.remaining() == 0;
}
@Override
public boolean resetPosition() {
bodyBytesIn.position(0);
return true;
}
};
}
HttpRequest request = new HttpRequest(method, path, requestHeaders, bodyStream);
TestHttpResponse response = null;
int numAttempts = 0;
do {
if (request.getBodyStream() != null) {
request.getBodyStream().resetPosition();
}
numAttempts++;
response = null;
try {
if (useChunkedEncoding) {
response = getResponse(uri, request, requestBody.getBytes(UTF8));
} else {
response = getResponse(uri, request, null);
}
} catch (Exception ex) {
// do nothing just let it retry
}
} while ((response == null || shouldRetry(response)) && numAttempts < 3);
Assert.assertNotEquals(-1, response.blockType);
boolean hasContentLengthHeader = false;
for (HttpHeader h : response.headers) {
if (h.getName().equals("Content-Length")) {
hasContentLengthHeader = true;
}
}
Assert.assertTrue(hasContentLengthHeader);
if (response.statusCode < 500) {
// if the server errored, not our fault
Assert.assertEquals("Expected and Actual Status Codes don't match", expectedStatus, response.statusCode);
}
return response;
}
Aggregations