Search in sources :

Example 61 with HttpResponse

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

the class CorsHandlerTest method preflightRequestAllowCredentials.

@Test
public void preflightRequestAllowCredentials() {
    final String origin = "null";
    final CorsConfig config = forOrigin(origin).allowCredentials().build();
    final HttpResponse response = preflightRequest(config, origin, "content-type, xheader1");
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_CREDENTIALS), is(equalTo("true")));
    assertThat(ReferenceCountUtil.release(response), is(true));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) AsciiString(io.netty.util.AsciiString) Test(org.junit.jupiter.api.Test)

Example 62 with HttpResponse

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

the class CorsHandlerTest method preflightRequestWithoutConnectionShouldStayOpen.

@Test
public void preflightRequestWithoutConnectionShouldStayOpen() 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", "", null);
    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 63 with HttpResponse

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

the class CorsHandlerTest method simpleRequestCustomHeaders.

@Test
public void simpleRequestCustomHeaders() {
    final CorsConfig config = forAnyOrigin().exposeHeaders("custom1", "custom2").build();
    final HttpResponse response = simpleRequest(config, "http://localhost:7777");
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN), equalTo("*"));
    assertThat(response.headers().get(ACCESS_CONTROL_EXPOSE_HEADERS), containsString("custom1"));
    assertThat(response.headers().get(ACCESS_CONTROL_EXPOSE_HEADERS), containsString("custom2"));
    assertThat(ReferenceCountUtil.release(response), is(true));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 64 with HttpResponse

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

the class CorsHandlerTest method preflightRequest.

private static HttpResponse preflightRequest(final List<CorsConfig> configs, final String origin, final String requestHeaders, final boolean isSHortCircuit) {
    final EmbeddedChannel channel = new EmbeddedChannel(new CorsHandler(configs, isSHortCircuit));
    assertThat(channel.writeInbound(optionsRequest(origin, requestHeaders, null)), is(false));
    HttpResponse response = channel.readOutbound();
    assertThat(channel.finish(), is(false));
    return response;
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse)

Example 65 with HttpResponse

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

the class CorsHandlerTest method shortCircuitWithConnectionCloseShouldClose.

@Test
public void shortCircuitWithConnectionCloseShouldClose() {
    final CorsConfig config = forOrigin("http://localhost:8080").shortCircuit().build();
    final EmbeddedChannel channel = new EmbeddedChannel(new CorsHandler(config));
    final FullHttpRequest request = createHttpRequest(GET);
    request.headers().set(ORIGIN, "http://localhost:8888");
    request.headers().set(CONNECTION, CLOSE);
    assertThat(channel.writeInbound(request), is(false));
    final HttpResponse response = channel.readOutbound();
    assertThat(HttpUtil.isKeepAlive(response), is(false));
    assertThat(channel.isOpen(), is(false));
    assertThat(response.status(), is(FORBIDDEN));
    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)

Aggregations

HttpResponse (io.netty.handler.codec.http.HttpResponse)366 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)138 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)95 HttpRequest (io.netty.handler.codec.http.HttpRequest)93 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)71 Test (org.junit.Test)70 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)65 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)65 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)64 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)63 Test (org.junit.jupiter.api.Test)59 HttpContent (io.netty.handler.codec.http.HttpContent)54 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)48 ByteBuf (io.netty.buffer.ByteBuf)42 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)37 Map (java.util.Map)31 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)27 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)27 IOException (java.io.IOException)27 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)26