Promote RequestCacheControl and ResponseCacheControl to public API
This commit is contained in:
parent
ef77109f35
commit
364fa60cd3
|
@ -25,10 +25,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.hc.client5.http.impl.cache;
|
package org.apache.hc.client5.http.cache;
|
||||||
|
|
||||||
import org.apache.hc.core5.annotation.Contract;
|
import org.apache.hc.core5.annotation.Contract;
|
||||||
import org.apache.hc.core5.annotation.Internal;
|
|
||||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,9 +36,8 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||||
*
|
*
|
||||||
* @since 5.4
|
* @since 5.4
|
||||||
*/
|
*/
|
||||||
@Internal
|
|
||||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||||
interface CacheControl {
|
public interface CacheControl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the max-age value from the Cache-Control header.
|
* Returns the max-age value from the Cache-Control header.
|
|
@ -25,21 +25,19 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.hc.client5.http.impl.cache;
|
package org.apache.hc.client5.http.cache;
|
||||||
|
|
||||||
import org.apache.hc.core5.annotation.Contract;
|
import org.apache.hc.core5.annotation.Contract;
|
||||||
import org.apache.hc.core5.annotation.Internal;
|
|
||||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the values of the Cache-Control header in an HTTP request, which indicate whether and for how long
|
* Represents the value of the Cache-Control header in an HTTP request containing cache
|
||||||
* the client is willing to cache the response.
|
* control directives.
|
||||||
*
|
*
|
||||||
* @since 5.4
|
* @since 5.4
|
||||||
*/
|
*/
|
||||||
@Internal
|
|
||||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||||
final class RequestCacheControl implements CacheControl {
|
public final class RequestCacheControl implements CacheControl {
|
||||||
|
|
||||||
private final long maxAge;
|
private final long maxAge;
|
||||||
private final long maxStale;
|
private final long maxStale;
|
||||||
|
@ -170,11 +168,11 @@ final class RequestCacheControl implements CacheControl {
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private long maxAge = -1;
|
private long maxAge = -1;
|
||||||
private long maxStale = -1;
|
private long maxStale = -1;
|
|
@ -25,7 +25,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.hc.client5.http.impl.cache;
|
package org.apache.hc.client5.http.cache;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -33,11 +33,10 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.hc.core5.annotation.Contract;
|
import org.apache.hc.core5.annotation.Contract;
|
||||||
import org.apache.hc.core5.annotation.Internal;
|
|
||||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the values of the Cache-Control header in an HTTP response, which indicate whether and for how long
|
* Represents the value of the Cache-Control header in an HTTP response, which indicate whether and for how long
|
||||||
* the response can be cached by the client and intermediary proxies.
|
* the response can be cached by the client and intermediary proxies.
|
||||||
* <p>
|
* <p>
|
||||||
* The class provides methods to retrieve the maximum age of the response and the maximum age that applies to shared
|
* The class provides methods to retrieve the maximum age of the response and the maximum age that applies to shared
|
||||||
|
@ -50,9 +49,8 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||||
*
|
*
|
||||||
* @since 5.4
|
* @since 5.4
|
||||||
*/
|
*/
|
||||||
@Internal
|
|
||||||
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
@Contract(threading = ThreadingBehavior.IMMUTABLE)
|
||||||
final class ResponseCacheControl implements CacheControl {
|
public final class ResponseCacheControl implements CacheControl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The max-age directive value.
|
* The max-age directive value.
|
||||||
|
@ -339,11 +337,11 @@ final class ResponseCacheControl implements CacheControl {
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private long maxAge = -1;
|
private long maxAge = -1;
|
||||||
private long sharedMaxAge = -1;
|
private long sharedMaxAge = -1;
|
||||||
|
@ -477,15 +475,6 @@ final class ResponseCacheControl implements CacheControl {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNoTransform() {
|
|
||||||
return noStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setNoTransform(final boolean noTransform) {
|
|
||||||
this.noTransform = noTransform;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isImmutable() {
|
public boolean isImmutable() {
|
||||||
return immutable;
|
return immutable;
|
||||||
}
|
}
|
|
@ -49,7 +49,9 @@ import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||||
import org.apache.hc.client5.http.cache.CacheResponseStatus;
|
import org.apache.hc.client5.http.cache.CacheResponseStatus;
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheContext;
|
import org.apache.hc.client5.http.cache.HttpCacheContext;
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||||
|
import org.apache.hc.client5.http.cache.RequestCacheControl;
|
||||||
import org.apache.hc.client5.http.cache.ResourceIOException;
|
import org.apache.hc.client5.http.cache.ResourceIOException;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.client5.http.impl.ExecSupport;
|
import org.apache.hc.client5.http.impl.ExecSupport;
|
||||||
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
||||||
import org.apache.hc.client5.http.schedule.SchedulingStrategy;
|
import org.apache.hc.client5.http.schedule.SchedulingStrategy;
|
||||||
|
|
|
@ -34,6 +34,8 @@ import java.util.function.BiConsumer;
|
||||||
|
|
||||||
import org.apache.hc.client5.http.cache.HeaderConstants;
|
import org.apache.hc.client5.http.cache.HeaderConstants;
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||||
|
import org.apache.hc.client5.http.cache.RequestCacheControl;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.core5.annotation.Contract;
|
import org.apache.hc.core5.annotation.Contract;
|
||||||
import org.apache.hc.core5.annotation.Internal;
|
import org.apache.hc.core5.annotation.Internal;
|
||||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||||
|
@ -160,7 +162,7 @@ class CacheControlHeaderParser {
|
||||||
*/
|
*/
|
||||||
public final ResponseCacheControl parseResponse(final Iterator<Header> headerIterator) {
|
public final ResponseCacheControl parseResponse(final Iterator<Header> headerIterator) {
|
||||||
Args.notNull(headerIterator, "headerIterator");
|
Args.notNull(headerIterator, "headerIterator");
|
||||||
final ResponseCacheControl.Builder builder = new ResponseCacheControl.Builder();
|
final ResponseCacheControl.Builder builder = ResponseCacheControl.builder();
|
||||||
parse(headerIterator, (name, value) -> {
|
parse(headerIterator, (name, value) -> {
|
||||||
if (name.equalsIgnoreCase(HeaderConstants.CACHE_CONTROL_S_MAX_AGE)) {
|
if (name.equalsIgnoreCase(HeaderConstants.CACHE_CONTROL_S_MAX_AGE)) {
|
||||||
builder.setSharedMaxAge(parseSeconds(name, value));
|
builder.setSharedMaxAge(parseSeconds(name, value));
|
||||||
|
@ -224,7 +226,7 @@ class CacheControlHeaderParser {
|
||||||
*/
|
*/
|
||||||
public final RequestCacheControl parseRequest(final Iterator<Header> headerIterator) {
|
public final RequestCacheControl parseRequest(final Iterator<Header> headerIterator) {
|
||||||
Args.notNull(headerIterator, "headerIterator");
|
Args.notNull(headerIterator, "headerIterator");
|
||||||
final RequestCacheControl.Builder builder = new RequestCacheControl.Builder();
|
final RequestCacheControl.Builder builder = RequestCacheControl.builder();
|
||||||
parse(headerIterator, (name, value) -> {
|
parse(headerIterator, (name, value) -> {
|
||||||
if (name.equalsIgnoreCase(HeaderConstants.CACHE_CONTROL_MAX_AGE)) {
|
if (name.equalsIgnoreCase(HeaderConstants.CACHE_CONTROL_MAX_AGE)) {
|
||||||
builder.setMaxAge(parseSeconds(name, value));
|
builder.setMaxAge(parseSeconds(name, value));
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.time.Instant;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.core5.http.Header;
|
import org.apache.hc.core5.http.Header;
|
||||||
import org.apache.hc.core5.http.HttpHeaders;
|
import org.apache.hc.core5.http.HttpHeaders;
|
||||||
import org.apache.hc.core5.http.message.MessageSupport;
|
import org.apache.hc.core5.http.message.MessageSupport;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hc.client5.http.impl.cache;
|
package org.apache.hc.client5.http.impl.cache;
|
||||||
|
|
||||||
|
import org.apache.hc.client5.http.cache.RequestCacheControl;
|
||||||
import org.apache.hc.core5.http.HttpRequest;
|
import org.apache.hc.core5.http.HttpRequest;
|
||||||
import org.apache.hc.core5.http.HttpVersion;
|
import org.apache.hc.core5.http.HttpVersion;
|
||||||
import org.apache.hc.core5.http.Method;
|
import org.apache.hc.core5.http.Method;
|
||||||
|
|
|
@ -38,6 +38,8 @@ import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||||
|
import org.apache.hc.client5.http.cache.RequestCacheControl;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.client5.http.utils.DateUtils;
|
import org.apache.hc.client5.http.utils.DateUtils;
|
||||||
import org.apache.hc.core5.http.Header;
|
import org.apache.hc.core5.http.Header;
|
||||||
import org.apache.hc.core5.http.HeaderElement;
|
import org.apache.hc.core5.http.HeaderElement;
|
||||||
|
|
|
@ -42,7 +42,9 @@ import org.apache.hc.client5.http.cache.CacheResponseStatus;
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheContext;
|
import org.apache.hc.client5.http.cache.HttpCacheContext;
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheStorage;
|
import org.apache.hc.client5.http.cache.HttpCacheStorage;
|
||||||
|
import org.apache.hc.client5.http.cache.RequestCacheControl;
|
||||||
import org.apache.hc.client5.http.cache.ResourceIOException;
|
import org.apache.hc.client5.http.cache.ResourceIOException;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.client5.http.classic.ExecChain;
|
import org.apache.hc.client5.http.classic.ExecChain;
|
||||||
import org.apache.hc.client5.http.classic.ExecChainHandler;
|
import org.apache.hc.client5.http.classic.ExecChainHandler;
|
||||||
import org.apache.hc.client5.http.impl.ExecSupport;
|
import org.apache.hc.client5.http.impl.ExecSupport;
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.hc.client5.http.cache.HeaderConstants;
|
import org.apache.hc.client5.http.cache.HeaderConstants;
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.core5.function.Factory;
|
import org.apache.hc.core5.function.Factory;
|
||||||
import org.apache.hc.core5.http.Header;
|
import org.apache.hc.core5.http.Header;
|
||||||
import org.apache.hc.core5.http.HttpHeaders;
|
import org.apache.hc.core5.http.HttpHeaders;
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.client5.http.utils.DateUtils;
|
import org.apache.hc.client5.http.utils.DateUtils;
|
||||||
import org.apache.hc.core5.http.HttpHeaders;
|
import org.apache.hc.core5.http.HttpHeaders;
|
||||||
import org.apache.hc.core5.http.HttpRequest;
|
import org.apache.hc.core5.http.HttpRequest;
|
||||||
|
|
|
@ -34,6 +34,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.apache.hc.client5.http.cache.RequestCacheControl;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.core5.http.Header;
|
import org.apache.hc.core5.http.Header;
|
||||||
import org.apache.hc.core5.http.message.BasicHeader;
|
import org.apache.hc.core5.http.message.BasicHeader;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
|
@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.client5.http.utils.DateUtils;
|
import org.apache.hc.client5.http.utils.DateUtils;
|
||||||
import org.apache.hc.core5.http.Header;
|
import org.apache.hc.core5.http.Header;
|
||||||
import org.apache.hc.core5.http.message.BasicHeader;
|
import org.apache.hc.core5.http.message.BasicHeader;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hc.client5.http.impl.cache;
|
package org.apache.hc.client5.http.impl.cache;
|
||||||
|
|
||||||
|
import org.apache.hc.client5.http.cache.RequestCacheControl;
|
||||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
|
@ -29,6 +29,8 @@ package org.apache.hc.client5.http.impl.cache;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||||
|
import org.apache.hc.client5.http.cache.RequestCacheControl;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.client5.http.utils.DateUtils;
|
import org.apache.hc.client5.http.utils.DateUtils;
|
||||||
import org.apache.hc.core5.http.Header;
|
import org.apache.hc.core5.http.Header;
|
||||||
import org.apache.hc.core5.http.HttpHost;
|
import org.apache.hc.core5.http.HttpHost;
|
||||||
|
|
|
@ -31,6 +31,8 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||||
|
import org.apache.hc.client5.http.cache.RequestCacheControl;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.client5.http.utils.DateUtils;
|
import org.apache.hc.client5.http.utils.DateUtils;
|
||||||
import org.apache.hc.core5.http.Header;
|
import org.apache.hc.core5.http.Header;
|
||||||
import org.apache.hc.core5.http.HttpHeaders;
|
import org.apache.hc.core5.http.HttpHeaders;
|
||||||
|
|
|
@ -35,6 +35,7 @@ import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.hc.client5.http.auth.StandardAuthScheme;
|
import org.apache.hc.client5.http.auth.StandardAuthScheme;
|
||||||
|
import org.apache.hc.client5.http.cache.ResponseCacheControl;
|
||||||
import org.apache.hc.client5.http.classic.methods.HttpOptions;
|
import org.apache.hc.client5.http.classic.methods.HttpOptions;
|
||||||
import org.apache.hc.client5.http.utils.DateUtils;
|
import org.apache.hc.client5.http.utils.DateUtils;
|
||||||
import org.apache.hc.core5.http.HttpHeaders;
|
import org.apache.hc.core5.http.HttpHeaders;
|
||||||
|
|
Loading…
Reference in New Issue