You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2006/08/07 21:12:46 UTC

svn commit: r429437 - /incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/InMemoryCachedResponse.java

Author: jmsnell
Date: Mon Aug  7 12:12:45 2006
New Revision: 429437

URL: http://svn.apache.org/viewvc?rev=429437&view=rev
Log:
Filter out hop-by-hop headers from the cached response

Modified:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/InMemoryCachedResponse.java

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/InMemoryCachedResponse.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/InMemoryCachedResponse.java?rev=429437&r1=429436&r2=429437&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/InMemoryCachedResponse.java (original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/InMemoryCachedResponse.java Mon Aug  7 12:12:45 2006
@@ -49,7 +49,8 @@
     this.uri = response.getUri();
     String[] headers = response.getHeaderNames();
     for (String header : headers) {
-      if (!isNoCacheOrPrivate(header, response)) {
+      if (!isNoCacheOrPrivate(header, response) &&
+          !isHopByHop(header)) {
         String[] values = response.getHeaders(header);
         List<String> list = Arrays.asList(values);
         getHeaders().put(header, list);
@@ -61,6 +62,23 @@
     response.setInputStream(getInputStream());
   }
 
+  /**
+   * We don't cache hop-by-hop headers
+   * TODO: There may actually be other hop-by-hop headers we need to filter 
+   *       out.  They'll be listed in the Connection header. see Section 14.10
+   *       of RFC2616 (last paragraph)
+   */
+  private boolean isHopByHop(String header) {
+    return (header.equalsIgnoreCase("Connection") ||
+            header.equalsIgnoreCase("Keep-Alive") ||
+            header.equalsIgnoreCase("Proxy-Authenticate") ||
+            header.equalsIgnoreCase("Proxy-Authorization") ||
+            header.equalsIgnoreCase("TE") ||
+            header.equalsIgnoreCase("Trailers") ||
+            header.equalsIgnoreCase("Transfer-Encoding") ||
+            header.equalsIgnoreCase("Upgrade"));
+  }
+  
   /**
    * This is terribly inefficient, but it is an in-memory cache
    * that is being used by parsers that incrementally consume