Skip to content

Commit

Permalink
Avoid to set the content length multiple times and thus check the con…
Browse files Browse the repository at this point in the history
…tent length is already set twice
  • Loading branch information
vietj committed Jun 25, 2017
1 parent 67486be commit ca64cff
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/main/java/io/vertx/core/http/impl/HttpServerResponseImpl.java
Expand Up @@ -314,11 +314,7 @@ public void end(String chunk, String enc) {
@Override
public void end(Buffer chunk) {
synchronized (conn) {
if (!chunked && !headers.contentLengthSet()) {
headers.set(HttpHeaders.CONTENT_LENGTH, String.valueOf(chunk.length()));
}
ByteBuf buf = chunk.getByteBuf();
end0(buf);
end0(chunk.getByteBuf());
}
}

Expand Down Expand Up @@ -467,9 +463,6 @@ private void doSendFile(String filename, long offset, long length, Handler<Async

long contentLength = Math.min(length, file.length() - offset);
bytesWritten = contentLength;
if (!headers.contentLengthSet()) {
putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(contentLength));
}
if (!headers.contentTypeSet()) {
String contentType = MimeMapping.getMimeTypeForFilename(filename);
if (contentType != null) {
Expand Down Expand Up @@ -583,8 +576,9 @@ private void prepareHeaders() {
if (!head) {
if (chunked) {
headers.set(HttpHeaders.TRANSFER_ENCODING, HttpHeaders.CHUNKED);
} else if (keepAlive && !headers.contentLengthSet()) {
headers.set(HttpHeaders.CONTENT_LENGTH, "0");
} else if (!headers.contentLengthSet()) {
String value = bytesWritten == 0 ? "0" : String.valueOf(bytesWritten);
headers.set(HttpHeaders.CONTENT_LENGTH, value);
}
}
if (headersEndHandler != null) {
Expand Down

0 comments on commit ca64cff

Please sign in to comment.