+ cacheControlMap.putAll(cacheParams);
+ }
+
+ @Override
+ public Map<String,String> getAdditionalHeaders(HttpServletRequest request) {
+ if (zipped && !out.empty)
+ return ADDITIONAL_HEADERS_GZIP;
+ else
+ return ADDITIONAL_HEADERS_NONE;
+ }
+
+ public void guessingFinished() {
+ guessing = false;
+ }
+
+
+ private void analyzeHeader(String name, String value, boolean overwrite) {
+ if (name == null)
+ return;
+ name = name.trim();
+
+ if (name.equalsIgnoreCase(Headers.HEADER_DATE)) {
+ if (value == null) {
+ if (overwrite) {
+ now = System.currentTimeMillis();
+ cacheSeconds = AcceleratorFilter.this.cacheSeconds;
+ }
+ return;
+ }
+ try {
+ SimpleDateFormat parser = new SimpleDateFormat(Headers.RFC_1123_DATE_FORMAT, Locale.US);
+ now = parser.parse(value).getTime();
+ calculateCacheSeconds();
+ }
+ catch (ParseException e) {
+ log.warn("ignoring date for header \"Date\" in invalid format: {}", value);
+ }
+ return;
+ }
+
+ if (name.equalsIgnoreCase(Headers.HEADER_EXPIRES)) {
+ if (value == null) {
+ if (overwrite) {
+ expires = 0;
+ cacheSeconds = AcceleratorFilter.this.cacheSeconds;
+ }
+ return;
+ }
+ try {
+ SimpleDateFormat parser = new SimpleDateFormat(Headers.RFC_1123_DATE_FORMAT, Locale.US);
+ expires = parser.parse(value).getTime();
+ calculateCacheSeconds();
+ }
+ catch (ParseException e) {
+ log.warn("ignoring date for header \"Expires\" in invalid format: {}", value);
+ }
+ return;
+ }
+
+ if (name.equalsIgnoreCase(Headers.HEADER_LAST_MODIFIED)) {
+ if (value == null) {
+ if (overwrite)
+ lastModified = AcceleratorFilter.this.lastModified;
+ return;
+ }
+ try {
+ SimpleDateFormat parser = new SimpleDateFormat(Headers.RFC_1123_DATE_FORMAT, Locale.US);
+ lastModified = parser.parse(value).getTime();
+ }
+ catch (ParseException e) {
+ log.warn("ignoring date for header \"Last-Modified\" in invalid format: {}", value);
+ }
+ return;
+ }
+
+ if (name.equalsIgnoreCase(Headers.HEADER_ETAG)) {
+ if (value == null) {
+ if (overwrite) {
+ eTag = AcceleratorFilter.this.eTag;
+ weak = AcceleratorFilter.this.weak;
+ }
+ return;
+ }
+ value = value.trim();
+ int start = 0;
+ int end = value.length();
+ if (value.startsWith("W/")) {
+ weak = true;
+ start = 2;
+ }
+ else {
+ weak = false;
+ }
+ if (value.charAt(start) == '"')
+ start++;
+ else
+ log.warn("Quote at the beginning ov ETag is missing: {}", value);
+ if (value.charAt(end -1) == '"')
+ end--;
+ else
+ log.warn("Quote at the end of ETag is missing: {}", value);
+ eTag = value.substring(start, end);
+ String filtered = eTag.replaceAll("[^\\x00-\\x21\\x23-\\x7F]+","");
+ if (filtered.length() < eTag.length()) {
+ log.warn("filtering out illegal characters in ETag: \"{}\" -> \"{}\"", eTag, filtered);
+ eTag = filtered;
+ }
+ }
+
+ if (name.equalsIgnoreCase(Headers.HEADER_CACHE_CONTROL)) {
+ if (overwrite)
+ cacheParams.clear();
+ if (value == null)
+ return;
+ for (String param : value.split(",")) {
+ param = param.trim();
+ int pos = param.indexOf("=");
+ if (pos < 0) {
+ cacheParams.put(param, null);
+ }
+ else {
+ String paramName = param.substring(0, pos).trim();
+ if (paramName.equalsIgnoreCase("max-age")) {
+ try {
+ cacheSeconds = Integer.parseInt(param.substring(pos + 1));
+ cacheSecondsSet = true;
+ }
+ catch (NumberFormatException e) {
+ log.warn("illegal value for Header \"Cache-Control\":", param);
+ }
+ }
+ else {
+ cacheParams.put(paramName, param.substring(pos + 1));
+ }
+ }
+ }
+ return;
+ }
+
+ if (name.equalsIgnoreCase(Headers.HEADER_PRAGMA)) {
+ if (value != null && value.trim().equalsIgnoreCase("no-cache"))
+ cacheSeconds = 0;
+ return;
+ }
+
+ /** Pass header through, if no value from intrest was found */
+ if (overwrite)
+ super.setHeader(name, value);
+ else
+ super.addHeader(name, value);
+ }
+
+ private void calculateCacheSeconds() {
+ if (!cacheSecondsSet && expires >= now) {
+ cacheSeconds = (int)(expires/1000 - now/1000);
+ log.debug("calculating cache-seconds from DATE and EXPIRES: {}", cacheSeconds);
+ }