if (requestVersion.equals ("HTTP/1.1")) {
String host = header.getHeader ("Host");
if (host == null) {
Exception exe =
new Exception ("No host header set in HTTP/1.1 request");
HttpHeader ret =
con.getHttpGenerator ().get400 (exe);
return ret;
}
maychunk = true;
String closeit = header.getHeader ("Proxy-Connection");
if (closeit == null)
closeit = header.getHeader ("Connection");
mayKeepAlive = (closeit == null
|| !closeit.equalsIgnoreCase ("close"));
} else {
header.setHTTPVersion ("HTTP/1.1");
maychunk = false;
// stupid netscape to not follow the standards,
// only "Connection" should be used...
String keepalive = header.getHeader ("Proxy-Connection");
mayKeepAlive = (keepalive != null
&& keepalive.equalsIgnoreCase ("Keep-Alive"));
if (!mayKeepAlive) {
keepalive = header.getHeader ("Connection");
mayKeepAlive = (keepalive != null
&& keepalive.equalsIgnoreCase ("Keep-Alive"));
}
}
boolean useCached = true;
boolean cacheAllowed = true;
// damn how many system that use cookies with id's
/*
System.out.println ("auth: " + header.getHeader ("authorization") +
", cookie:" + header.getHeader ("cookie") +
", Pragma: " + header.getHeader ("Pragma") +
", Cache: " + header.getHeader ("Cache-Control"));
*/
//String cached = header.getHeader ("Pragma");
List<String> ccs = header.getHeaders ("Cache-Control");
for (String cached : ccs) {
cached = cached.trim ();
if (cached.equals ("no-store")) {
useCached = false;
cacheAllowed = false;
} else if (cached.equals ("no-cache")) {
useCached = false;
} else if (cached.equals ("no-transform")) {
useCached = false; // cache is transformed.
cacheAllowed = false; // dont store, no point.
con.setMayFilter (false);
}
}
ccs = header.getHeaders ("Pragma");
for (String cached : ccs) {
cached = cached.trim ();
if (cached.equals ("no-cache")) {
useCached = false;
}
}
String method = header.getMethod ().trim ();
if (!method.equals ("GET") && !method.equals ("HEAD")) {
useCached = false;
cacheAllowed = false;
//mayKeepAlive = false;
} else if (method.equals ("HEAD")) {
maychunk = false;
}
con.setChunking (maychunk);
String mf = header.getHeader ("Max-Forwards");
if (mf != null) {
HttpHeader ret = checkMaxForwards (con, header, mf);
if (ret != null) {
return ret;
}
}
String auths = header.getHeader ("authorization");
if (auths != null) {
useCached = false; // dont use cached files,
cacheAllowed = false; // and dont cache it.
} else if (cookieId) {
String cookie = header.getHeader ("cookie");
String lccookie = null;
if (cookie != null && // cookie-passwords suck.
(((lccookie = cookie.toLowerCase ()).indexOf ("password") >= 0)
|| (lccookie.indexOf ("id") >= 0))) {
useCached = false; // dont use cached files,
cacheAllowed = false; // and dont cache it.
}
}
con.setMayUseCache (useCached);
con.setMayCache (cacheAllowed);
con.setKeepalive (mayKeepAlive);
String requri = header.getRequestURI ();
if (requri.toLowerCase ().startsWith (NOPROXY))
requri = handleNoProxyRequest (requri, header, con);
HttpHeader headerr = handleURLSetup (requri, header, con);
if (headerr != null)
return headerr;
removeConnectionTokens (header);
int rsize = removes.size ();