Java Code Examples for io.netty.handler.codec.http.HttpStatusClass#valueOf()

The following examples show how to use io.netty.handler.codec.http.HttpStatusClass#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultHttp2ConnectionEncoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private static boolean validateHeadersSentState(Http2Stream stream, Http2Headers headers, boolean isServer,
                                                boolean endOfStream) {
    boolean isInformational = isServer && HttpStatusClass.valueOf(headers.status()) == INFORMATIONAL;
    if ((isInformational || !endOfStream) && stream.isHeadersSent() || stream.isTrailersSent()) {
        throw new IllegalStateException("Stream " + stream.id() + " sent too many headers EOS: " + endOfStream);
    }
    return isInformational;
}
 
Example 2
Source File: DefaultHttp2ConnectionDecoder.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency,
        short weight, boolean exclusive, int padding, boolean endOfStream) throws Http2Exception {
    Http2Stream stream = connection.stream(streamId);
    boolean allowHalfClosedRemote = false;
    if (stream == null && !connection.streamMayHaveExisted(streamId)) {
        stream = connection.remote().createStream(streamId, endOfStream);
        // Allow the state to be HALF_CLOSE_REMOTE if we're creating it in that state.
        allowHalfClosedRemote = stream.state() == HALF_CLOSED_REMOTE;
    }

    if (shouldIgnoreHeadersOrDataFrame(ctx, streamId, stream, "HEADERS")) {
        return;
    }

    boolean isInformational = !connection.isServer() &&
            HttpStatusClass.valueOf(headers.status()) == INFORMATIONAL;
    if ((isInformational || !endOfStream) && stream.isHeadersReceived() || stream.isTrailersReceived()) {
        throw streamError(streamId, PROTOCOL_ERROR,
                          "Stream %d received too many headers EOS: %s state: %s",
                          streamId, endOfStream, stream.state());
    }

    switch (stream.state()) {
        case RESERVED_REMOTE:
            stream.open(endOfStream);
            break;
        case OPEN:
        case HALF_CLOSED_LOCAL:
            // Allowed to receive headers in these states.
            break;
        case HALF_CLOSED_REMOTE:
            if (!allowHalfClosedRemote) {
                throw streamError(stream.id(), STREAM_CLOSED, "Stream %d in unexpected state: %s",
                        stream.id(), stream.state());
            }
            break;
        case CLOSED:
            throw streamError(stream.id(), STREAM_CLOSED, "Stream %d in unexpected state: %s",
                    stream.id(), stream.state());
        default:
            // Connection error.
            throw connectionError(PROTOCOL_ERROR, "Stream %d in unexpected state: %s", stream.id(),
                    stream.state());
    }

    stream.headersReceived(isInformational);
    encoder.flowController().updateDependencyTree(streamId, streamDependency, weight, exclusive);

    listener.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive, padding, endOfStream);

    // If the headers completes this stream, close it.
    if (endOfStream) {
        lifecycleManager.closeStreamRemote(stream, ctx.newSucceededFuture());
    }
}
 
Example 3
Source File: AbstractWebResponse.java    From async-gamequery-lib with MIT License 4 votes vote down vote up
public HttpStatusClass getStatus() {
    return HttpStatusClass.valueOf(this.response.getStatusCode());
}