Search in sources :

Example 81 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 82 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)

Example 83 with HttpResponse

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

the class CorsHandlerTest method preflightRequestWithDefaultHeaders.

@Test
public void preflightRequestWithDefaultHeaders() {
    final CorsConfig config = forOrigin("http://localhost:8888").build();
    final HttpResponse response = preflightRequest(config, "http://localhost:8888", "content-type, xheader1");
    assertThat(response.headers().get(CONTENT_LENGTH), is("0"));
    assertThat(response.headers().get(DATE), is(notNullValue()));
    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 84 with HttpResponse

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

the class CorsHandlerTest method simpleRequestAllowCredentials.

@Test
public void simpleRequestAllowCredentials() {
    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(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 85 with HttpResponse

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

the class CorsHandlerTest method simpleRequestExposeHeaders.

@Test
public void simpleRequestExposeHeaders() {
    final CorsConfig config = forAnyOrigin().exposeHeaders("one", "two").build();
    final HttpResponse response = simpleRequest(config, "http://localhost:7777");
    assertThat(response.headers().get(ACCESS_CONTROL_EXPOSE_HEADERS), containsString("one"));
    assertThat(response.headers().get(ACCESS_CONTROL_EXPOSE_HEADERS), containsString("two"));
    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)

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