Skip to content

Commit

Permalink
Remove one useless method call in HttpServerResponseImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Oct 24, 2018
1 parent 077a73f commit 85685e6
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions src/main/java/io/vertx/core/http/impl/HttpServerResponseImpl.java
Expand Up @@ -52,6 +52,7 @@
*/
public class HttpServerResponseImpl implements HttpServerResponse {

private static final Buffer EMPTY_BUFFER = Buffer.buffer(Unpooled.EMPTY_BUFFER);
private static final Logger log = LoggerFactory.getLogger(HttpServerResponseImpl.class);

private final VertxInternal vertx;
Expand Down Expand Up @@ -318,7 +319,30 @@ public void end(String chunk, String enc) {
@Override
public void end(Buffer chunk) {
synchronized (conn) {
end0(chunk.getByteBuf());
checkValid();
ByteBuf data = chunk.getByteBuf();
bytesWritten += data.readableBytes();
if (!headWritten) {
// if the head was not written yet we can write out everything in one go
// which is cheaper.
prepareHeaders(bytesWritten);
conn.writeToChannel(new AssembledFullHttpResponse(head, version, status, headers, data, trailingHeaders));
} else {
conn.writeToChannel(new AssembledLastHttpContent(data, trailingHeaders));
}

if (!keepAlive) {
closeConnAfterWrite();
closed = true;
}
written = true;
conn.responseComplete();
if (bodyEndHandler != null) {
bodyEndHandler.handle(null);
}
if (endHandler != null) {
endHandler.handle(null);
}
}
}

Expand All @@ -338,9 +362,7 @@ public void close() {

@Override
public void end() {
synchronized (conn) {
end0(Unpooled.EMPTY_BUFFER);
}
end(EMPTY_BUFFER);
}

@Override
Expand Down Expand Up @@ -399,32 +421,6 @@ public HttpServerResponse bodyEndHandler(Handler<Void> handler) {
}
}

private void end0(ByteBuf data) {
checkValid();
bytesWritten += data.readableBytes();
if (!headWritten) {
// if the head was not written yet we can write out everything in one go
// which is cheaper.
prepareHeaders(bytesWritten);
conn.writeToChannel(new AssembledFullHttpResponse(head, version, status, headers, data, trailingHeaders));
} else {
conn.writeToChannel(new AssembledLastHttpContent(data, trailingHeaders));
}

if (!keepAlive) {
closeConnAfterWrite();
closed = true;
}
written = true;
conn.responseComplete();
if (bodyEndHandler != null) {
bodyEndHandler.handle(null);
}
if (endHandler != null) {
endHandler.handle(null);
}
}

private void doSendFile(String filename, long offset, long length, Handler<AsyncResult<Void>> resultHandler) {
synchronized (conn) {
if (headWritten) {
Expand Down

0 comments on commit 85685e6

Please sign in to comment.