protected Reply dupReply(Request request
, org.w3c.www.protocol.http.Reply rep)
throws HTTPException, IOException
{
Reply reply = request.makeReply(rep.getStatus());
// get rid of "by default" headers wchich SHOULD NOT be modified
reply.setHeaderValue(Reply.H_SERVER, null);
// Duplicate reply header values:
Enumeration e = rep.enumerateHeaderDescriptions();
while ( e.hasMoreElements() ) {
HeaderDescription d = (HeaderDescription) e.nextElement();
HeaderValue v = rep.getHeaderValue(d);
if ( v != null )
reply.setHeaderValue(d, v);
}
// Get rid of hop by hop headers:
reply.setHeaderValue(Reply.H_CONNECTION, null);
reply.setHeaderValue(Reply.H_PROXY_CONNECTION, null);
reply.setHeaderValue(Reply.H_PROXY_AUTHENTICATE, null);
reply.setHeaderValue(Reply.H_PUBLIC, null);
reply.setHeaderValue(Reply.H_TRANSFER_ENCODING, null);
reply.setHeaderValue(Reply.H_UPGRADE, null);
reply.setHeaderValue(Reply.H_TRAILER, null);
reply.removeHeader("keep-alive");
// Get rid of the fields enumerated in the connection header:
String conn[] = rep.getConnection();
if (conn != null) {
for (int i = 0 ; i < conn.length ; i++)
reply.removeHeader(conn[i]);
}
// check if nasty people are mixing Content-Length and chunking
if (reply.getContentLength() >= 0 ) {
String te[] = rep.getTransferEncoding() ;
if ( te != null ) {
for (int i = 0 ; i < te.length ; i++) {
if (te[i].equals("chunked")) {
reply.setContentLength(-1);
}
}
}
}
// Update the via route:
reply.addVia(getVia());
// Update the reply output stream:
try {
reply.setStream(rep.getInputStream());
} catch (Exception ex) {};
// if reply is using bad HTTP version we should close it
if (rep.getMajorVersion() == 0) {
reply.setKeepConnection(false);
}
// if HTTP/1.0 and no Content-Length also...
if ((rep.getMajorVersion() == 1) &&
(rep.getMajorVersion() == 0) &&
(reply.getContentLength() == -1)) {
reply.setKeepConnection(false);
}
// check the age
int age = rep.getAge();
if (age >= 0 ) {
// check if it is an heuristic expiration without a warning
if (age > 86400) {
if ((rep.getExpires() == -1) && (rep.getMaxAge() == -1) &&
(rep.getSMaxAge() == -1)) {
// rfc2616: 13.2.4 on behalf of a bad upstream server
HttpWarning w[] = rep.getWarning();
boolean doit = true;
if (w != null) {
for (int i=0; doit && (i<w.length); i++) {
doit = (w[i].getStatus() != 113);
}
}
if (doit) {
reply.addWarning(WARN_HEURISTIC);
}
}
}
}
reply.setProxy(true);
return reply;
}