use of io.netty.handler.codec.http.HttpHeaders in project ambry by linkedin.
the class FrontendIntegrationTest method multipartPostGetHeadTest.
/**
* Tests multipart POST and verifies it via GET operations.
* @throws Exception
*/
@Test
public void multipartPostGetHeadTest() throws Exception {
Account refAccount = ACCOUNT_SERVICE.createAndAddRandomAccount();
Container refContainer = refAccount.getContainerById(Container.DEFAULT_PUBLIC_CONTAINER_ID);
doPostGetHeadDeleteTest(0, refAccount, refContainer, refAccount.getName(), !refContainer.isCacheable(), refAccount.getName(), refContainer.getName(), true);
doPostGetHeadDeleteTest(FRONTEND_CONFIG.frontendChunkedGetResponseThresholdInBytes * 3, refAccount, refContainer, refAccount.getName(), !refContainer.isCacheable(), refAccount.getName(), refContainer.getName(), true);
// failure case
// size of content being POSTed is higher than what is allowed via multipart/form-data
long maxAllowedSizeBytes = new NettyConfig(FRONTEND_VERIFIABLE_PROPS).nettyMultipartPostMaxSizeBytes;
ByteBuffer content = ByteBuffer.wrap(TestUtils.getRandomBytes((int) maxAllowedSizeBytes + 1));
HttpHeaders headers = new DefaultHttpHeaders();
setAmbryHeadersForPut(headers, 7200, !refContainer.isCacheable(), refAccount.getName(), "application/octet-stream", null, refAccount.getName(), refContainer.getName());
HttpRequest httpRequest = RestTestUtils.createRequest(HttpMethod.POST, "/", headers);
HttpPostRequestEncoder encoder = createEncoder(httpRequest, content, ByteBuffer.allocate(0));
ResponseParts responseParts = nettyClient.sendRequest(encoder.finalizeRequest(), encoder, null).get();
HttpResponse response = getHttpResponse(responseParts);
assertEquals("Unexpected response status", HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, response.status());
assertTrue("No Date header", response.headers().getTimeMillis(HttpHeaderNames.DATE, -1) != -1);
assertFalse("Channel should not be active", HttpUtil.isKeepAlive(response));
}
use of io.netty.handler.codec.http.HttpHeaders in project ambry by linkedin.
the class FrontendIntegrationTest method verifyOperationsAfterDelete.
/**
* Verifies that the right response code is returned for GET, HEAD and DELETE once a blob is deleted.
* @param blobId the ID of the blob that was deleted.
* @param expectedHeaders the expected headers in the response if the right options are provided.
* @param isPrivate {@code true} if the blob is expected to be private
* @param accountName the expected account name in {@code response}.
* @param containerName the expected container name in {@code response}.
* @param expectedContent the expected content of the blob if the right options are provided.
* @param usermetadata if non-null, this is expected to come as the body.
* @throws Exception
*/
private void verifyOperationsAfterDelete(String blobId, HttpHeaders expectedHeaders, boolean isPrivate, String accountName, String containerName, ByteBuffer expectedContent, byte[] usermetadata) throws Exception {
HttpHeaders headers = new DefaultHttpHeaders().add(RestUtils.Headers.GET_OPTION, GetOption.None.toString());
FullHttpRequest httpRequest = buildRequest(HttpMethod.GET, blobId, null, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.GET, blobId, headers, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.HEAD, blobId, null, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.HEAD, blobId, headers, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.DELETE, blobId, null, null);
verifyDeleted(httpRequest, HttpResponseStatus.ACCEPTED);
GetOption[] options = { GetOption.Include_Deleted_Blobs, GetOption.Include_All };
for (GetOption option : options) {
getBlobAndVerify(blobId, null, option, expectedHeaders, isPrivate, expectedContent);
getNotModifiedBlobAndVerify(blobId, option, isPrivate);
getUserMetadataAndVerify(blobId, option, expectedHeaders, usermetadata);
getBlobInfoAndVerify(blobId, option, expectedHeaders, isPrivate, accountName, containerName, usermetadata);
getHeadAndVerify(blobId, null, option, expectedHeaders, isPrivate, accountName, containerName);
}
}
use of io.netty.handler.codec.http.HttpHeaders in project ambry by linkedin.
the class FrontendIntegrationTest method getUserMetadataAndVerify.
/**
* Gets the user metadata of the blob with blob ID {@code blobId} and verifies them against what is expected.
* @param blobId the blob ID of the blob to HEAD.
* @param getOption the options to use while getting the blob.
* @param expectedHeaders the expected headers in the response.
* @param usermetadata if non-null, this is expected to come as the body.
* @throws ExecutionException
* @throws InterruptedException
*/
private void getUserMetadataAndVerify(String blobId, GetOption getOption, HttpHeaders expectedHeaders, byte[] usermetadata) throws ExecutionException, InterruptedException {
HttpHeaders headers = new DefaultHttpHeaders();
if (getOption != null) {
headers.add(RestUtils.Headers.GET_OPTION, getOption.toString());
}
FullHttpRequest httpRequest = buildRequest(HttpMethod.GET, blobId + "/" + RestUtils.SubResource.UserMetadata, headers, null);
ResponseParts responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
HttpResponse response = getHttpResponse(responseParts);
assertEquals("Unexpected response status", HttpResponseStatus.OK, response.status());
checkCommonGetHeadHeaders(response.headers());
verifyUserMetadata(expectedHeaders, response, usermetadata, responseParts.queue);
assertTrue("Channel should be active", HttpUtil.isKeepAlive(response));
}
use of io.netty.handler.codec.http.HttpHeaders in project ambry by linkedin.
the class FrontendIntegrationTest method getNotModifiedBlobAndVerify.
/**
* Gets the blob with blob ID {@code blobId} and verifies that the blob is not returned as blob is not modified
* @param blobId the blob ID of the blob to GET.
* @param getOption the options to use while getting the blob.
* @param isPrivate {@code true} if the blob is private, {@code false} if not.
* @throws Exception
*/
private void getNotModifiedBlobAndVerify(String blobId, GetOption getOption, boolean isPrivate) throws Exception {
HttpHeaders headers = new DefaultHttpHeaders();
if (getOption != null) {
headers.add(RestUtils.Headers.GET_OPTION, getOption.toString());
}
headers.add(RestUtils.Headers.IF_MODIFIED_SINCE, new Date());
FullHttpRequest httpRequest = buildRequest(HttpMethod.GET, blobId, headers, null);
ResponseParts responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
HttpResponse response = getHttpResponse(responseParts);
assertEquals("Unexpected response status", HttpResponseStatus.NOT_MODIFIED, response.status());
assertNotNull("Date header should be set", response.headers().get(RestUtils.Headers.DATE));
assertNotNull("Last-Modified header should be set", response.headers().get("Last-Modified"));
assertNull("Content-Length should not be set", response.headers().get(RestUtils.Headers.CONTENT_LENGTH));
assertNull("Accept-Ranges should not be set", response.headers().get(RestUtils.Headers.ACCEPT_RANGES));
assertNull("Content-Range header should not be set", response.headers().get(RestUtils.Headers.CONTENT_RANGE));
assertNull(RestUtils.Headers.BLOB_SIZE + " should have been null ", response.headers().get(RestUtils.Headers.BLOB_SIZE));
assertNull("Content-Type should have been null", response.headers().get(RestUtils.Headers.CONTENT_TYPE));
verifyCacheHeaders(isPrivate, response);
assertNoContent(responseParts.queue);
}
use of io.netty.handler.codec.http.HttpHeaders in project async-http-client by AsyncHttpClient.
the class InputStreamTest method testInvalidInputStream.
@Test
public void testInvalidInputStream() throws IOException, ExecutionException, InterruptedException {
try (AsyncHttpClient c = asyncHttpClient()) {
HttpHeaders h = new DefaultHttpHeaders().add(CONTENT_TYPE, HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED);
InputStream is = new InputStream() {
int readAllowed;
@Override
public int available() {
// Fake
return 1;
}
@Override
public int read() {
int fakeCount = readAllowed++;
if (fakeCount == 0) {
return (int) 'a';
} else if (fakeCount == 1) {
return (int) 'b';
} else if (fakeCount == 2) {
return (int) 'c';
} else {
return -1;
}
}
};
Response resp = c.preparePost(getTargetUrl()).setHeaders(h).setBody(is).execute().get();
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("X-Param"), "abc");
}
}
Aggregations