String uri,
ClientSocket stream)
throws ServletException, IOException
{
ReadStream rs = stream.getInputStream();
WriteStream out = stream.getOutputStream();
try {
out.print(req.getMethod());
out.print(' ');
out.print(uri);
out.print(" HTTP/1.1\r\n");
out.print("Host: ");
String host = req.getHeader("Host");
if (host != null)
out.println(host);
else
out.println(req.getServerName() + ":" + req.getServerPort());
out.print("X-Forwarded-For: ");
out.println(req.getRemoteAddr());
Enumeration<String> e = req.getHeaderNames();
while (e.hasMoreElements()) {
String name = e.nextElement();
if (name.equalsIgnoreCase("Connection"))
continue;
Enumeration<String> e1 = req.getHeaders(name);
while (e1.hasMoreElements()) {
String value = (String) e1.nextElement();
out.print(name);
out.print(": ");
out.println(value);
}
}
int contentLength = req.getContentLength();
InputStream is = req.getInputStream();
TempBuffer tempBuffer = TempBuffer.allocate();
byte []buffer = tempBuffer.getBuffer();
boolean isFirst = true;
if (contentLength >= 0) {
isFirst = false;
out.print("\r\n");
}
int len;
while ((len = is.read(buffer, 0, buffer.length)) > 0) {
if (isFirst) {
out.print("Transfer-Encoding: chunked\r\n");
}
isFirst = false;
if (contentLength < 0) {
out.print("\r\n");
out.print(Integer.toHexString(len));
out.print("\r\n");
}
out.write(buffer, 0, len);
}
if (isFirst) {
out.print("Content-Length: 0\r\n");
}
else
out.print("\r\n0\r\n");
out.print("\r\n");
TempBuffer.free(tempBuffer);
out.flush();
return parseResults(rs, req, res);
} catch (IOException e1) {
log.log(Level.FINE, e1.toString(), e1);