Search in sources :

Example 86 with FullHttpRequest

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

the class HttpPostMultiPartRequestDecoderTest method testDecodeFullHttpRequestWithInvalidCharset.

@Test
public void testDecodeFullHttpRequestWithInvalidCharset() {
    FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
    req.headers().set(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=--89421926422648 [; charset=UTF-8]");
    try {
        new HttpPostMultipartRequestDecoder(req);
        fail("Was expecting an ErrorDataDecoderException");
    } catch (HttpPostRequestDecoder.ErrorDataDecoderException expected) {
    // expected
    } finally {
        assertTrue(req.release());
    }
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Test(org.junit.jupiter.api.Test)

Example 87 with FullHttpRequest

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

the class HttpPostMultiPartRequestDecoderTest method testDecodeFullHttpRequestWithNoContentTypeHeader.

@Test
public void testDecodeFullHttpRequestWithNoContentTypeHeader() {
    FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
    try {
        new HttpPostMultipartRequestDecoder(req);
        fail("Was expecting an ErrorDataDecoderException");
    } catch (HttpPostRequestDecoder.ErrorDataDecoderException expected) {
    // expected
    } finally {
        assertTrue(req.release());
    }
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Test(org.junit.jupiter.api.Test)

Example 88 with FullHttpRequest

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

the class CorsHandlerTest method preflightRequestWithConnectionKeepAliveShouldStayOpen.

@Test
public void preflightRequestWithConnectionKeepAliveShouldStayOpen() throws Exception {
    final CorsConfig config = forOrigin("http://localhost:8888").build();
    final EmbeddedChannel channel = new EmbeddedChannel(new CorsHandler(config));
    final FullHttpRequest request = optionsRequest("http://localhost:8888", "", KEEP_ALIVE);
    assertThat(channel.writeInbound(request), is(false));
    final HttpResponse response = channel.readOutbound();
    assertThat(HttpUtil.isKeepAlive(response), is(true));
    assertThat(channel.isOpen(), is(true));
    assertThat(response.status(), is(OK));
    assertThat(ReferenceCountUtil.release(response), is(true));
    assertThat(channel.finish(), is(false));
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 89 with FullHttpRequest

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

the class CorsHandlerTest method simpleRequestAllowPrivateNetwork.

@Test
public void simpleRequestAllowPrivateNetwork() {
    final CorsConfig config = forOrigin("http://localhost:8888").allowPrivateNetwork().build();
    final EmbeddedChannel channel = new EmbeddedChannel(new CorsHandler(config));
    final FullHttpRequest request = optionsRequest("http://localhost:8888", "", null);
    request.headers().set(ACCESS_CONTROL_REQUEST_PRIVATE_NETWORK, "true");
    assertThat(channel.writeInbound(request), is(false));
    final HttpResponse response = channel.readOutbound();
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_PRIVATE_NETWORK), equalTo("true"));
    assertThat(ReferenceCountUtil.release(response), is(true));
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 90 with FullHttpRequest

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

the class CorsHandlerTest method optionsRequest.

private static FullHttpRequest optionsRequest(final String origin, final String requestHeaders, final AsciiString connection) {
    final FullHttpRequest httpRequest = createHttpRequest(OPTIONS);
    httpRequest.headers().set(ORIGIN, origin);
    httpRequest.headers().set(ACCESS_CONTROL_REQUEST_METHOD, httpRequest.method().toString());
    httpRequest.headers().set(ACCESS_CONTROL_REQUEST_HEADERS, requestHeaders);
    if (connection != null) {
        httpRequest.headers().set(CONNECTION, connection);
    }
    return httpRequest;
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest)

Aggregations

FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)287 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)180 Test (org.junit.jupiter.api.Test)74 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)69 Test (org.junit.Test)64 ByteBuf (io.netty.buffer.ByteBuf)54 HttpResponse (io.netty.handler.codec.http.HttpResponse)49 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)43 URI (java.net.URI)35 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)31 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)30 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)30 AsciiString (io.netty.util.AsciiString)25 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)23 Map (java.util.Map)22 ChannelPromise (io.netty.channel.ChannelPromise)21 HttpMethod (io.netty.handler.codec.http.HttpMethod)20 IOException (java.io.IOException)19 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)18 ResponseParts (com.github.ambry.rest.NettyClient.ResponseParts)16