hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1623734 - in /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie: DefaultCookieSpecProvider.java PublicSuffixDomainFilter.java RFC2109SpecProvider.java RFC2965SpecProvider.java
Date Tue, 09 Sep 2014 10:06:29 GMT
Author: olegk
Date: Tue Sep  9 10:06:29 2014
New Revision: 1623734

URL: http://svn.apache.org/r1623734
Log:
Default and standard cookie specs to use public suffix list when available

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/DefaultCookieSpecProvider.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/PublicSuffixDomainFilter.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2109SpecProvider.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965SpecProvider.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/DefaultCookieSpecProvider.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/DefaultCookieSpecProvider.java?rev=1623734&r1=1623733&r2=1623734&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/DefaultCookieSpecProvider.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/DefaultCookieSpecProvider.java
Tue Sep  9 10:06:29 2014
@@ -28,6 +28,7 @@
 package org.apache.http.impl.cookie;
 
 import org.apache.http.annotation.Immutable;
+import org.apache.http.conn.util.PublicSuffixMatcher;
 import org.apache.http.cookie.Cookie;
 import org.apache.http.cookie.CookieOrigin;
 import org.apache.http.cookie.CookieSpec;
@@ -51,6 +52,7 @@ public class DefaultCookieSpecProvider i
     }
 
     private final CompatibilityLevel compatibilityLevel;
+    private final PublicSuffixMatcher publicSuffixMatcher;
     private final String[] datepatterns;
     private final boolean oneHeader;
 
@@ -58,16 +60,24 @@ public class DefaultCookieSpecProvider i
 
     public DefaultCookieSpecProvider(
             final CompatibilityLevel compatibilityLevel,
+            final PublicSuffixMatcher publicSuffixMatcher,
             final String[] datepatterns,
             final boolean oneHeader) {
         super();
         this.compatibilityLevel = compatibilityLevel != null ? compatibilityLevel : CompatibilityLevel.DEFAULT;
+        this.publicSuffixMatcher = publicSuffixMatcher;
         this.datepatterns = datepatterns;
         this.oneHeader = oneHeader;
     }
 
+    public DefaultCookieSpecProvider(
+            final CompatibilityLevel compatibilityLevel,
+            final PublicSuffixMatcher publicSuffixMatcher) {
+        this(compatibilityLevel, publicSuffixMatcher, null, false);
+    }
+
     public DefaultCookieSpecProvider() {
-        this(CompatibilityLevel.DEFAULT, null, false);
+        this(CompatibilityLevel.DEFAULT, null, null, false);
     }
 
     @Override
@@ -78,7 +88,8 @@ public class DefaultCookieSpecProvider i
                     final RFC2965Spec strict = new RFC2965Spec(this.oneHeader,
                             new RFC2965VersionAttributeHandler(),
                             new BasicPathHandler(),
-                            new RFC2965DomainAttributeHandler(),
+                            PublicSuffixDomainFilter.decorate(
+                                    new RFC2965DomainAttributeHandler(), this.publicSuffixMatcher),
                             new RFC2965PortAttributeHandler(),
                             new BasicMaxAgeHandler(),
                             new BasicSecureHandler(),
@@ -88,12 +99,14 @@ public class DefaultCookieSpecProvider i
                     final RFC2109Spec obsoleteStrict = new RFC2109Spec(this.oneHeader,
                             new RFC2109VersionHandler(),
                             new BasicPathHandler(),
-                            new RFC2109DomainHandler(),
+                            PublicSuffixDomainFilter.decorate(
+                                    new RFC2109DomainHandler(), this.publicSuffixMatcher),
                             new BasicMaxAgeHandler(),
                             new BasicSecureHandler(),
                             new BasicCommentHandler());
                     final NetscapeDraftSpec netscapeDraft = new NetscapeDraftSpec(
-                            new BasicDomainHandler(),
+                            PublicSuffixDomainFilter.decorate(
+                                    new BasicDomainHandler(), this.publicSuffixMatcher),
                             this.compatibilityLevel == CompatibilityLevel.IE_MEDIUM_SECURITY
?
                                     new BasicPathHandler() {
                                         @Override

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/PublicSuffixDomainFilter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/PublicSuffixDomainFilter.java?rev=1623734&r1=1623733&r2=1623734&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/PublicSuffixDomainFilter.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/PublicSuffixDomainFilter.java
Tue Sep  9 10:06:29 2014
@@ -51,18 +51,20 @@ import org.apache.http.util.Args;
 public class PublicSuffixDomainFilter implements CommonCookieAttributeHandler {
 
     private final CommonCookieAttributeHandler handler;
-    private final PublicSuffixMatcher matcher;
+    private final PublicSuffixMatcher publicSuffixMatcher;
 
-    public PublicSuffixDomainFilter(final CommonCookieAttributeHandler handler, final PublicSuffixMatcher
matcher) {
+    public PublicSuffixDomainFilter(
+            final CommonCookieAttributeHandler handler, final PublicSuffixMatcher publicSuffixMatcher)
{
         this.handler = Args.notNull(handler, "Cookie handler");
-        this.matcher = Args.notNull(matcher, "Public suffix matcher");
+        this.publicSuffixMatcher = Args.notNull(publicSuffixMatcher, "Public suffix matcher");
     }
 
-    public PublicSuffixDomainFilter(final CommonCookieAttributeHandler handler, final PublicSuffixList
suffixList) {
+    public PublicSuffixDomainFilter(
+            final CommonCookieAttributeHandler handler, final PublicSuffixList suffixList)
{
         Args.notNull(handler, "Cookie handler");
         Args.notNull(suffixList, "Public suffix list");
         this.handler = handler;
-        this.matcher = new PublicSuffixMatcher(suffixList.getRules(), suffixList.getExceptions());
+        this.publicSuffixMatcher = new PublicSuffixMatcher(suffixList.getRules(), suffixList.getExceptions());
     }
 
     /**
@@ -71,7 +73,7 @@ public class PublicSuffixDomainFilter im
     @Override
     public boolean match(final Cookie cookie, final CookieOrigin origin) {
         final String domain = cookie.getDomain();
-        if (!domain.equalsIgnoreCase("localhost") && matcher.matches(domain)) {
+        if (!domain.equalsIgnoreCase("localhost") && publicSuffixMatcher.matches(domain))
{
             return false;
         } else {
             return handler.match(cookie, origin);
@@ -93,4 +95,10 @@ public class PublicSuffixDomainFilter im
         return handler.getAttributeName();
     }
 
+    public static CommonCookieAttributeHandler decorate(
+            final CommonCookieAttributeHandler handler, final PublicSuffixMatcher publicSuffixMatcher)
{
+        Args.notNull(handler, "Cookie attribute handler");
+        return publicSuffixMatcher != null ? new PublicSuffixDomainFilter(handler, publicSuffixMatcher)
: handler;
+    }
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2109SpecProvider.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2109SpecProvider.java?rev=1623734&r1=1623733&r2=1623734&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2109SpecProvider.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2109SpecProvider.java
Tue Sep  9 10:06:29 2014
@@ -28,6 +28,7 @@
 package org.apache.http.impl.cookie;
 
 import org.apache.http.annotation.Immutable;
+import org.apache.http.conn.util.PublicSuffixMatcher;
 import org.apache.http.cookie.CookieSpec;
 import org.apache.http.cookie.CookieSpecProvider;
 import org.apache.http.protocol.HttpContext;
@@ -42,17 +43,23 @@ import org.apache.http.protocol.HttpCont
 @Immutable
 public class RFC2109SpecProvider implements CookieSpecProvider {
 
+    private final PublicSuffixMatcher publicSuffixMatcher;
     private final boolean oneHeader;
 
     private volatile CookieSpec cookieSpec;
 
-    public RFC2109SpecProvider(final boolean oneHeader) {
+    public RFC2109SpecProvider(final PublicSuffixMatcher publicSuffixMatcher, final boolean
oneHeader) {
         super();
         this.oneHeader = oneHeader;
+        this.publicSuffixMatcher = publicSuffixMatcher;
+    }
+
+    public RFC2109SpecProvider(final PublicSuffixMatcher publicSuffixMatcher) {
+        this(publicSuffixMatcher, false);
     }
 
     public RFC2109SpecProvider() {
-        this(false);
+        this(null, false);
     }
 
     @Override
@@ -60,7 +67,14 @@ public class RFC2109SpecProvider impleme
         if (cookieSpec == null) {
             synchronized (this) {
                 if (cookieSpec == null) {
-                    this.cookieSpec = new RFC2109Spec(null, this.oneHeader);
+                    this.cookieSpec = new RFC2109Spec(this.oneHeader,
+                            new RFC2109VersionHandler(),
+                            new BasicPathHandler(),
+                            PublicSuffixDomainFilter.decorate(
+                                    new RFC2109DomainHandler(), this.publicSuffixMatcher),
+                            new BasicMaxAgeHandler(),
+                            new BasicSecureHandler(),
+                            new BasicCommentHandler());
                 }
             }
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965SpecProvider.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965SpecProvider.java?rev=1623734&r1=1623733&r2=1623734&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965SpecProvider.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965SpecProvider.java
Tue Sep  9 10:06:29 2014
@@ -28,6 +28,7 @@
 package org.apache.http.impl.cookie;
 
 import org.apache.http.annotation.Immutable;
+import org.apache.http.conn.util.PublicSuffixMatcher;
 import org.apache.http.cookie.CookieSpec;
 import org.apache.http.cookie.CookieSpecProvider;
 import org.apache.http.protocol.HttpContext;
@@ -42,17 +43,23 @@ import org.apache.http.protocol.HttpCont
 @Immutable
 public class RFC2965SpecProvider implements CookieSpecProvider {
 
+    private final PublicSuffixMatcher publicSuffixMatcher;
     private final boolean oneHeader;
 
     private volatile CookieSpec cookieSpec;
 
-    public RFC2965SpecProvider(final boolean oneHeader) {
+    public RFC2965SpecProvider(final PublicSuffixMatcher publicSuffixMatcher, final boolean
oneHeader) {
         super();
         this.oneHeader = oneHeader;
+        this.publicSuffixMatcher = publicSuffixMatcher;
+    }
+
+    public RFC2965SpecProvider(final PublicSuffixMatcher publicSuffixMatcher) {
+        this(publicSuffixMatcher, false);
     }
 
     public RFC2965SpecProvider() {
-        this(false);
+        this(null, false);
     }
 
     @Override
@@ -60,7 +67,17 @@ public class RFC2965SpecProvider impleme
         if (cookieSpec == null) {
             synchronized (this) {
                 if (cookieSpec == null) {
-                    this.cookieSpec = new RFC2965Spec(null, this.oneHeader);
+                    this.cookieSpec = new RFC2965Spec(this.oneHeader,
+                            new RFC2965VersionAttributeHandler(),
+                            new BasicPathHandler(),
+                            PublicSuffixDomainFilter.decorate(
+                                    new RFC2965DomainAttributeHandler(), this.publicSuffixMatcher),
+                            new RFC2965PortAttributeHandler(),
+                            new BasicMaxAgeHandler(),
+                            new BasicSecureHandler(),
+                            new BasicCommentHandler(),
+                            new RFC2965CommentUrlAttributeHandler(),
+                            new RFC2965DiscardAttributeHandler());
                 }
             }
         }



Mime
View raw message