Prevent sending Transfer-encoding: chunked and Content-Length at the same time

Affects issues:
- Fixed #1488
This commit is contained in:
Risto Lahtela 2021-02-12 13:52:05 +02:00
parent da3b71f8b9
commit 6c3382ae87
1 changed files with 5 additions and 1 deletions

View File

@ -91,9 +91,13 @@ public class ResponseSender {
}
private void beginSend() throws IOException {
String length = response.getHeaders().get("Content-Length");
if (length == null || "0".equals(length)) {
exchange.getResponseHeaders().remove("Content-Length");
}
// Return a content length of -1 for HTTP code 204 (No content)
// and HEAD requests to avoid warning messages.
exchange.sendResponseHeaders(response.getCode(), (response.getCode() == 204 || "HEAD".equals(exchange.getRequestMethod())) ? -1 : 0);
exchange.sendResponseHeaders(response.getCode(), (response.getCode() == 204 || "HEAD".equals(exchange.getRequestMethod()) || length == null) ? -1 : Long.parseLong(length));
}
private void sendRawBytes() throws IOException {