Search in sources :

Example 86 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project zuul by Netflix.

the class ClientRequestReceiverTest method multipleHostHeaders_setBadRequestStatus.

@Test
public void multipleHostHeaders_setBadRequestStatus() {
    ClientRequestReceiver receiver = new ClientRequestReceiver(null);
    EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestEncoder());
    PassportLoggingHandler loggingHandler = new PassportLoggingHandler(new DefaultRegistry());
    // Required for messages
    channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234);
    channel.pipeline().addLast(new HttpServerCodec());
    channel.pipeline().addLast(receiver);
    channel.pipeline().addLast(loggingHandler);
    HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/post");
    httpRequest.headers().add("Host", "foo.bar.com");
    httpRequest.headers().add("Host", "bar.foo.com");
    channel.writeOutbound(httpRequest);
    ByteBuf byteBuf = channel.readOutbound();
    channel.writeInbound(byteBuf);
    channel.readInbound();
    channel.close();
    HttpRequestMessage request = ClientRequestReceiver.getRequestFromChannel(channel);
    SessionContext context = request.getContext();
    assertEquals(StatusCategoryUtils.getStatusCategory(context), ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST);
    assertEquals("Multiple Host headers", context.getError().getMessage());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpRequestEncoder(io.netty.handler.codec.http.HttpRequestEncoder) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) SessionContext(com.netflix.zuul.context.SessionContext) ByteBuf(io.netty.buffer.ByteBuf) PassportLoggingHandler(com.netflix.zuul.netty.insights.PassportLoggingHandler) Test(org.junit.Test)

Example 87 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project zuul by Netflix.

the class ClientRequestReceiverTest method parseUriFromNetty_unknown.

@Test
public void parseUriFromNetty_unknown() {
    EmbeddedChannel channel = new EmbeddedChannel(new ClientRequestReceiver(null));
    channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234);
    HttpRequestMessageImpl result;
    {
        channel.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "asdf", Unpooled.buffer()));
        result = channel.readInbound();
        result.disposeBufferedBody();
    }
    assertEquals("asdf", result.getPath());
    channel.close();
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpRequestMessageImpl(com.netflix.zuul.message.http.HttpRequestMessageImpl) Test(org.junit.Test)

Example 88 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project zuul by Netflix.

the class ClientRequestReceiverTest method maxHeaderSizeExceeded_setBadRequestStatus.

@Test
public void maxHeaderSizeExceeded_setBadRequestStatus() {
    int maxInitialLineLength = BaseZuulChannelInitializer.MAX_INITIAL_LINE_LENGTH.get();
    int maxHeaderSize = 10;
    int maxChunkSize = BaseZuulChannelInitializer.MAX_CHUNK_SIZE.get();
    ClientRequestReceiver receiver = new ClientRequestReceiver(null);
    EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestEncoder());
    PassportLoggingHandler loggingHandler = new PassportLoggingHandler(new DefaultRegistry());
    // Required for messages
    channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234);
    channel.pipeline().addLast(new HttpServerCodec(maxInitialLineLength, maxHeaderSize, maxChunkSize, false));
    channel.pipeline().addLast(receiver);
    channel.pipeline().addLast(loggingHandler);
    String str = "test-header-value";
    ByteBuf buf = Unpooled.buffer(1);
    HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/post", buf);
    for (int i = 0; i < 100; i++) {
        httpRequest.headers().add("test-header" + i, str);
    }
    channel.writeOutbound(httpRequest);
    ByteBuf byteBuf = channel.readOutbound();
    channel.writeInbound(byteBuf);
    channel.readInbound();
    channel.close();
    HttpRequestMessage request = ClientRequestReceiver.getRequestFromChannel(channel);
    assertEquals(StatusCategoryUtils.getStatusCategory(request.getContext()), ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpRequestEncoder(io.netty.handler.codec.http.HttpRequestEncoder) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ByteBuf(io.netty.buffer.ByteBuf) PassportLoggingHandler(com.netflix.zuul.netty.insights.PassportLoggingHandler) Test(org.junit.Test)

Example 89 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project wildfly by wildfly.

the class TestingOcspServer method getHttpResponse.

public HttpResponse getHttpResponse(HttpRequest request, HttpOcspServlet servlet) {
    byte[] body;
    HttpMethod method;
    if (request.getBody() == null) {
        method = HttpMethod.GET;
        body = request.getPath().getValue().split("/ocsp/", 2)[1].getBytes(UTF_8);
    } else {
        method = HttpMethod.POST;
        body = request.getBody().getRawBytes();
    }
    ByteBuf buffer = Unpooled.wrappedBuffer(body);
    FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, method, request.getPath().getValue(), buffer);
    for (Header header : request.getHeaderList()) {
        for (NottableString value : header.getValues()) {
            nettyRequest.headers().add(header.getName().getValue(), value.getValue());
        }
    }
    FullHttpResponse nettyResponse;
    try {
        nettyResponse = servlet.service(nettyRequest, new ServletURI(request.getPath().getValue()), null, SslReverseProxyMode.NONE);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    HttpResponse response = response().withStatusCode(nettyResponse.status().code()).withBody(nettyResponse.content().array());
    for (Map.Entry<String, String> header : nettyResponse.headers()) {
        response.withHeader(header.getKey(), header.getValue());
    }
    return response;
}
Also used : ServletURI(org.xipki.http.servlet.ServletURI) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpResponse(org.mockserver.model.HttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) NottableString(org.mockserver.model.NottableString) ByteBuf(io.netty.buffer.ByteBuf) SQLException(java.sql.SQLException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Header(org.mockserver.model.Header) NottableString(org.mockserver.model.NottableString) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) Map(java.util.Map) HttpMethod(io.netty.handler.codec.http.HttpMethod)

Example 90 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project crate by crate.

the class HttpAuthUpstreamHandlerTest method testUserAuthenticationWithDisabledHBA.

@Test
public void testUserAuthenticationWithDisabledHBA() throws Exception {
    User crateUser = User.of("crate", EnumSet.of(User.Role.SUPERUSER));
    Authentication authServiceNoHBA = new AlwaysOKAuthentication(userName -> crateUser);
    HttpAuthUpstreamHandler handler = new HttpAuthUpstreamHandler(Settings.EMPTY, authServiceNoHBA);
    EmbeddedChannel ch = new EmbeddedChannel(handler);
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/_sql");
    request.headers().add(HttpHeaderNames.AUTHORIZATION.toString(), "Basic Y3JhdGU6");
    ch.writeInbound(request);
    ch.releaseInbound();
    assertTrue(handler.authorized());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) User(io.crate.user.User) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Aggregations

DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)215 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)117 Test (org.junit.jupiter.api.Test)72 Test (org.junit.Test)61 ByteBuf (io.netty.buffer.ByteBuf)56 HttpRequest (io.netty.handler.codec.http.HttpRequest)47 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)43 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)40 AsciiString (io.netty.util.AsciiString)30 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)23 Channel (io.netty.channel.Channel)20 ChannelPromise (io.netty.channel.ChannelPromise)19 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)18 IOException (java.io.IOException)17 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)15 HttpResponse (io.netty.handler.codec.http.HttpResponse)15 URI (java.net.URI)15 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)14 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)13 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)12