Search in sources :

Example 86 with HttpResponse

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

Example 87 with HttpResponse

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

Example 88 with HttpResponse

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));
}
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.jupiter.api.Test)

Example 89 with HttpResponse

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

Example 90 with HttpResponse

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);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse)

Aggregations

HttpResponse (io.netty.handler.codec.http.HttpResponse)283 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)108 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)74 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)71 HttpRequest (io.netty.handler.codec.http.HttpRequest)69 Test (org.junit.Test)60 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)57 Test (org.junit.jupiter.api.Test)56 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)54 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)51 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)47 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)42 HttpContent (io.netty.handler.codec.http.HttpContent)39 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)32 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)24 ByteBuf (io.netty.buffer.ByteBuf)20 ResponseParts (com.github.ambry.rest.NettyClient.ResponseParts)18 ChannelFuture (io.netty.channel.ChannelFuture)17 Map (java.util.Map)17 IOException (java.io.IOException)15