use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project ambry by linkedin.
the class CopyForcingByteBuf method contentAddAndReadTest.
/**
* Tests {@link NettyRequest#addContent(HttpContent)} and
* {@link NettyRequest#readInto(AsyncWritableChannel, Callback)} with different digest algorithms (including a test
* with no digest algorithm).
* @throws Exception
*/
@Test
public void contentAddAndReadTest() throws Exception {
String[] digestAlgorithms = { "", "MD5", "SHA-1", "SHA-256" };
HttpMethod[] methods = { HttpMethod.POST, HttpMethod.PUT };
for (HttpMethod method : methods) {
for (String digestAlgorithm : digestAlgorithms) {
contentAddAndReadTest(digestAlgorithm, true, method);
contentAddAndReadTest(digestAlgorithm, false, method);
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project ambry by linkedin.
the class MockChannelHandlerContext method keepAliveTest.
/**
* Tests keep-alive for different HTTP methods and error statuses.
*/
@Test
public void keepAliveTest() {
HttpMethod[] HTTP_METHODS = { HttpMethod.POST, HttpMethod.PUT, HttpMethod.GET, HttpMethod.HEAD, HttpMethod.DELETE };
EmbeddedChannel channel = createEmbeddedChannel();
for (HttpMethod httpMethod : HTTP_METHODS) {
for (RestServiceErrorCode errorCode : RestServiceErrorCode.values()) {
channel = doKeepAliveTest(channel, httpMethod, errorCode, getExpectedHttpResponseStatus(errorCode), 0, null);
}
channel = doKeepAliveTest(channel, httpMethod, null, HttpResponseStatus.INTERNAL_SERVER_ERROR, 0, null);
channel = doKeepAliveTest(channel, httpMethod, null, HttpResponseStatus.INTERNAL_SERVER_ERROR, 0, true);
channel = doKeepAliveTest(channel, httpMethod, null, HttpResponseStatus.INTERNAL_SERVER_ERROR, 0, false);
}
// special test for put because the keep alive depends on content size (0 already tested above)
channel = doKeepAliveTest(channel, HttpMethod.PUT, null, HttpResponseStatus.INTERNAL_SERVER_ERROR, 1, null);
channel = doKeepAliveTest(channel, HttpMethod.PUT, null, HttpResponseStatus.INTERNAL_SERVER_ERROR, 100, null);
channel.close();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project netty by netty.
the class SpdyHttpDecoder method createHttpRequest.
private static FullHttpRequest createHttpRequest(SpdyHeadersFrame requestFrame, ByteBufAllocator alloc) throws Exception {
// Create the first line of the request from the name/value pairs
SpdyHeaders headers = requestFrame.headers();
HttpMethod method = HttpMethod.valueOf(headers.getAsString(METHOD));
String url = headers.getAsString(PATH);
HttpVersion httpVersion = HttpVersion.valueOf(headers.getAsString(VERSION));
headers.remove(METHOD);
headers.remove(PATH);
headers.remove(VERSION);
boolean release = true;
ByteBuf buffer = alloc.buffer();
try {
FullHttpRequest req = new DefaultFullHttpRequest(httpVersion, method, url, buffer);
// Remove the scheme header
headers.remove(SCHEME);
// Replace the SPDY host header with the HTTP host header
CharSequence host = headers.get(HOST);
headers.remove(HOST);
req.headers().set(HttpHeaderNames.HOST, host);
for (Map.Entry<CharSequence, CharSequence> e : requestFrame.headers()) {
req.headers().add(e.getKey(), e.getValue());
}
// The Connection and Keep-Alive headers are no longer valid
HttpUtil.setKeepAlive(req, true);
// Transfer-Encoding header is not valid
req.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
release = false;
return req;
} finally {
if (release) {
buffer.release();
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project rest.li by linkedin.
the class NettyRequestAdapter method toNettyRequest.
/**
* Adapts a RestRequest to Netty's HttpRequest
* @param request R2 rest request
* @return Adapted HttpRequest.
*/
public static HttpRequest toNettyRequest(RestRequest request) throws Exception {
HttpMethod nettyMethod = HttpMethod.valueOf(request.getMethod());
URL url = new URL(request.getURI().toString());
String path = url.getFile();
// it MUST be given as "/" (the server root).
if (path.isEmpty()) {
path = "/";
}
ByteBuf content = Unpooled.wrappedBuffer(request.getEntity().asByteBuffer());
HttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, nettyMethod, path, content);
nettyRequest.headers().set(HttpConstants.CONTENT_LENGTH, request.getEntity().length());
setHttpHeadersAndCookies(request, url, nettyRequest);
return nettyRequest;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project zuul by Netflix.
the class PushMessageSender method channelRead0.
@Override
protected void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest request) throws Exception {
if (!request.decoderResult().isSuccess()) {
sendHttpResponse(ctx, request, BAD_REQUEST, null);
return;
}
final String path = request.uri();
if (path == null) {
sendHttpResponse(ctx, request, BAD_REQUEST, null);
return;
}
if (path.endsWith("/push")) {
logPushAttempt();
final HttpMethod method = request.method();
if ((method != HttpMethod.POST) && (method != HttpMethod.GET)) {
sendHttpResponse(ctx, request, METHOD_NOT_ALLOWED, null);
return;
}
final PushUserAuth userAuth = getPushUserAuth(request);
if (!userAuth.isSuccess()) {
sendHttpResponse(ctx, request, UNAUTHORIZED, userAuth);
logNoIdentity();
return;
}
final PushConnection pushConn = pushConnectionRegistry.get(userAuth.getClientIdentity());
if (pushConn == null) {
sendHttpResponse(ctx, request, NOT_FOUND, userAuth);
logClientNotConnected();
return;
}
if (!verifySecureToken(request, pushConn)) {
sendHttpResponse(ctx, request, FORBIDDEN, userAuth);
logSecurityTokenVerificationFail();
return;
}
if (method == HttpMethod.GET) {
// client only checking if particular CID + ESN is connected to this instance
sendHttpResponse(ctx, request, OK, userAuth);
return;
}
final ByteBuf body = request.content().retain();
if (body.readableBytes() <= 0) {
sendHttpResponse(ctx, request, NO_CONTENT, userAuth);
return;
}
if (pushConn.isRateLimited()) {
sendHttpResponse(ctx, request, HttpResponseStatus.SERVICE_UNAVAILABLE, userAuth);
logRateLimited();
return;
}
final ChannelFuture clientFuture = pushConn.sendPushMessage(body);
clientFuture.addListener(cf -> {
HttpResponseStatus status;
if (cf.isSuccess()) {
logPushSuccess();
status = OK;
} else {
logPushError(cf.cause());
status = INTERNAL_SERVER_ERROR;
}
sendHttpResponse(ctx, request, status, userAuth);
});
} else {
// Last handler in the chain
sendHttpResponse(ctx, request, BAD_REQUEST, null);
}
}
Aggregations