Search in sources :

Example 71 with HttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse 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 72 with HttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse 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 73 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 74 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 75 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)

Aggregations

HttpResponse (io.netty.handler.codec.http.HttpResponse)283 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)108 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)74 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)71 HttpRequest (io.netty.handler.codec.http.HttpRequest)69 Test (org.junit.Test)60 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)57 Test (org.junit.jupiter.api.Test)56 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)54 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)51 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)47 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)42 HttpContent (io.netty.handler.codec.http.HttpContent)39 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)32 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)24 ByteBuf (io.netty.buffer.ByteBuf)20 ResponseParts (com.github.ambry.rest.NettyClient.ResponseParts)18 ChannelFuture (io.netty.channel.ChannelFuture)17 Map (java.util.Map)17 IOException (java.io.IOException)15