use of org.apache.hc.core5.http.impl.IncomingEntityDetails in project httpcomponents-core by apache.
the class ClientPushH2StreamHandler method consumeHeader.
@Override
public void consumeHeader(final List<Header> headers, final boolean endStream) throws HttpException, IOException {
if (responseState == MessageState.HEADERS) {
Asserts.notNull(request, "Request");
Asserts.notNull(exchangeHandler, "Exchange handler");
final HttpResponse response = DefaultH2ResponseConverter.INSTANCE.convert(headers);
final EntityDetails entityDetails = endStream ? null : new IncomingEntityDetails(request, -1);
context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
httpProcessor.process(response, entityDetails, context);
connMetrics.incrementResponseCount();
exchangeHandler.consumePromise(request, response, entityDetails, context);
if (endStream) {
responseState = MessageState.COMPLETE;
exchangeHandler.streamEnd(null);
} else {
responseState = MessageState.BODY;
}
} else {
throw new ProtocolException("Unexpected message headers");
}
}
use of org.apache.hc.core5.http.impl.IncomingEntityDetails in project httpcomponents-core by apache.
the class ServerH2StreamHandler method consumeHeader.
@Override
public void consumeHeader(final List<Header> headers, final boolean endStream) throws HttpException, IOException {
if (done.get()) {
throw new ProtocolException("Unexpected message headers");
}
switch(requestState) {
case HEADERS:
requestState = endStream ? MessageState.COMPLETE : MessageState.BODY;
final HttpRequest request = DefaultH2RequestConverter.INSTANCE.convert(headers);
final EntityDetails requestEntityDetails = endStream ? null : new IncomingEntityDetails(request, -1);
final AsyncServerExchangeHandler handler;
try {
handler = exchangeHandlerFactory != null ? exchangeHandlerFactory.create(request, context) : null;
} catch (final ProtocolException ex) {
throw new H2StreamResetException(H2Error.PROTOCOL_ERROR, ex.getMessage());
}
if (handler == null) {
throw new H2StreamResetException(H2Error.REFUSED_STREAM, "Stream refused");
}
exchangeHandler = handler;
context.setProtocolVersion(HttpVersion.HTTP_2);
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
try {
httpProcessor.process(request, requestEntityDetails, context);
connMetrics.incrementRequestCount();
receivedRequest = request;
exchangeHandler.handleRequest(request, requestEntityDetails, responseChannel, context);
} catch (final HttpException ex) {
if (!responseCommitted.get()) {
final AsyncResponseProducer responseProducer = new BasicResponseProducer(ServerSupport.toStatusCode(ex), ServerSupport.toErrorMessage(ex));
exchangeHandler = new ImmediateResponseExchangeHandler(responseProducer);
exchangeHandler.handleRequest(request, requestEntityDetails, responseChannel, context);
} else {
throw ex;
}
}
break;
case BODY:
responseState = MessageState.COMPLETE;
exchangeHandler.streamEnd(headers);
break;
default:
throw new ProtocolException("Unexpected message headers");
}
}
Aggregations