void consumeHeader()

in httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java [194:249]


    void consumeHeader(final HttpResponse response, final EntityDetails entityDetails) throws HttpException, IOException {
        if (done.get() || responseState != MessageState.HEADERS) {
            throw new ProtocolException("Unexpected message head");
        }
        final ProtocolVersion transportVersion = response.getVersion();
        if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
            throw new UnsupportedHttpVersionException(transportVersion);
        }

        final int status = response.getCode();
        if (status < HttpStatus.SC_INFORMATIONAL) {
            throw new ProtocolException("Invalid response: " + new StatusLine(response));
        }
        if (status > HttpStatus.SC_CONTINUE && status < HttpStatus.SC_SUCCESS) {
            exchangeHandler.consumeInformation(response, context);
        } else {
            if (!connectionReuseStrategy.keepAlive(committedRequest, response, context)) {
                keepAlive = false;
            }
        }
        if (requestState == MessageState.ACK) {
            if (status == HttpStatus.SC_CONTINUE || status >= HttpStatus.SC_SUCCESS) {
                outputChannel.setSocketTimeout(timeout);
                requestState = MessageState.BODY;
                if (status < HttpStatus.SC_CLIENT_ERROR) {
                    exchangeHandler.produce(internalDataChannel);
                }
            }
        }
        if (status < HttpStatus.SC_SUCCESS) {
            return;
        }
        if (requestState == MessageState.BODY) {
            if (status >= HttpStatus.SC_CLIENT_ERROR) {
                requestState = MessageState.COMPLETE;
                if (!outputChannel.abortGracefully()) {
                    keepAlive = false;
                }
            }
        }

        context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
        context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
        httpProcessor.process(response, entityDetails, context);

        if (entityDetails == null && !keepAlive) {
            outputChannel.close();
        }

        exchangeHandler.consumeResponse(response, entityDetails, context);
        if (entityDetails == null) {
            responseState = MessageState.COMPLETE;
        } else {
            responseState = MessageState.BODY;
        }
    }