Search in sources :

Example 76 with HttpResponseStatus

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

the class HttpClientWithTomcatTest method contentHeader.

@Test
void contentHeader() {
    ConnectionProvider fixed = ConnectionProvider.create("contentHeader", 1);
    HttpClient client = HttpClient.create(fixed).wiretap(true).headers(h -> h.add("content-length", "1"));
    HttpResponseStatus r = client.request(HttpMethod.GET).uri(getURL()).send(ByteBufFlux.fromString(Mono.just(" "))).responseSingle((res, buf) -> Mono.just(res.status())).block(Duration.ofSeconds(30));
    client.request(HttpMethod.GET).uri(getURL()).send(ByteBufFlux.fromString(Mono.just(" "))).responseSingle((res, buf) -> Mono.just(res.status())).block(Duration.ofSeconds(30));
    assertThat(r).isEqualTo(HttpResponseStatus.BAD_REQUEST);
    fixed.dispose();
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Tuples(reactor.util.function.Tuples) Tuple2(reactor.util.function.Tuple2) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) ByteBufFlux(reactor.netty.ByteBufFlux) TomcatServer(reactor.netty.TomcatServer) Duration(java.time.Duration) Path(java.nio.file.Path) HttpHeaderValues(io.netty.handler.codec.http.HttpHeaderValues) Files(java.nio.file.Files) HttpMethod(io.netty.handler.codec.http.HttpMethod) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Mono(reactor.core.publisher.Mono) Channel(io.netty.channel.Channel) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) Paths(java.nio.file.Paths) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) ConnectionProvider(reactor.netty.resources.ConnectionProvider) InputStream(java.io.InputStream) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) ConnectionProvider(reactor.netty.resources.ConnectionProvider) Test(org.junit.jupiter.api.Test)

Example 77 with HttpResponseStatus

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

the class AccessLogHandlerH1 method write.

@Override
@SuppressWarnings("FutureReturnValueIgnored")
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
    if (msg instanceof HttpResponse) {
        final HttpResponse response = (HttpResponse) msg;
        final HttpResponseStatus status = response.status();
        if (status.equals(HttpResponseStatus.CONTINUE)) {
            // "FutureReturnValueIgnored" this is deliberate
            ctx.write(msg, promise);
            return;
        }
        final boolean chunked = HttpUtil.isTransferEncodingChunked(response);
        accessLogArgProvider.response(response).chunked(chunked);
        if (!chunked) {
            accessLogArgProvider.contentLength(HttpUtil.getContentLength(response, -1));
        }
        ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel());
        if (ops instanceof HttpInfos) {
            accessLogArgProvider.cookies(((HttpInfos) ops).cookies());
        }
    }
    if (msg instanceof LastHttpContent) {
        accessLogArgProvider.increaseContentLength(((LastHttpContent) msg).content().readableBytes());
        ctx.write(msg, promise.unvoid()).addListener(future -> {
            if (future.isSuccess()) {
                AccessLog log = accessLog.apply(accessLogArgProvider);
                if (log != null) {
                    log.log();
                }
                accessLogArgProvider.clear();
            }
        });
        return;
    }
    if (msg instanceof ByteBuf) {
        accessLogArgProvider.increaseContentLength(((ByteBuf) msg).readableBytes());
    }
    if (msg instanceof ByteBufHolder) {
        accessLogArgProvider.increaseContentLength(((ByteBufHolder) msg).content().readableBytes());
    }
    // "FutureReturnValueIgnored" this is deliberate
    ctx.write(msg, promise);
}
Also used : HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) HttpResponse(io.netty.handler.codec.http.HttpResponse) ByteBufHolder(io.netty.buffer.ByteBufHolder) HttpInfos(reactor.netty.http.HttpInfos) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)73 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)17 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)16 ByteBuf (io.netty.buffer.ByteBuf)15 HttpMethod (io.netty.handler.codec.http.HttpMethod)11 IOException (java.io.IOException)11 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)10 HttpResponse (io.netty.handler.codec.http.HttpResponse)10 HttpVersion (io.netty.handler.codec.http.HttpVersion)9 Map (java.util.Map)8 URI (java.net.URI)7 Test (org.junit.Test)7 URISyntaxException (java.net.URISyntaxException)6 Test (org.junit.jupiter.api.Test)6 Channel (io.netty.channel.Channel)5 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)5 Duration (java.time.Duration)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4