Skip to content

Commit

Permalink
fixes #757 avoid parsing the body if content-type is missing (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Aug 25, 2020
1 parent de20020 commit 2a14b2f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions body/src/main/java/com/networknt/body/BodyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public BodyHandler() {
public void handleRequest(final HttpServerExchange exchange) throws Exception {
// parse the body to map or list if content type is application/json
String contentType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE);
if (exchange.isInIoThread()) {
exchange.dispatch(this);
return;
}
exchange.startBlocking();
if (contentType != null) {
if (exchange.isInIoThread()) {
exchange.dispatch(this);
return;
}
exchange.startBlocking();
try {
if (contentType.startsWith("application/json")) {
InputStream inputStream = exchange.getInputStream();
Expand All @@ -119,10 +119,6 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
setExchangeStatus(exchange, CONTENT_TYPE_MISMATCH, contentType);
return;
}
} else {
// attach the stream to the exchange if the content type is missing.
InputStream inputStream = exchange.getInputStream();
exchange.putAttachment(REQUEST_BODY, inputStream);
}
Handler.next(exchange, next);
}
Expand Down

0 comments on commit 2a14b2f

Please sign in to comment.