Search in sources :

Example 36 with HttpResponse

use of 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"));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.Test)

Example 37 with HttpResponse

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

the class CorsHandlerTest method simpleRequestWithNoMatchingOrigin.

@Test
public void simpleRequestWithNoMatchingOrigin() {
    final String origin = "http://localhost:8888";
    final HttpResponse response = simpleRequest(forOrigins("https://localhost:8888").build(), origin);
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN), is(nullValue()));
    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) AsciiString(io.netty.util.AsciiString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 38 with HttpResponse

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

the class CorsHandlerTest method simpleRequestAllowCredentials.

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

Example 39 with HttpResponse

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

the class CorsHandlerTest method simpleRequestWithAnyOrigin.

@Test
public void simpleRequestWithAnyOrigin() {
    final HttpResponse response = simpleRequest(forAnyOrigin().build(), "http://localhost:7777");
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN), is("*"));
    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 40 with HttpResponse

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

the class CorsHandlerTest method preflightRequestWithDefaultHeaders.

@Test
public void preflightRequestWithDefaultHeaders() {
    final CorsConfig config = forOrigin("http://localhost:8888").build();
    final HttpResponse response = preflightRequest(config, "http://localhost:8888", "content-type, xheader1");
    assertThat(response.headers().get(CONTENT_LENGTH), is("0"));
    assertThat(response.headers().get(DATE), is(notNullValue()));
    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)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