Skip to content

Commit 7016ed1

Browse files
author
Robert Engels
committed
avoid unnecessary flush
1 parent 6fbbe75 commit 7016ed1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/main/java/robaho/net/httpserver/ExchangeImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,8 @@ public void sendResponseHeaders(int rCode, long contentLen)
217217
this.rcode = rCode;
218218
String statusLine = rCode == 101 ? "HTTP/1.1 101 Switching Protocols\r\n"
219219
: "HTTP/1.1 " + rCode + Code.msg(rCode) + "\r\n";
220-
OutputStream tmpout = new BufferedOutputStream(ros);
221220
PlaceholderOutputStream o = getPlaceholderResponseBody();
222-
tmpout.write(bytes(statusLine, 0), 0, statusLine.length());
221+
ros.write(bytes(statusLine, 0), 0, statusLine.length());
223222
boolean noContentToSend = false; // assume there is content
224223
boolean noContentLengthHeader = false; // must not send Content-length is set
225224
rspHdrs.set("Date", FORMATTER.format(Instant.now()));
@@ -299,12 +298,13 @@ public void sendResponseHeaders(int rCode, long contentLen)
299298
}
300299
}
301300

302-
write(rspHdrs, tmpout);
301+
write(rspHdrs, ros);
303302
this.rspContentLen = contentLen;
304-
tmpout.flush();
305-
tmpout = null;
306303
sentHeaders = true;
307304
logger.log(Level.TRACE, "Sent headers: noContentToSend=" + noContentToSend);
305+
if(contentLen==0) {
306+
ros.flush();
307+
}
308308
if (noContentToSend) {
309309
close();
310310
}

0 commit comments

Comments
 (0)