if (!serverMode) {
throw new IOException("Only in server mode");
}
endSent = false;
IOBuffer sendBody = http.sendBody;
HttpResponse res = http.getResponse();
if (res.isCommitted()) {
return;
}
res.setCommitted(true);
sendBodyState.noBody = !res.hasBody();
if (statusDropsConnection(res.getStatus())) {
closeStreamOnEnd("status drops connection");
}
if (http.error) {
closeStreamOnEnd("error");
}
MultiMap headers = res.getMimeHeaders();
// Add date header
if (headers.getHeader("Date") == null) {
headers.setValue("Date").set(FastHttpDateFormat.getCurrentDate());
}
// Add server header
if (http.serverHeader.length() > 0) {
headers.setValue("Server").set(http.serverHeader);
}
// Decide on a transfer encoding for out.
if (keepAlive()) { // request and user allows keep alive
int cl = res.getContentLength();
if (http10) {
if (cl < 0 && !sendBodyState.noBody &&
sendBody.isAppendClosed()) {
// We can generate content-lenght
cl = sendBody.available();
res.setContentLength(cl);
}
if (cl < 0 && !sendBodyState.noBody) {
closeStreamOnEnd("HTTP/1.0 without content length");
} else {