use of org.apache.hc.core5.http.ProtocolVersion in project httpcomponents-core by apache.
the class ServerHttp1StreamHandler method commitResponse.
private void commitResponse(final HttpResponse response, final EntityDetails responseEntityDetails) throws HttpException, IOException {
if (responseCommitted.compareAndSet(false, true)) {
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_SUCCESS) {
throw new HttpException("Invalid response: " + status);
}
context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
httpProcessor.process(response, responseEntityDetails, context);
final boolean endStream = responseEntityDetails == null || (receivedRequest != null && Method.HEAD.isSame(receivedRequest.getMethod()));
if (!connectionReuseStrategy.keepAlive(receivedRequest, response, context)) {
keepAlive = false;
}
outputChannel.submit(response, endStream, endStream ? FlushMode.IMMEDIATE : FlushMode.BUFFER);
if (endStream) {
if (!keepAlive) {
outputChannel.close();
}
responseState = MessageState.COMPLETE;
} else {
responseState = MessageState.BODY;
exchangeHandler.produce(internalDataChannel);
}
} else {
throw new HttpException("Response already committed");
}
}
use of org.apache.hc.core5.http.ProtocolVersion in project httpcomponents-core by apache.
the class DefaultHttpResponseWriter method writeHeadLine.
@Override
protected void writeHeadLine(final T message, final CharArrayBuffer lineBuf) throws IOException {
lineBuf.clear();
final ProtocolVersion transportVersion = message.getVersion();
getLineFormatter().formatStatusLine(lineBuf, new StatusLine(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1, message.getCode(), message.getReasonPhrase()));
}
Aggregations