use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project ambry by linkedin.
the class PublicAccessLogHandlerTest method doRequestHandleWithMultipleRequest.
/**
* Does a test to see that two consecutive requests without sending last http content for first request fails
* @param httpMethod the {@link HttpMethod} for the request.
* @param uri Uri to be used during the request
* @param useSSL {@code true} to test SSL logging.
* @throws Exception
*/
private void doRequestHandleWithMultipleRequest(HttpMethod httpMethod, String uri, boolean useSSL) throws Exception {
EmbeddedChannel channel = createChannel(useSSL);
// contains one logged request header
HttpHeaders headers1 = new DefaultHttpHeaders();
headers1.add(HttpHeaderNames.CONTENT_LENGTH, new Random().nextLong());
HttpRequest request = RestTestUtils.createRequest(httpMethod, uri, headers1);
HttpUtil.setKeepAlive(request, true);
channel.writeInbound(request);
// contains one logged and not logged header
HttpHeaders headers2 = new DefaultHttpHeaders();
headers2.add(NOT_LOGGED_HEADER_KEY + "1", "headerValue1");
headers2.add(HttpHeaderNames.CONTENT_LENGTH, new Random().nextLong());
// sending another request w/o sending last http content
request = RestTestUtils.createRequest(httpMethod, uri, headers2);
HttpUtil.setKeepAlive(request, true);
sendRequestCheckResponse(channel, request, uri, headers2, false, false, useSSL);
Assert.assertTrue("Channel should not be closed ", channel.isOpen());
// verify that headers from first request is not found in public access log
String lastLogEntry = publicAccessLogger.getLastPublicAccessLogEntry();
// verify request headers
verifyPublicAccessLogEntryForRequestHeaders(lastLogEntry, headers1, request.method(), false);
channel.close();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest 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 org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project ambry by linkedin.
the class FrontendIntegrationTest method multipartPostBlobAndVerify.
/**
* Posts a blob with the given {@code headers} and {@code content}.
* @param headers the headers required.
* @param content the content of the blob.
* @param usermetadata the {@link ByteBuffer} that represents user metadata
* @return the blob ID of the blob.
* @throws Exception
*/
private String multipartPostBlobAndVerify(HttpHeaders headers, ByteBuffer content, ByteBuffer usermetadata) throws Exception {
HttpRequest httpRequest = RestTestUtils.createRequest(HttpMethod.POST, "/", headers);
HttpPostRequestEncoder encoder = createEncoder(httpRequest, content, usermetadata);
ResponseParts responseParts = nettyClient.sendRequest(encoder.finalizeRequest(), encoder, null).get();
return verifyPostAndReturnBlobId(responseParts);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project async-http-client by AsyncHttpClient.
the class NettyConnectListener method writeRequest.
private void writeRequest(Channel channel) {
if (futureIsAlreadyCancelled(channel)) {
return;
}
if (LOGGER.isDebugEnabled()) {
HttpRequest httpRequest = future.getNettyRequest().getHttpRequest();
LOGGER.debug("Using new Channel '{}' for '{}' to '{}'", channel, httpRequest.method(), httpRequest.uri());
}
Channels.setAttribute(channel, future);
channelManager.registerOpenChannel(channel);
future.attachChannel(channel, false);
requestSender.writeRequest(future, channel);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project tesla by linking12.
the class BlackURLHttpRequestFilter method doFilter.
@Override
public HttpResponse doFilter(HttpRequest originalRequest, HttpObject httpObject, ChannelHandlerContext channelHandlerContext) {
if (httpObject instanceof HttpRequest) {
HttpRequest httpRequest = (HttpRequest) httpObject;
String url = httpRequest.uri();
int index = url.indexOf("?");
if (index > -1) {
url = url.substring(0, index);
}
List<Pattern> patterns = super.getRule(this);
for (Pattern pattern : patterns) {
Matcher matcher = pattern.matcher(url);
if (matcher.find()) {
super.writeFilterLog(url, BlackIpHttpRequesFilter.class, pattern.pattern());
return super.createResponse(HttpResponseStatus.FORBIDDEN, originalRequest);
}
}
}
return null;
}
Aggregations