*/
public void
sendResponse(InputStream in, int length, String type, int code)
throws IOException
{
HttpInputStream hin = new HttpInputStream(in);
byte[] buf = new byte[server.bufsize];
if (length >= 0) {
sendHeaders(code, type, length);
if (!method.equals("HEAD")) {
if (hin.copyTo(out, length, buf) != length) {
keepAlive = false;
}
}
} else if (version <= 10) {
keepAlive = false;
sendHeaders(code, type, -1);
if (!method.equals("HEAD")) {
hin.copyTo(out, -1, buf);
}
} else {
if (method.equals("HEAD")) {
sendHeaders(code, type, -1);
return;
}
addHeader("Transfer-Encoding", "chunked");
sendHeaders(code, type, -1);
while (true) {
int count = hin.read(buf);
if (count < 0) {
out.writeBytes("0\r\n\r\n");
break;
}
out.writeBytes(Integer.toHexString(count) + "\r\n");