hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [8/8] httpcomponents-client git commit: Use stable (HttpRequest implementation independent) implementation of key generation
Date Mon, 16 Oct 2017 21:03:49 GMT
Use stable (HttpRequest implementation independent) implementation of key generation


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/93557310
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/93557310
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/93557310

Branch: refs/heads/master
Commit: 935573104cb399a680ff66fb803199a5430d27d4
Parents: 0aa4b81
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Mon Oct 16 16:58:07 2017 +0200
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Mon Oct 16 23:01:13 2017 +0200

----------------------------------------------------------------------
 .../http/impl/cache/CacheKeyGenerator.java      | 25 ++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/93557310/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java
b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java
index b6dad23..082322e 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java
@@ -47,6 +47,7 @@ import org.apache.hc.core5.http.HeaderElement;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.message.MessageSupport;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.net.URIBuilder;
 
 /**
@@ -86,14 +87,34 @@ class CacheKeyGenerator {
      * @return String the extracted URI
      */
     public String generateKey(final HttpHost host, final HttpRequest req) {
+        final StringBuilder buf = new StringBuilder();
+        final URIAuthority authority = req.getAuthority();
+        if (authority != null) {
+            final String scheme = req.getScheme();
+            buf.append(scheme != null ? scheme : "http").append("://");
+            buf.append(authority.getHostName());
+            if (authority.getPort() >= 0) {
+                buf.append(":").append(authority.getPort());
+            }
+        }
+        final String path = req.getPath();
+        if (path == null) {
+            buf.append("/");
+        } else {
+            if (buf.length() > 0 && !path.startsWith("/")) {
+                buf.append("/");
+            }
+            buf.append(path);
+        }
+        final String s = buf.toString();
         try {
-            URI uri = req.getUri();
+            URI uri = new URI(s);
             if (!uri.isAbsolute()) {
                 uri = URIUtils.rewriteURI(uri, host);
             }
             return normalize(uri).toASCIIString();
         } catch (final URISyntaxException ex) {
-            return req.getRequestUri();
+            return s;
         }
     }
 


Mime
View raw message