You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2023/05/21 14:29:52 UTC
[httpcomponents-client] branch 5.3.x updated: Removed HttpCacheSupport from public API
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch 5.3.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
The following commit(s) were added to refs/heads/5.3.x by this push:
new 3ce24beff Removed HttpCacheSupport from public API
3ce24beff is described below
commit 3ce24beff9a7e119aefd3c1111e887a25ffc8194
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sun May 21 16:27:11 2023 +0200
Removed HttpCacheSupport from public API
---
.../http/impl/cache/CacheInvalidatorBase.java | 2 +-
.../client5/http/impl/cache/CacheKeyGenerator.java | 4 +-
.../{HttpCacheSupport.java => CacheSupport.java} | 29 ++-----
.../impl/cache/DefaultAsyncCacheInvalidator.java | 12 +--
.../http/impl/cache/DefaultCacheInvalidator.java | 12 +--
.../client5/http/impl/cache/HttpCacheSupport.java | 88 ++--------------------
.../cache/TestDefaultAsyncCacheInvalidator.java | 2 +-
.../impl/cache/TestDefaultCacheInvalidator.java | 2 +-
8 files changed, 28 insertions(+), 123 deletions(-)
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheInvalidatorBase.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheInvalidatorBase.java
index 2323d3230..860c8434b 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheInvalidatorBase.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheInvalidatorBase.java
@@ -68,7 +68,7 @@ class CacheInvalidatorBase {
if (h == null) {
return null;
}
- final URI locationUri = HttpCacheSupport.normalizeQuietly(h.getValue());
+ final URI locationUri = CacheSupport.normalize(h.getValue());
if (locationUri == null) {
return requestUri;
}
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 76b25309a..b019fd72c 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
@@ -70,7 +70,7 @@ public class CacheKeyGenerator implements Resolver<URI, String> {
*/
public String generateKey(final URI requestUri) {
try {
- final URI normalizeRequestUri = HttpCacheSupport.normalize(requestUri);
+ final URI normalizeRequestUri = CacheSupport.normalize(requestUri);
return normalizeRequestUri.toASCIIString();
} catch (final URISyntaxException ex) {
return requestUri.toASCIIString();
@@ -86,7 +86,7 @@ public class CacheKeyGenerator implements Resolver<URI, String> {
* @return cache key
*/
public String generateKey(final HttpHost host, final HttpRequest request) {
- final String s = HttpCacheSupport.getRequestUri(request, host);
+ final String s = CacheSupport.getRequestUri(request, host);
try {
return generateKey(new URI(s));
} catch (final URISyntaxException ex) {
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheSupport.java
similarity index 87%
copy from httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
copy to httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheSupport.java
index 67e03f119..78626e73e 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheSupport.java
@@ -30,6 +30,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hc.client5.http.utils.URIUtils;
+import org.apache.hc.core5.annotation.Internal;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.URIScheme;
@@ -40,9 +41,10 @@ import org.apache.hc.core5.util.Args;
/**
* HTTP cache support utilities.
*
- * @since 5.0
+ * @since 5.3
*/
-public final class HttpCacheSupport {
+@Internal
+public final class CacheSupport {
private static final URI BASE_URI = URI.create("http://example.com/");
@@ -94,10 +96,6 @@ public final class HttpCacheSupport {
* Returns normalized representation of the request URI optimized for use as a cache key.
* This method ensures the resultant URI has an explicit port in the authority component,
* and explicit path component and no fragment.
- *
- * @param requestUri original request URI
- * @return normalized URI.
- * @throws URISyntaxException
*/
public static URI normalize(final URI requestUri) throws URISyntaxException {
Args.notNull(requestUri, "URI");
@@ -123,25 +121,8 @@ public final class HttpCacheSupport {
/**
* Lenient URI parser that normalizes valid {@link URI}s and returns {@code null} for malformed URIs.
- * @deprecated Use {@link #normalizeQuietly(String)}
- */
- @Deprecated
- public static URI normalizeQuetly(final String requestUri) {
- if (requestUri == null) {
- return null;
- }
- try {
- return normalize(new URI(requestUri));
- } catch (final URISyntaxException ex) {
- return null;
- }
- }
-
- /**
- * Lenient URI parser that normalizes valid {@link URI}s and returns {@code null} for malformed URIs.
- * @since 5.2
*/
- public static URI normalizeQuietly(final String requestUri) {
+ public static URI normalize(final String requestUri) {
if (requestUri == null) {
return null;
}
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java
index 952659516..91d301ba4 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheInvalidator.java
@@ -100,8 +100,8 @@ public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implement
final Resolver<URI, String> cacheKeyResolver,
final HttpAsyncCacheStorage storage,
final FutureCallback<Boolean> callback) {
- final String s = HttpCacheSupport.getRequestUri(request, host);
- final URI uri = HttpCacheSupport.normalizeQuietly(s);
+ final String s = CacheSupport.getRequestUri(request, host);
+ final URI uri = CacheSupport.normalize(s);
final String cacheKey = uri != null ? cacheKeyResolver.resolve(uri) : s;
return storage.getEntry(cacheKey, new FutureCallback<HttpCacheEntry>() {
@@ -123,7 +123,7 @@ public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implement
}
final Header clHdr = request.getFirstHeader(HttpHeaders.CONTENT_LOCATION);
if (clHdr != null) {
- final URI contentLocation = HttpCacheSupport.normalizeQuietly(clHdr.getValue());
+ final URI contentLocation = CacheSupport.normalize(clHdr.getValue());
if (contentLocation != null) {
if (!flushAbsoluteUriFromSameHost(uri, contentLocation, cacheKeyResolver, storage)) {
flushRelativeUriFromSameHost(uri, contentLocation, cacheKeyResolver, storage);
@@ -132,7 +132,7 @@ public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implement
}
final Header lHdr = request.getFirstHeader(HttpHeaders.LOCATION);
if (lHdr != null) {
- final URI location = HttpCacheSupport.normalizeQuietly(lHdr.getValue());
+ final URI location = CacheSupport.normalize(lHdr.getValue());
if (location != null) {
flushAbsoluteUriFromSameHost(uri, location, cacheKeyResolver, storage);
}
@@ -189,8 +189,8 @@ public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implement
final FutureCallback<Boolean> callback) {
final int status = response.getCode();
if (status >= HttpStatus.SC_SUCCESS && status < HttpStatus.SC_REDIRECTION) {
- final String s = HttpCacheSupport.getRequestUri(request, host);
- final URI requestUri = HttpCacheSupport.normalizeQuietly(s);
+ final String s = CacheSupport.getRequestUri(request, host);
+ final URI requestUri = CacheSupport.normalize(s);
if (requestUri != null) {
final List<String> cacheKeys = new ArrayList<>(2);
final URI contentLocation = getContentLocationURI(requestUri, response);
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheInvalidator.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheInvalidator.java
index 0ac340d91..d629857a0 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheInvalidator.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultCacheInvalidator.java
@@ -86,8 +86,8 @@ public class DefaultCacheInvalidator extends CacheInvalidatorBase implements Htt
final HttpRequest request,
final Resolver<URI, String> cacheKeyResolver,
final HttpCacheStorage storage) {
- final String s = HttpCacheSupport.getRequestUri(request, host);
- final URI uri = HttpCacheSupport.normalizeQuietly(s);
+ final String s = CacheSupport.getRequestUri(request, host);
+ final URI uri = CacheSupport.normalize(s);
final String cacheKey = uri != null ? cacheKeyResolver.resolve(uri) : s;
final HttpCacheEntry parent = getEntry(storage, cacheKey);
@@ -107,7 +107,7 @@ public class DefaultCacheInvalidator extends CacheInvalidatorBase implements Htt
}
final Header clHdr = request.getFirstHeader(HttpHeaders.CONTENT_LOCATION);
if (clHdr != null) {
- final URI contentLocation = HttpCacheSupport.normalizeQuietly(clHdr.getValue());
+ final URI contentLocation = CacheSupport.normalize(clHdr.getValue());
if (contentLocation != null) {
if (!flushAbsoluteUriFromSameHost(uri, contentLocation, cacheKeyResolver, storage)) {
flushRelativeUriFromSameHost(uri, contentLocation, cacheKeyResolver, storage);
@@ -116,7 +116,7 @@ public class DefaultCacheInvalidator extends CacheInvalidatorBase implements Htt
}
final Header lHdr = request.getFirstHeader(HttpHeaders.LOCATION);
if (lHdr != null) {
- final URI location = HttpCacheSupport.normalizeQuietly(lHdr.getValue());
+ final URI location = CacheSupport.normalize(lHdr.getValue());
if (location != null) {
flushAbsoluteUriFromSameHost(uri, location, cacheKeyResolver, storage);
}
@@ -159,8 +159,8 @@ public class DefaultCacheInvalidator extends CacheInvalidatorBase implements Htt
if (status < 200 || status > 299) {
return;
}
- final String s = HttpCacheSupport.getRequestUri(request, host);
- final URI uri = HttpCacheSupport.normalizeQuietly(s);
+ final String s = CacheSupport.getRequestUri(request, host);
+ final URI uri = CacheSupport.normalize(s);
if (uri == null) {
return;
}
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
index 67e03f119..69285cb1b 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCacheSupport.java
@@ -29,96 +29,27 @@ package org.apache.hc.client5.http.impl.cache;
import java.net.URI;
import java.net.URISyntaxException;
-import org.apache.hc.client5.http.utils.URIUtils;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.URIScheme;
-import org.apache.hc.core5.net.URIAuthority;
-import org.apache.hc.core5.net.URIBuilder;
-import org.apache.hc.core5.util.Args;
/**
* HTTP cache support utilities.
*
* @since 5.0
+ *
+ * @deprecated Do not use. This functionality is internal.
*/
+@Deprecated
public final class HttpCacheSupport {
private static final URI BASE_URI = URI.create("http://example.com/");
- /**
- * Returns text representation of the request URI of the given {@link HttpRequest}.
- * This method will use {@link HttpRequest#getPath()}, {@link HttpRequest#getScheme()} and
- * {@link HttpRequest#getAuthority()} values when available or attributes of target
- * {@link HttpHost } in order to construct an absolute URI.
- * <p>
- * This method will not attempt to ensure validity of the resultant text representation.
- *
- * @param request the {@link HttpRequest}
- * @param target target host
- *
- * @return String the request URI
- */
public static String getRequestUri(final HttpRequest request, final HttpHost target) {
- Args.notNull(request, "HTTP request");
- Args.notNull(target, "Target");
- final StringBuilder buf = new StringBuilder();
- final URIAuthority authority = request.getAuthority();
- if (authority != null) {
- final String scheme = request.getScheme();
- buf.append(scheme != null ? scheme : URIScheme.HTTP.id).append("://");
- buf.append(authority.getHostName());
- if (authority.getPort() >= 0) {
- buf.append(":").append(authority.getPort());
- }
- } else {
- buf.append(target.getSchemeName()).append("://");
- buf.append(target.getHostName());
- if (target.getPort() >= 0) {
- buf.append(":").append(target.getPort());
- }
- }
- final String path = request.getPath();
- if (path == null) {
- buf.append("/");
- } else {
- if (buf.length() > 0 && !path.startsWith("/")) {
- buf.append("/");
- }
- buf.append(path);
- }
- return buf.toString();
+ return CacheSupport.getRequestUri(request, target);
}
- /**
- * Returns normalized representation of the request URI optimized for use as a cache key.
- * This method ensures the resultant URI has an explicit port in the authority component,
- * and explicit path component and no fragment.
- *
- * @param requestUri original request URI
- * @return normalized URI.
- * @throws URISyntaxException
- */
public static URI normalize(final URI requestUri) throws URISyntaxException {
- Args.notNull(requestUri, "URI");
- final URIBuilder builder = new URIBuilder(requestUri.isAbsolute() ? URIUtils.resolve(BASE_URI, requestUri) : requestUri) ;
- if (builder.getHost() != null) {
- if (builder.getScheme() == null) {
- builder.setScheme(URIScheme.HTTP.id);
- }
- if (builder.getPort() <= -1) {
- if (URIScheme.HTTP.same(builder.getScheme())) {
- builder.setPort(80);
- } else if (URIScheme.HTTPS.same(builder.getScheme())) {
- builder.setPort(443);
- }
- }
- }
- builder.setFragment(null);
- if (builder.isPathEmpty()) {
- builder.setPathSegments("");
- }
- return builder.build();
+ return CacheSupport.normalize(requestUri);
}
/**
@@ -142,14 +73,7 @@ public final class HttpCacheSupport {
* @since 5.2
*/
public static URI normalizeQuietly(final String requestUri) {
- if (requestUri == null) {
- return null;
- }
- try {
- return normalize(new URI(requestUri));
- } catch (final URISyntaxException ex) {
- return null;
- }
+ return CacheSupport.normalize(requestUri);
}
}
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultAsyncCacheInvalidator.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultAsyncCacheInvalidator.java
index cf4d3c4c4..08ab5d0b6 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultAsyncCacheInvalidator.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultAsyncCacheInvalidator.java
@@ -83,7 +83,7 @@ public class TestDefaultAsyncCacheInvalidator {
when(cacheKeyResolver.resolve(ArgumentMatchers.any())).thenAnswer((Answer<String>) invocation -> {
final URI uri = invocation.getArgument(0);
- return HttpCacheSupport.normalize(uri).toASCIIString();
+ return CacheSupport.normalize(uri).toASCIIString();
});
host = new HttpHost("foo.example.com");
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultCacheInvalidator.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultCacheInvalidator.java
index d2797fbd5..2a98d2f24 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultCacheInvalidator.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestDefaultCacheInvalidator.java
@@ -77,7 +77,7 @@ public class TestDefaultCacheInvalidator {
when(cacheKeyResolver.resolve(ArgumentMatchers.any())).thenAnswer((Answer<String>) invocation -> {
final URI uri = invocation.getArgument(0);
- return HttpCacheSupport.normalize(uri).toASCIIString();
+ return CacheSupport.normalize(uri).toASCIIString();
});
host = new HttpHost("foo.example.com");