hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1623735 - in /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http: conn/util/PublicSuffixMatcherLoader.java impl/client/HttpClientBuilder.java impl/cookie/DefaultCookieSpecProvider.java
Date Tue, 09 Sep 2014 10:06:43 GMT
Author: olegk
Date: Tue Sep  9 10:06:43 2014
New Revision: 1623735

URL: http://svn.apache.org/r1623735
Log:
HttpClientBuilder to initialize public suffix matcher for cookie specs and the default hostname
verifier

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/util/PublicSuffixMatcherLoader.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/DefaultCookieSpecProvider.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/util/PublicSuffixMatcherLoader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/util/PublicSuffixMatcherLoader.java?rev=1623735&r1=1623734&r2=1623735&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/util/PublicSuffixMatcherLoader.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/util/PublicSuffixMatcherLoader.java
Tue Sep  9 10:06:43 2014
@@ -26,6 +26,8 @@
  */
 package org.apache.http.conn.util;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -39,18 +41,34 @@ import org.apache.http.annotation.Thread
 import org.apache.http.util.Args;
 
 /**
+ * {@link org.apache.http.conn.util.PublicSuffixMatcher} loader.
+ *
  * @since 4.4
  */
 @ThreadSafe
 public final class PublicSuffixMatcherLoader {
 
+    private static PublicSuffixMatcher load(final InputStream in) throws IOException {
+        final PublicSuffixList list = new PublicSuffixListParser().parse(
+                new InputStreamReader(in, Consts.UTF_8));
+        return new PublicSuffixMatcher(list.getRules(), list.getExceptions());
+    }
+
     public static PublicSuffixMatcher load(final URL url) throws IOException {
         Args.notNull(url, "URL");
         final InputStream in = url.openStream();
         try {
-            final PublicSuffixList list = new PublicSuffixListParser().parse(
-                    new InputStreamReader(in, Consts.UTF_8));
-            return new PublicSuffixMatcher(list.getRules(), list.getExceptions());
+            return load(in);
+        } finally {
+            in.close();
+        }
+    }
+
+    public static PublicSuffixMatcher load(final File file) throws IOException {
+        Args.notNull(file, "File");
+        final InputStream in = new FileInputStream(file);
+        try {
+            return load(in);
         } finally {
             in.close();
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java?rev=1623735&r1=1623734&r2=1623735&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
Tue Sep  9 10:06:43 2014
@@ -81,9 +81,12 @@ import org.apache.http.conn.routing.Http
 import org.apache.http.conn.socket.ConnectionSocketFactory;
 import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
 import org.apache.http.conn.socket.PlainConnectionSocketFactory;
+import org.apache.http.conn.ssl.DefaultHostnameVerifier;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
 import org.apache.http.conn.ssl.SSLContexts;
 import org.apache.http.conn.ssl.X509HostnameVerifier;
+import org.apache.http.conn.util.PublicSuffixMatcher;
+import org.apache.http.conn.util.PublicSuffixMatcherLoader;
 import org.apache.http.cookie.CookieSpecProvider;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.NoConnectionReuseStrategy;
@@ -211,6 +214,8 @@ public class HttpClientBuilder {
 
     private List<Closeable> closeables;
 
+    private PublicSuffixMatcher publicSuffixMatcher;
+
     public static HttpClientBuilder create() {
         return new HttpClientBuilder();
     }
@@ -259,6 +264,20 @@ public class HttpClientBuilder {
     }
 
     /**
+     * Assigns file containing public suffix matcher. Instances of this class can be created
+     * with {@link org.apache.http.conn.util.PublicSuffixMatcherLoader}.
+     *
+     * @see org.apache.http.conn.util.PublicSuffixMatcher
+     * @see org.apache.http.conn.util.PublicSuffixMatcherLoader
+     *
+     *   @since 4.4
+     */
+    public final HttpClientBuilder setPublicSuffixMatcher(final PublicSuffixMatcher publicSuffixMatcher)
{
+        this.publicSuffixMatcher = publicSuffixMatcher;
+        return this;
+    }
+
+    /**
      * Assigns {@link SSLContext} instance.
      * <p>
      * Please note this value can be overridden by the {@link #setConnectionManager(
@@ -803,6 +822,11 @@ public class HttpClientBuilder {
     public CloseableHttpClient build() {
         // Create main request executor
         // We copy the instance fields to avoid changing them, and rename to avoid accidental
use of the wrong version
+        PublicSuffixMatcher publicSuffixMatcherCopy = this.publicSuffixMatcher;
+        if (publicSuffixMatcherCopy == null) {
+            publicSuffixMatcherCopy = PublicSuffixMatcherLoader.getDefault();
+        }
+
         HttpRequestExecutor requestExecCopy = this.requestExec;
         if (requestExecCopy == null) {
             requestExecCopy = new HttpRequestExecutor();
@@ -817,7 +841,7 @@ public class HttpClientBuilder {
                         System.getProperty("https.cipherSuites")) : null;
                 HostnameVerifier hostnameVerifierCopy = this.hostnameVerifier;
                 if (hostnameVerifierCopy == null) {
-                    hostnameVerifierCopy = SSLConnectionSocketFactory.getDefaultHostnameVerifier();
+                    hostnameVerifierCopy = new DefaultHostnameVerifier(publicSuffixMatcherCopy);
                 }
                 if (sslcontext != null) {
                     sslSocketFactoryCopy = new SSLConnectionSocketFactory(
@@ -1047,8 +1071,8 @@ public class HttpClientBuilder {
         Lookup<CookieSpecProvider> cookieSpecRegistryCopy = this.cookieSpecRegistry;
         if (cookieSpecRegistryCopy == null) {
             cookieSpecRegistryCopy = RegistryBuilder.<CookieSpecProvider>create()
-                .register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
-                .register(CookieSpecs.STANDARD, new RFC2965SpecProvider())
+                .register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider(publicSuffixMatcherCopy))
+                .register(CookieSpecs.STANDARD, new RFC2965SpecProvider(publicSuffixMatcherCopy))
                 .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
                 .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider())
                 .build();

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=1623735&r1=1623734&r2=1623735&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:43 2014
@@ -76,6 +76,10 @@ public class DefaultCookieSpecProvider i
         this(compatibilityLevel, publicSuffixMatcher, null, false);
     }
 
+    public DefaultCookieSpecProvider(final PublicSuffixMatcher publicSuffixMatcher) {
+        this(CompatibilityLevel.DEFAULT, publicSuffixMatcher, null, false);
+    }
+
     public DefaultCookieSpecProvider() {
         this(CompatibilityLevel.DEFAULT, null, null, false);
     }



Mime
View raw message