Search in sources :

Example 91 with HttpResponse

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

the class CorsHandlerTest method preflightRequestDoNotAllowCredentials.

@Test
public void preflightRequestDoNotAllowCredentials() {
    final CorsConfig config = forOrigin("http://localhost:8888").build();
    final HttpResponse response = preflightRequest(config, "http://localhost:8888", "");
    // the only valid value for Access-Control-Allow-Credentials is true.
    assertThat(response.headers().contains(ACCESS_CONTROL_ALLOW_CREDENTIALS), is(false));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.Test)

Example 92 with HttpResponse

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

the class CorsHandlerTest method shortCurcuitWithoutConnectionShouldStayOpen.

@Test
public void shortCurcuitWithoutConnectionShouldStayOpen() {
    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");
    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(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.Test)

Example 93 with HttpResponse

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

the class CorsHandlerTest method simpleRequestDoNotAllowCredentials.

@Test
public void simpleRequestDoNotAllowCredentials() {
    final CorsConfig config = forAnyOrigin().build();
    final HttpResponse response = simpleRequest(config, "http://localhost:7777");
    assertThat(response.headers().contains(ACCESS_CONTROL_ALLOW_CREDENTIALS), is(false));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.Test)

Example 94 with HttpResponse

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

the class CorsHandlerTest method preflightRequestWithCustomHeader.

@Test
public void preflightRequestWithCustomHeader() {
    final CorsConfig config = forOrigin("http://localhost:8888").preflightResponseHeader("CustomHeader", "somevalue").build();
    final HttpResponse response = preflightRequest(config, "http://localhost:8888", "content-type, xheader1");
    assertThat(response.headers().get(of("CustomHeader")), equalTo("somevalue"));
    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)

Example 95 with HttpResponse

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

the class CorsHandlerTest method simpleRequestWithOrigins.

@Test
public void simpleRequestWithOrigins() {
    final String origin1 = "http://localhost:8888";
    final String origin2 = "https://localhost:8888";
    final String[] origins = { origin1, origin2 };
    final HttpResponse response1 = simpleRequest(forOrigins(origins).build(), origin1);
    assertThat(response1.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN), is(origin1));
    assertThat(response1.headers().get(ACCESS_CONTROL_ALLOW_HEADERS), is(nullValue()));
    final HttpResponse response2 = simpleRequest(forOrigins(origins).build(), origin2);
    assertThat(response2.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN), is(origin2));
    assertThat(response2.headers().get(ACCESS_CONTROL_ALLOW_HEADERS), is(nullValue()));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) AsciiString(io.netty.util.AsciiString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

HttpResponse (io.netty.handler.codec.http.HttpResponse)127 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)57 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)26 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)24 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)10 AsciiString (io.netty.util.AsciiString)9 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