Skip to content

Commit

Permalink
Bug fix: HTTP/1.1 server side stream handler to validate the request …
Browse files Browse the repository at this point in the history
…message before the request routing and handler resolution
  • Loading branch information
ok2c committed May 31, 2024
1 parent 0a4d381 commit 1255be4
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,6 @@ void consumeHeader(final HttpRequest request, final EntityDetails requestEntityD
receivedRequest = request;
requestState = requestEntityDetails == null ? MessageState.COMPLETE : MessageState.BODY;

AsyncServerExchangeHandler handler;
try {
handler = exchangeHandlerFactory.create(request, context);
} catch (final MisdirectedRequestException ex) {
handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_MISDIRECTED_REQUEST, ex.getMessage());
} catch (final HttpException ex) {
handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
}
if (handler == null) {
handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_NOT_FOUND, "Cannot handle request");
}

exchangeHandler = handler;

final ProtocolVersion transportVersion = request.getVersion();
if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
throw new UnsupportedHttpVersionException(transportVersion);
Expand All @@ -268,6 +254,20 @@ void consumeHeader(final HttpRequest request, final EntityDetails requestEntityD

try {
httpProcessor.process(request, requestEntityDetails, context);

AsyncServerExchangeHandler handler;
try {
handler = exchangeHandlerFactory.create(request, context);
} catch (final MisdirectedRequestException ex) {
handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_MISDIRECTED_REQUEST, ex.getMessage());
} catch (final HttpException ex) {
handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
}
if (handler == null) {
handler = new ImmediateResponseExchangeHandler(HttpStatus.SC_NOT_FOUND, "Cannot handle request");
}
exchangeHandler = handler;

exchangeHandler.handleRequest(request, requestEntityDetails, responseChannel, context);
} catch (final HttpException ex) {
if (!responseCommitted.get()) {
Expand Down

0 comments on commit 1255be4

Please sign in to comment.