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));
}
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));
}
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));
}
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()));
}
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()));
}
Aggregations