use of org.apache.flink.shaded.netty4.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()));
assertThat(ReferenceCountUtil.release(response), is(true));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project netty by netty.
the class CorsHandlerTest method preflightGetRequestWithCustomHeaders.
@Test
public void preflightGetRequestWithCustomHeaders() {
final CorsConfig config = forOrigin("http://localhost:8888").allowedRequestMethods(OPTIONS, GET, DELETE).allowedRequestHeaders("content-type", "xheader1").build();
final HttpResponse response = preflightRequest(config, "http://localhost:8888", "content-type, xheader1");
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN), is("http://localhost:8888"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_METHODS), containsString("OPTIONS"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_METHODS), containsString("GET"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS), containsString("content-type"));
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_HEADERS), containsString("xheader1"));
assertThat(response.headers().get(VARY), equalTo(ORIGIN.toString()));
assertThat(ReferenceCountUtil.release(response), is(true));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project netty by netty.
the class CorsHandlerTest method shortCircuitWithoutConnectionShouldStayOpen.
@Test
public void shortCircuitWithoutConnectionShouldStayOpen() {
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 org.apache.flink.shaded.netty4.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()));
assertThat(ReferenceCountUtil.release(response), is(true));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project netty by netty.
the class WebSocketServerHandshakerFactory method sendUnsupportedVersionResponse.
/**
* Return that we need cannot not support the web socket version
*/
public static ChannelFuture sendUnsupportedVersionResponse(Channel channel, ChannelPromise promise) {
HttpResponse res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UPGRADE_REQUIRED, channel.alloc().buffer(0));
res.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
HttpUtil.setContentLength(res, 0);
return channel.writeAndFlush(res, promise);
}
Aggregations