diff --git a/source/net/yacy/cora/protocol/RequestHeader.java b/source/net/yacy/cora/protocol/RequestHeader.java index 9e03fecd8..8ec7be751 100644 --- a/source/net/yacy/cora/protocol/RequestHeader.java +++ b/source/net/yacy/cora/protocol/RequestHeader.java @@ -58,6 +58,8 @@ public class RequestHeader extends HeaderFramework { HTML, JSON, XML } + private Date date_cache_IfModifiedSince = null; + public RequestHeader() { super(); } @@ -86,8 +88,11 @@ public class RequestHeader extends HeaderFramework { return url.getHost(); } + public Date ifModifiedSince() { - return headerDate(IF_MODIFIED_SINCE); + if (this.date_cache_IfModifiedSince != null) return date_cache_IfModifiedSince; + this.date_cache_IfModifiedSince = headerDate(RequestHeader.IF_MODIFIED_SINCE); + return this.date_cache_IfModifiedSince; } public Object ifRange() { diff --git a/source/net/yacy/cora/protocol/ResponseHeader.java b/source/net/yacy/cora/protocol/ResponseHeader.java index 8f7b90b93..c531a334c 100644 --- a/source/net/yacy/cora/protocol/ResponseHeader.java +++ b/source/net/yacy/cora/protocol/ResponseHeader.java @@ -38,6 +38,10 @@ public class ResponseHeader extends HeaderFramework { private static final long serialVersionUID = 0L; private static final ConcurrentLog log = new ConcurrentLog(ResponseHeader.class.getName()); + private Date date_cache_Date = null; + private Date date_cache_Expires = null; + private Date date_cache_LastModified = null; + public ResponseHeader(final int statusCode) { super(); this.put(HeaderFramework.STATUS_CODE, Integer.toString(statusCode)); @@ -69,21 +73,27 @@ public class ResponseHeader extends HeaderFramework { return 200; } } - + public Date date() { + if (this.date_cache_Date != null) return this.date_cache_Date; final Date d = headerDate(HeaderFramework.DATE); final Date now = new Date(); - return (d == null) ? now : d.after(now) ? now : d; + this.date_cache_Date = (d == null) ? now : d.after(now) ? now : d; + return this.date_cache_Date; } public Date expires() { - return headerDate(EXPIRES); + if (this.date_cache_Expires != null) return this.date_cache_Expires; + this.date_cache_Expires = headerDate(HeaderFramework.EXPIRES); + return this.date_cache_Expires; } public Date lastModified() { - final Date d = headerDate(LAST_MODIFIED); + if (this.date_cache_LastModified != null) return this.date_cache_LastModified; + final Date d = headerDate(HeaderFramework.LAST_MODIFIED); final Date now = new Date(); - return (d == null) ? date() : d.after(now) ? now : d; + this.date_cache_LastModified = (d == null) ? date() : d.after(now) ? now : d; + return this.date_cache_LastModified; } public long age() { @@ -94,8 +104,8 @@ public class ResponseHeader extends HeaderFramework { } public boolean gzip() { - return ((containsKey(CONTENT_ENCODING)) && - ((get(CONTENT_ENCODING)).toUpperCase().startsWith("GZIP"))); + return ((containsKey(HeaderFramework.CONTENT_ENCODING)) && + ((get(HeaderFramework.CONTENT_ENCODING)).toUpperCase().startsWith("GZIP"))); } public static Object[] parseResponseLine(final String respLine) {