Search in sources :

Example 66 with HttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project netty by netty.

the class CorsHandlerTest method preflightRequestWithNullOrigin.

@Test
public void preflightRequestWithNullOrigin() {
    final String origin = "null";
    final CorsConfig config = forOrigin(origin).allowNullOrigin().allowCredentials().build();
    final HttpResponse response = preflightRequest(config, origin, "content-type, xheader1");
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN), is(equalTo("null")));
    assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_CREDENTIALS), is(equalTo("true")));
    assertThat(ReferenceCountUtil.release(response), is(true));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) AsciiString(io.netty.util.AsciiString) Test(org.junit.jupiter.api.Test)

Example 67 with HttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse 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));
    HttpResponse response = channel.readOutbound();
    assertThat(channel.finish(), is(false));
    return response;
}
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)

Example 68 with HttpResponse

use of org.apache.flink.shaded.netty4.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()));
    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 69 with HttpResponse

use of org.apache.flink.shaded.netty4.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()));
    assertThat(ReferenceCountUtil.release(response), is(true));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) AsciiString(io.netty.util.AsciiString) Test(org.junit.jupiter.api.Test)

Example 70 with HttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project netty by netty.

the class CorsHandlerTest method preflightRequestWithValueGenerator.

@Test
public void preflightRequestWithValueGenerator() {
    final CorsConfig config = forOrigin("http://localhost:8888").preflightResponseHeader("GenHeader", new Callable<String>() {

        @Override
        public String call() throws Exception {
            return "generatedValue";
        }
    }).build();
    final HttpResponse response = preflightRequest(config, "http://localhost:8888", "content-type, xheader1");
    assertThat(response.headers().get(of("GenHeader")), equalTo("generatedValue"));
    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) Callable(java.util.concurrent.Callable) Test(org.junit.jupiter.api.Test)

Aggregations

HttpResponse (io.netty.handler.codec.http.HttpResponse)443 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)164 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)109 HttpRequest (io.netty.handler.codec.http.HttpRequest)104 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)86 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)75 Test (org.junit.Test)73 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)72 Test (org.junit.jupiter.api.Test)70 HttpContent (io.netty.handler.codec.http.HttpContent)66 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)64 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)63 ByteBuf (io.netty.buffer.ByteBuf)58 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)51 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)39 IOException (java.io.IOException)39 ChannelFuture (io.netty.channel.ChannelFuture)35 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)33 Map (java.util.Map)33 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)32