use of io.netty.handler.codec.http.FullHttpRequest 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));
}
use of io.netty.handler.codec.http.FullHttpRequest 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));
}
use of io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class CorsHandlerTest method preflightRequestShouldReleaseRequest.
@Test
public void preflightRequestShouldReleaseRequest() {
final CorsConfig config = forOrigin("http://localhost:8888").preflightResponseHeader("CustomHeader", Arrays.asList("value1", "value2")).build();
final EmbeddedChannel channel = new EmbeddedChannel(new CorsHandler(config));
final FullHttpRequest request = optionsRequest("http://localhost:8888", "content-type, xheader1", null);
assertThat(channel.writeInbound(request), is(false));
assertThat(request.refCnt(), is(0));
assertThat(ReferenceCountUtil.release(channel.readOutbound()), is(true));
assertThat(channel.finish(), is(false));
}
use of io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class CorsHandlerTest method forbiddenShouldReleaseRequest.
@Test
public void forbiddenShouldReleaseRequest() {
final CorsConfig config = forOrigin("https://localhost").shortCircuit().build();
final EmbeddedChannel channel = new EmbeddedChannel(new CorsHandler(config), new EchoHandler());
final FullHttpRequest request = createHttpRequest(GET);
request.headers().set(ORIGIN, "http://localhost:8888");
assertThat(channel.writeInbound(request), is(false));
assertThat(request.refCnt(), is(0));
assertThat(ReferenceCountUtil.release(channel.readOutbound()), is(true));
assertThat(channel.finish(), is(false));
}
use of io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class CorsHandlerTest method simpleRequest.
private static HttpResponse simpleRequest(final CorsConfig config, final String origin, final String requestHeaders, final HttpMethod method) {
final EmbeddedChannel channel = new EmbeddedChannel(new CorsHandler(config), new EchoHandler());
final FullHttpRequest httpRequest = createHttpRequest(method);
if (origin != null) {
httpRequest.headers().set(ORIGIN, origin);
}
if (requestHeaders != null) {
httpRequest.headers().set(ACCESS_CONTROL_REQUEST_HEADERS, requestHeaders);
}
assertThat(channel.writeInbound(httpRequest), is(false));
return (HttpResponse) channel.readOutbound();
}
Aggregations