in httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java [210:264]
void consumeHeader(final HttpResponse response, final EntityDetails entityDetails) throws HttpException, IOException {
if (done.get() || responseState.get() != MessageState.HEADERS) {
throw new ProtocolException("Unexpected message head");
}
final ProtocolVersion transportVersion = response.getVersion();
if (transportVersion != null) {
if (transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
throw new UnsupportedHttpVersionException(transportVersion);
}
context.setProtocolVersion(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.get() == MessageState.ACK) {
if (status == HttpStatus.SC_CONTINUE || status >= HttpStatus.SC_SUCCESS) {
outputChannel.setSocketTimeout(timeout);
requestState.set(MessageState.BODY);
if (status < HttpStatus.SC_CLIENT_ERROR) {
exchangeHandler.produce(internalDataChannel);
}
}
}
if (status < HttpStatus.SC_SUCCESS) {
return;
}
if (requestState.get() == MessageState.BODY) {
if (status >= HttpStatus.SC_CLIENT_ERROR) {
requestState.set(MessageState.COMPLETE);
if (!outputChannel.abortGracefully()) {
keepAlive = false;
}
}
}
context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
context.setResponse(response);
httpProcessor.process(response, entityDetails, context);
if (entityDetails == null && !keepAlive) {
outputChannel.close();
}
exchangeHandler.consumeResponse(response, entityDetails, context);
responseState.set(entityDetails == null ? MessageState.COMPLETE : MessageState.BODY);
}