| Code with Finding: |
class CachedResource {
public void setReplyHeaders(Reply reply) {
ArrayDictionary a = getExtraHeaders();
if ( reply.getStatus() != HTTP.NOT_MODIFIED ) {
int cl = getContentLength();
if ((cl >= 0) && (reply.getStatus() != HTTP.PARTIAL_CONTENT))
reply.setContentLength(getContentLength());
reply.setContentType(getContentType());
reply.setLastModified(getLastModified());
// Take all remaining extra headers, and define them:
if ( a != null ) {
// This is the slowest operation of the whole cache :-(
Enumeration e = a.keys();
while (e.hasMoreElements() ) {
String hname = (String) e.nextElement();
String hvalue = (String) a.get(hname);
reply.setValue(hname, hvalue);
}
}
} else {
// Unset from orig reply, the headers that are not needed:
reply.setContentLength(-1);
// Just pick the mandatory ones (HTTP/1.1, draft 7, 10.3.5)
// I am happy not to have to write the *fastest* server
if ( a != null ) {
String str = (String) a.get("cache-control");
if ( str != null )
reply.setValue("cache-control", str);
str = (String) a.get("expires");
if ( str != null )
reply.setValue("expires", str);
str = (String) a.get("vary");
if ( str != null )
reply.setValue("vary", str);
str = (String) a.get("content-location");
if ( str != null )
reply.setValue("content-location", str);
}
}
if (reply.getStatus() == HTTP.PARTIAL_CONTENT)
reply.setContentMD5(null);
reply.setAge((int) (computeCurrentAge() / 1000));
long date = getDate();
if ( date > 0 )
reply.setDate(getDate());
// Always send the etag, if available:
reply.setETag(getHETag());
/*
if ((etags == null) && definesAttribute(ATTR_ETAG)) {
etags = new HttpEntityTag[1];
etags[0] = HttpFactory.parseETag(getETag());
}
if ( etags != null )
reply.setETag(etags[0]);
*/
}
}
|