--- /c/home/os/tmp/apache-tomcat-6.0.18-src/java/org/apache/catalina/servlets/DefaultServlet.java 2008-07-22 02:01:30.000000000 +0200 +++ org/apache/catalina/servlets/DefaultServlet.java 2009-02-02 10:48:46.578125000 +0100 @@ -561,34 +561,19 @@ HttpServletResponse response, ResourceAttributes resourceAttributes) throws IOException { + + // the logic here is that a function that detects that it can send + // a reply will do so and return false. So it is safe to drop + // checkIfMatch and checkIfNoneMatch from the following expression + // to eliminate ETag handling - return checkIfMatch(request, response, resourceAttributes) - && checkIfModifiedSince(request, response, resourceAttributes) - && checkIfNoneMatch(request, response, resourceAttributes) + return checkIfModifiedSince(request, response, resourceAttributes) && checkIfUnmodifiedSince(request, response, resourceAttributes); } /** - * Get the ETag associated with a file. - * - * @param resourceAttributes The resource information - */ - protected String getETag(ResourceAttributes resourceAttributes) { - String result = null; - if ((result = resourceAttributes.getETag(true)) != null) { - return result; - } else if ((result = resourceAttributes.getETag()) != null) { - return result; - } else { - return "W/\"" + resourceAttributes.getContentLength() + "-" - + resourceAttributes.getLastModified() + "\""; - } - } - - - /** * URL rewriter. * * @param path Path which has to be rewiten @@ -723,7 +708,7 @@ ranges = parseRange(request, response, cacheEntry.attributes); // ETag header - response.setHeader("ETag", getETag(cacheEntry.attributes)); + // response.setHeader("ETag", getETag(cacheEntry.attributes)); // Last-Modified header response.setHeader("Last-Modified", @@ -969,14 +954,14 @@ ; } - String eTag = getETag(resourceAttributes); + // eTag = getETag(resourceAttributes); long lastModified = resourceAttributes.getLastModified(); if (headerValueTime == (-1L)) { // If the ETag the client gave does not match the entity // etag, then the entire entity is returned. - if (!eTag.equals(headerValue.trim())) + // if (!eTag.equals(headerValue.trim())) return FULL; } else { @@ -1505,50 +1490,6 @@ } } - - /** - * Check if the if-match condition is satisfied. - * - * @param request The servlet request we are processing - * @param response The servlet response we are creating - * @param resourceInfo File object - * @return boolean true if the resource meets the specified condition, - * and false if the condition is not satisfied, in which case request - * processing is stopped - */ - protected boolean checkIfMatch(HttpServletRequest request, - HttpServletResponse response, - ResourceAttributes resourceAttributes) - throws IOException { - - String eTag = getETag(resourceAttributes); - String headerValue = request.getHeader("If-Match"); - if (headerValue != null) { - if (headerValue.indexOf('*') == -1) { - - StringTokenizer commaTokenizer = new StringTokenizer - (headerValue, ","); - boolean conditionSatisfied = false; - - while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { - String currentToken = commaTokenizer.nextToken(); - if (currentToken.trim().equals(eTag)) - conditionSatisfied = true; - } - - // If none of the given ETags match, 412 Precodition failed is - // sent back - if (!conditionSatisfied) { - response.sendError - (HttpServletResponse.SC_PRECONDITION_FAILED); - return false; - } - - } - } - return true; - - } /** @@ -1577,7 +1518,7 @@ // The entity has not been modified since the date // specified by the client. This is not an error case. response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); - response.setHeader("ETag", getETag(resourceAttributes)); + // response.setHeader("ETag", getETag(resourceAttributes)); return false; } @@ -1591,66 +1532,6 @@ /** - * Check if the if-none-match condition is satisfied. - * - * @param request The servlet request we are processing - * @param response The servlet response we are creating - * @param resourceInfo File object - * @return boolean true if the resource meets the specified condition, - * and false if the condition is not satisfied, in which case request - * processing is stopped - */ - protected boolean checkIfNoneMatch(HttpServletRequest request, - HttpServletResponse response, - ResourceAttributes resourceAttributes) - throws IOException { - - String eTag = getETag(resourceAttributes); - String headerValue = request.getHeader("If-None-Match"); - if (headerValue != null) { - - boolean conditionSatisfied = false; - - if (!headerValue.equals("*")) { - - StringTokenizer commaTokenizer = - new StringTokenizer(headerValue, ","); - - while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { - String currentToken = commaTokenizer.nextToken(); - if (currentToken.trim().equals(eTag)) - conditionSatisfied = true; - } - - } else { - conditionSatisfied = true; - } - - if (conditionSatisfied) { - - // For GET and HEAD, we should respond with - // 304 Not Modified. - // For every other method, 412 Precondition Failed is sent - // back. - if ( ("GET".equals(request.getMethod())) - || ("HEAD".equals(request.getMethod())) ) { - response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); - response.setHeader("ETag", getETag(resourceAttributes)); - - return false; - } else { - response.sendError - (HttpServletResponse.SC_PRECONDITION_FAILED); - return false; - } - } - } - return true; - - } - - - /** * Check if the if-unmodified-since condition is satisfied. * * @param request The servlet request we are processing