Search in sources :

Example 26 with HttpResponse

use of io.netty.handler.codec.http.HttpResponse in project netty by netty.

the class CorsHandlerTest method simpleRequestExposeHeaders.

@Test
public void simpleRequestExposeHeaders() {
    final CorsConfig config = forAnyOrigin().exposeHeaders("one", "two").build();
    final HttpResponse response = simpleRequest(config, "http://localhost:7777");
    assertThat(response.headers().get(ACCESS_CONTROL_EXPOSE_HEADERS), containsString("one"));
    assertThat(response.headers().get(ACCESS_CONTROL_EXPOSE_HEADERS), containsString("two"));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.Test)

Example 27 with HttpResponse

use of io.netty.handler.codec.http.HttpResponse in project netty by netty.

the class CorsHandlerTest method simpleRequestWithNullOrigin.

@Test
public void simpleRequestWithNullOrigin() {
    final HttpResponse response = simpleRequest(forOrigin("http://test.com").allowNullOrigin().allowCredentials().build(), "null");
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN), is("null"));
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_CREDENTIALS), is(equalTo("true")));
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS), is(nullValue()));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.Test)

Example 28 with HttpResponse

use of 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.Test)

Example 29 with HttpResponse

use of 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.Test)

Example 30 with HttpResponse

use of io.netty.handler.codec.http.HttpResponse in project netty by netty.

the class CorsHandlerTest method anyOriginAndAllowCredentialsShouldEchoRequestOrigin.

@Test
public void anyOriginAndAllowCredentialsShouldEchoRequestOrigin() {
    final CorsConfig config = forAnyOrigin().allowCredentials().build();
    final HttpResponse response = simpleRequest(config, "http://localhost:7777");
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_CREDENTIALS), equalTo("true"));
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN), equalTo("http://localhost:7777"));
    assertThat(response.headers().get(VARY), equalTo(ORIGIN.toString()));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.Test)

Aggregations

HttpResponse (io.netty.handler.codec.http.HttpResponse)118 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)53 Test (org.junit.Test)50 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)30 HttpRequest (io.netty.handler.codec.http.HttpRequest)27 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)24 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)19 HttpContent (io.netty.handler.codec.http.HttpContent)18 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)18 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)14 ChannelFuture (io.netty.channel.ChannelFuture)12 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)12 ByteBuf (io.netty.buffer.ByteBuf)9 AsciiString (io.netty.util.AsciiString)8 HttpObject (io.netty.handler.codec.http.HttpObject)7 Map (java.util.Map)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 WebSocketExtensionData (io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData)6 IOException (java.io.IOException)6 Settings (org.elasticsearch.common.settings.Settings)6