Example usage for io.netty.handler.codec.http HttpStatusClass INFORMATIONAL

List of usage examples for io.netty.handler.codec.http HttpStatusClass INFORMATIONAL

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpStatusClass INFORMATIONAL.

Prototype

HttpStatusClass INFORMATIONAL

To view the source code for io.netty.handler.codec.http HttpStatusClass INFORMATIONAL.

Click Source Link

Document

The informational class (1xx)

Usage

From source file:com.linecorp.armeria.client.http.Http1ResponseDecoder.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (!(msg instanceof HttpObject)) {
        ctx.fireChannelRead(msg);//  w w  w  . ja  v a  2  s  .c om
        return;
    }

    try {
        switch (state) {
        case NEED_HEADERS:
            if (msg instanceof HttpResponse) {
                final HttpResponse nettyRes = (HttpResponse) msg;
                final DecoderResult decoderResult = nettyRes.decoderResult();
                if (!decoderResult.isSuccess()) {
                    fail(ctx, new ProtocolViolationException(decoderResult.cause()));
                    return;
                }

                if (!HttpUtil.isKeepAlive(nettyRes)) {
                    disconnectWhenFinished();
                }

                final HttpResponseWrapper res = getResponse(resId);
                assert res != null;
                this.res = res;

                if (nettyRes.status().codeClass() == HttpStatusClass.INFORMATIONAL) {
                    state = State.NEED_INFORMATIONAL_DATA;
                } else {
                    state = State.NEED_DATA_OR_TRAILING_HEADERS;
                    res.scheduleTimeout(ctx);
                }

                res.write(ArmeriaHttpUtil.toArmeria(nettyRes));
            } else {
                failWithUnexpectedMessageType(ctx, msg);
            }
            break;
        case NEED_INFORMATIONAL_DATA:
            if (msg instanceof LastHttpContent) {
                state = State.NEED_HEADERS;
            } else {
                failWithUnexpectedMessageType(ctx, msg);
            }
            break;
        case NEED_DATA_OR_TRAILING_HEADERS:
            if (msg instanceof HttpContent) {
                final HttpContent content = (HttpContent) msg;
                final DecoderResult decoderResult = content.decoderResult();
                if (!decoderResult.isSuccess()) {
                    fail(ctx, new ProtocolViolationException(decoderResult.cause()));
                    return;
                }

                final ByteBuf data = content.content();
                final int dataLength = data.readableBytes();
                if (dataLength > 0) {
                    final long maxContentLength = res.maxContentLength();
                    if (maxContentLength > 0 && res.writtenBytes() > maxContentLength - dataLength) {
                        fail(ctx, ContentTooLargeException.get());
                        return;
                    } else {
                        res.write(HttpData.of(data));
                    }
                }

                if (msg instanceof LastHttpContent) {
                    final HttpResponseWriter res = removeResponse(resId++);
                    assert this.res == res;
                    this.res = null;

                    state = State.NEED_HEADERS;

                    final HttpHeaders trailingHeaders = ((LastHttpContent) msg).trailingHeaders();
                    if (!trailingHeaders.isEmpty()) {
                        res.write(ArmeriaHttpUtil.toArmeria(trailingHeaders));
                    }

                    res.close();

                    if (needsToDisconnect()) {
                        ctx.close();
                    }
                }
            } else {
                failWithUnexpectedMessageType(ctx, msg);
            }
            break;
        case DISCARD:
            break;
        }
    } finally {
        ReferenceCountUtil.release(msg);
    }
}

From source file:com.linecorp.armeria.client.Http1ResponseDecoder.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (!(msg instanceof HttpObject)) {
        ctx.fireChannelRead(msg);/*  www  .  j  av  a2s.  com*/
        return;
    }

    try {
        switch (state) {
        case NEED_HEADERS:
            if (msg instanceof HttpResponse) {
                final HttpResponse nettyRes = (HttpResponse) msg;
                final DecoderResult decoderResult = nettyRes.decoderResult();
                if (!decoderResult.isSuccess()) {
                    fail(ctx, new ProtocolViolationException(decoderResult.cause()));
                    return;
                }

                if (!HttpUtil.isKeepAlive(nettyRes)) {
                    disconnectWhenFinished();
                }

                final HttpResponseWrapper res = getResponse(resId);
                assert res != null;
                this.res = res;

                if (nettyRes.status().codeClass() == HttpStatusClass.INFORMATIONAL) {
                    state = State.NEED_INFORMATIONAL_DATA;
                } else {
                    state = State.NEED_DATA_OR_TRAILING_HEADERS;
                }

                res.scheduleTimeout(ctx);
                res.write(ArmeriaHttpUtil.toArmeria(nettyRes));
            } else {
                failWithUnexpectedMessageType(ctx, msg);
            }
            break;
        case NEED_INFORMATIONAL_DATA:
            if (msg instanceof LastHttpContent) {
                state = State.NEED_HEADERS;
            } else {
                failWithUnexpectedMessageType(ctx, msg);
            }
            break;
        case NEED_DATA_OR_TRAILING_HEADERS:
            if (msg instanceof HttpContent) {
                final HttpContent content = (HttpContent) msg;
                final DecoderResult decoderResult = content.decoderResult();
                if (!decoderResult.isSuccess()) {
                    fail(ctx, new ProtocolViolationException(decoderResult.cause()));
                    return;
                }

                final ByteBuf data = content.content();
                final int dataLength = data.readableBytes();
                if (dataLength > 0) {
                    assert res != null;
                    final long maxContentLength = res.maxContentLength();
                    if (maxContentLength > 0 && res.writtenBytes() > maxContentLength - dataLength) {
                        fail(ctx, ContentTooLargeException.get());
                        return;
                    } else {
                        res.write(HttpData.of(data));
                    }
                }

                if (msg instanceof LastHttpContent) {
                    final HttpResponseWrapper res = removeResponse(resId++);
                    assert res != null;
                    assert this.res == res;
                    this.res = null;

                    state = State.NEED_HEADERS;

                    final HttpHeaders trailingHeaders = ((LastHttpContent) msg).trailingHeaders();
                    if (!trailingHeaders.isEmpty()) {
                        res.write(ArmeriaHttpUtil.toArmeria(trailingHeaders));
                    }

                    res.close();

                    if (needsToDisconnect()) {
                        ctx.close();
                    }
                }
            } else {
                failWithUnexpectedMessageType(ctx, msg);
            }
            break;
        case DISCARD:
            break;
        }
    } finally {
        ReferenceCountUtil.release(msg);
    }
}

From source file:com.linecorp.armeria.server.http.Http1RequestDecoder.java

License:Apache License

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    if (msg instanceof HttpResponse
            && ((HttpResponse) msg).status().codeClass() != HttpStatusClass.INFORMATIONAL) {
        sentResponses++;//from w w w .j  ava2 s.  com
    }
    ctx.write(msg, promise);
}

From source file:reactor.ipc.netty.http.server.HttpServerHandler.java

License:Open Source License

static boolean isInformational(HttpResponse response) {
    return response.status().codeClass() == HttpStatusClass.INFORMATIONAL;
}