Upgraded HttpCore to version 5.0-alpha1
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1724315 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ff89f7d76d
commit
1f8fe36da1
|
@ -33,7 +33,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.http.concurrent.FutureCallback;
|
||||
import org.apache.hc.core5.concurrent.FutureCallback;
|
||||
|
||||
/**
|
||||
* This example demonstrates how the he HttpClient fluent API can be used to execute multiple
|
||||
|
|
|
@ -28,9 +28,9 @@ package org.apache.http.client.fluent;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
|
||||
/**
|
||||
* This example demonstrates how the he HttpClient fluent API can be used to execute multiple
|
||||
|
|
|
@ -28,9 +28,9 @@ package org.apache.http.client.fluent;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
|
||||
/**
|
||||
* This example demonstrates basics of request execution with the HttpClient fluent API.
|
||||
|
|
|
@ -28,19 +28,19 @@ package org.apache.http.client.fluent;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.StatusLine;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpResponseException;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class FluentResponseHandling {
|
|||
}
|
||||
Charset charset = contentType.getCharset();
|
||||
if (charset == null) {
|
||||
charset = Consts.ISO_8859_1;
|
||||
charset = StandardCharsets.ISO_8859_1;
|
||||
}
|
||||
return docBuilder.parse(entity.getContent(), charset.name());
|
||||
} catch (ParserConfigurationException ex) {
|
||||
|
|
|
@ -28,9 +28,9 @@ package org.apache.http.client.fluent;
|
|||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.hc.core5.concurrent.BasicFuture;
|
||||
import org.apache.hc.core5.concurrent.FutureCallback;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.concurrent.BasicFuture;
|
||||
import org.apache.http.concurrent.FutureCallback;
|
||||
|
||||
public class Async {
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ package org.apache.http.client.fluent;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
|
||||
/**
|
||||
* This class represents arbitrary content of a specfic type that can be consumed
|
||||
|
@ -61,7 +61,7 @@ public class Content {
|
|||
public String asString() {
|
||||
Charset charset = this.type.getCharset();
|
||||
if (charset == null) {
|
||||
charset = Consts.ISO_8859_1;
|
||||
charset = StandardCharsets.ISO_8859_1;
|
||||
}
|
||||
return asString(charset);
|
||||
}
|
||||
|
|
|
@ -28,14 +28,14 @@ package org.apache.http.client.fluent;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
import org.apache.hc.core5.http.entity.EntityUtils;
|
||||
import org.apache.http.impl.client.AbstractResponseHandler;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
* {@link org.apache.http.client.ResponseHandler} implementation that converts
|
||||
* {@link org.apache.http.HttpResponse} messages to {@link org.apache.http.client.fluent.Content}
|
||||
* {@link org.apache.hc.core5.http.HttpResponse} messages to {@link org.apache.http.client.fluent.Content}
|
||||
* instances.
|
||||
*
|
||||
* @see org.apache.http.client.fluent.Content
|
||||
|
|
|
@ -33,19 +33,18 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.config.Registry;
|
||||
import org.apache.hc.core5.http.config.RegistryBuilder;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.Credentials;
|
||||
import org.apache.http.auth.NTCredentials;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.AuthCache;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.CredentialsStore;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.config.Registry;
|
||||
import org.apache.http.config.RegistryBuilder;
|
||||
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
||||
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
|
||||
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
|
||||
|
@ -106,7 +105,7 @@ public class Executor {
|
|||
}
|
||||
|
||||
private final HttpClient httpclient;
|
||||
private volatile AuthCache authCache;
|
||||
private final AuthCache authCache;
|
||||
private volatile CredentialsStore credentialsStore;
|
||||
private volatile CookieStore cookieStore;
|
||||
|
||||
|
@ -214,15 +213,6 @@ public class Executor {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated (4.5) Use {@link #use(CookieStore)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public Executor cookieStore(final CookieStore cookieStore) {
|
||||
this.cookieStore = cookieStore;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.5
|
||||
*/
|
||||
|
@ -247,7 +237,7 @@ public class Executor {
|
|||
* @see Response#discardContent()
|
||||
*/
|
||||
public Response execute(
|
||||
final Request request) throws ClientProtocolException, IOException {
|
||||
final Request request) throws IOException {
|
||||
final HttpClientContext localContext = HttpClientContext.create();
|
||||
if (this.credentialsStore != null) {
|
||||
localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsStore);
|
||||
|
|
|
@ -29,8 +29,8 @@ package org.apache.http.client.fluent;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.hc.core5.http.NameValuePair;
|
||||
import org.apache.hc.core5.http.message.BasicNameValuePair;
|
||||
|
||||
public class Form {
|
||||
|
||||
|
|
|
@ -32,9 +32,9 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.http.entity.AbstractHttpEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.util.Args;
|
||||
import org.apache.hc.core5.http.entity.AbstractHttpEntity;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
class InternalByteArrayEntity extends AbstractHttpEntity implements Cloneable {
|
||||
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.client.fluent;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
@NotThreadSafe
|
||||
class InternalEntityEnclosingHttpRequest extends InternalHttpRequest implements HttpEntityEnclosingRequest {
|
||||
|
||||
private HttpEntity entity;
|
||||
|
||||
public InternalEntityEnclosingHttpRequest(final String method, final URI requestURI) {
|
||||
super(method, requestURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpEntity getEntity() {
|
||||
return this.entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntity(final HttpEntity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean expectContinue() {
|
||||
final Header expect = getFirstHeader(HTTP.EXPECT_DIRECTIVE);
|
||||
return expect != null && HTTP.EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue());
|
||||
}
|
||||
|
||||
}
|
|
@ -33,9 +33,9 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.http.entity.AbstractHttpEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.util.Args;
|
||||
import org.apache.hc.core5.http.entity.AbstractHttpEntity;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
class InternalFileEntity extends AbstractHttpEntity implements Cloneable {
|
||||
|
||||
|
|
|
@ -31,18 +31,18 @@ import java.net.URI;
|
|||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.RequestLine;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.concurrent.Cancellable;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.RequestLine;
|
||||
import org.apache.hc.core5.http.message.AbstractHttpMessage;
|
||||
import org.apache.hc.core5.http.message.BasicRequestLine;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.Configurable;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.concurrent.Cancellable;
|
||||
import org.apache.http.message.AbstractHttpMessage;
|
||||
import org.apache.http.message.BasicRequestLine;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
@NotThreadSafe
|
||||
class InternalHttpRequest extends AbstractHttpMessage
|
||||
|
|
|
@ -31,9 +31,9 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.http.entity.AbstractHttpEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.util.Args;
|
||||
import org.apache.hc.core5.http.entity.AbstractHttpEntity;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
class InternalInputStreamEntity extends AbstractHttpEntity {
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -39,15 +40,15 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.NameValuePair;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.Configurable;
|
||||
|
@ -60,9 +61,6 @@ import org.apache.http.client.methods.HttpPost;
|
|||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.methods.HttpTrace;
|
||||
import org.apache.http.client.utils.URLEncodedUtils;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
public class Request {
|
||||
|
||||
|
@ -103,27 +101,27 @@ public class Request {
|
|||
}
|
||||
|
||||
public static Request Post(final URI uri) {
|
||||
return new Request(new InternalEntityEnclosingHttpRequest(HttpPost.METHOD_NAME, uri));
|
||||
return new Request(new InternalHttpRequest(HttpPost.METHOD_NAME, uri));
|
||||
}
|
||||
|
||||
public static Request Post(final String uri) {
|
||||
return new Request(new InternalEntityEnclosingHttpRequest(HttpPost.METHOD_NAME, URI.create(uri)));
|
||||
return new Request(new InternalHttpRequest(HttpPost.METHOD_NAME, URI.create(uri)));
|
||||
}
|
||||
|
||||
public static Request Patch(final URI uri) {
|
||||
return new Request(new InternalEntityEnclosingHttpRequest(HttpPatch.METHOD_NAME, uri));
|
||||
return new Request(new InternalHttpRequest(HttpPatch.METHOD_NAME, uri));
|
||||
}
|
||||
|
||||
public static Request Patch(final String uri) {
|
||||
return new Request(new InternalEntityEnclosingHttpRequest(HttpPatch.METHOD_NAME, URI.create(uri)));
|
||||
return new Request(new InternalHttpRequest(HttpPatch.METHOD_NAME, URI.create(uri)));
|
||||
}
|
||||
|
||||
public static Request Put(final URI uri) {
|
||||
return new Request(new InternalEntityEnclosingHttpRequest(HttpPut.METHOD_NAME, uri));
|
||||
return new Request(new InternalHttpRequest(HttpPut.METHOD_NAME, uri));
|
||||
}
|
||||
|
||||
public static Request Put(final String uri) {
|
||||
return new Request(new InternalEntityEnclosingHttpRequest(HttpPut.METHOD_NAME, URI.create(uri)));
|
||||
return new Request(new InternalHttpRequest(HttpPut.METHOD_NAME, URI.create(uri)));
|
||||
}
|
||||
|
||||
public static Request Trace(final URI uri) {
|
||||
|
@ -157,7 +155,7 @@ public class Request {
|
|||
|
||||
HttpResponse internalExecute(
|
||||
final HttpClient client,
|
||||
final HttpContext localContext) throws ClientProtocolException, IOException {
|
||||
final HttpContext localContext) throws IOException {
|
||||
final RequestConfig.Builder builder;
|
||||
if (client instanceof Configurable) {
|
||||
builder = RequestConfig.copy(((Configurable) client).getConfig());
|
||||
|
@ -181,7 +179,7 @@ public class Request {
|
|||
return client.execute(this.request, localContext);
|
||||
}
|
||||
|
||||
public Response execute() throws ClientProtocolException, IOException {
|
||||
public Response execute() throws IOException {
|
||||
return new Response(internalExecute(Executor.CLIENT, null));
|
||||
}
|
||||
|
||||
|
@ -273,7 +271,7 @@ public class Request {
|
|||
}
|
||||
|
||||
public Request userAgent(final String agent) {
|
||||
this.request.setHeader(HTTP.USER_AGENT, agent);
|
||||
this.request.setHeader(HttpHeaders.USER_AGENT, agent);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -307,12 +305,7 @@ public class Request {
|
|||
//// HTTP entity operations
|
||||
|
||||
public Request body(final HttpEntity entity) {
|
||||
if (this.request instanceof HttpEntityEnclosingRequest) {
|
||||
((HttpEntityEnclosingRequest) this.request).setEntity(entity);
|
||||
} else {
|
||||
throw new IllegalStateException(this.request.getMethod()
|
||||
+ " request cannot enclose an entity");
|
||||
}
|
||||
this.request.setEntity(entity);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -327,11 +320,11 @@ public class Request {
|
|||
}
|
||||
|
||||
public Request bodyForm(final Iterable <? extends NameValuePair> formParams) {
|
||||
return bodyForm(formParams, Consts.ISO_8859_1);
|
||||
return bodyForm(formParams, StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
public Request bodyForm(final NameValuePair... formParams) {
|
||||
return bodyForm(Arrays.asList(formParams), Consts.ISO_8859_1);
|
||||
return bodyForm(Arrays.asList(formParams), StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
public Request bodyString(final String s, final ContentType contentType) {
|
||||
|
|
|
@ -31,15 +31,14 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.StatusLine;
|
||||
import org.apache.hc.core5.http.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
import org.apache.hc.core5.http.entity.EntityUtils;
|
||||
import org.apache.http.client.HttpResponseException;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
public class Response {
|
||||
|
||||
|
@ -84,7 +83,7 @@ public class Response {
|
|||
* Handles the response using the specified {@link ResponseHandler}
|
||||
*/
|
||||
public <T> T handleResponse(
|
||||
final ResponseHandler<T> handler) throws ClientProtocolException, IOException {
|
||||
final ResponseHandler<T> handler) throws IOException {
|
||||
assertNotConsumed();
|
||||
try {
|
||||
return handler.handleResponse(this.response);
|
||||
|
@ -93,7 +92,7 @@ public class Response {
|
|||
}
|
||||
}
|
||||
|
||||
public Content returnContent() throws ClientProtocolException, IOException {
|
||||
public Content returnContent() throws IOException {
|
||||
return handleResponse(new ContentResponseHandler());
|
||||
}
|
||||
|
||||
|
|
|
@ -31,20 +31,19 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpException;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
import org.apache.hc.core5.http.entity.EntityUtils;
|
||||
import org.apache.hc.core5.http.entity.StringEntity;
|
||||
import org.apache.hc.core5.http.io.HttpRequestHandler;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.localserver.LocalServerTestBase;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpRequestHandler;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -74,14 +73,12 @@ public class TestFluent extends LocalServerTestBase {
|
|||
final HttpResponse response,
|
||||
final HttpContext context) throws HttpException, IOException {
|
||||
HttpEntity responseEntity = null;
|
||||
if (request instanceof HttpEntityEnclosingRequest) {
|
||||
final HttpEntity requestEntity = ((HttpEntityEnclosingRequest) request).getEntity();
|
||||
if (requestEntity != null) {
|
||||
final ContentType contentType = ContentType.getOrDefault(requestEntity);
|
||||
if (ContentType.TEXT_PLAIN.getMimeType().equals(contentType.getMimeType())) {
|
||||
responseEntity = new StringEntity(
|
||||
EntityUtils.toString(requestEntity), ContentType.TEXT_PLAIN);
|
||||
}
|
||||
final HttpEntity requestEntity = request.getEntity();
|
||||
if (requestEntity != null) {
|
||||
final ContentType contentType = ContentType.getOrDefault(requestEntity);
|
||||
if (ContentType.TEXT_PLAIN.getMimeType().equals(contentType.getMimeType())) {
|
||||
responseEntity = new StringEntity(
|
||||
EntityUtils.toString(requestEntity), ContentType.TEXT_PLAIN);
|
||||
}
|
||||
}
|
||||
if (responseEntity == null) {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
package org.apache.http.client.cache;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
|
||||
/**
|
||||
* Records static constants for various HTTP header names.
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
*/
|
||||
package org.apache.http.client.cache;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.http.protocol.BasicHttpContext;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
|
|
|
@ -30,20 +30,20 @@ import java.io.Serializable;
|
|||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderIterator;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.StatusLine;
|
||||
import org.apache.hc.core5.http.message.HeaderGroup;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.HeaderGroup;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* Structure used to store an {@link org.apache.http.HttpResponse} in a cache.
|
||||
* Structure used to store an {@link org.apache.hc.core5.http.HttpResponse} in a cache.
|
||||
* Some entries can optionally depend on system resources that may require
|
||||
* explicit deallocation. In such a case {@link #getResource()} should return
|
||||
* a non null instance of {@link Resource} that must be deallocated by calling
|
||||
|
@ -186,7 +186,7 @@ public class HttpCacheEntry implements Serializable {
|
|||
* @return the Date value of the header or null if the header is not present
|
||||
*/
|
||||
private Date parseDate() {
|
||||
final Header dateHdr = getFirstHeader(HTTP.DATE_HEADER);
|
||||
final Header dateHdr = getFirstHeader(HttpHeaders.DATE);
|
||||
if (dateHdr == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public class HttpCacheEntry implements Serializable {
|
|||
|
||||
/**
|
||||
* Returns the {@link StatusLine} from the origin
|
||||
* {@link org.apache.http.HttpResponse}.
|
||||
* {@link org.apache.hc.core5.http.HttpResponse}.
|
||||
*/
|
||||
public StatusLine getStatusLine() {
|
||||
return this.statusLine;
|
||||
|
@ -203,7 +203,7 @@ public class HttpCacheEntry implements Serializable {
|
|||
|
||||
/**
|
||||
* Returns the {@link ProtocolVersion} from the origin
|
||||
* {@link org.apache.http.HttpResponse}.
|
||||
* {@link org.apache.hc.core5.http.HttpResponse}.
|
||||
*/
|
||||
public ProtocolVersion getProtocolVersion() {
|
||||
return this.statusLine.getProtocolVersion();
|
||||
|
@ -211,7 +211,7 @@ public class HttpCacheEntry implements Serializable {
|
|||
|
||||
/**
|
||||
* Gets the reason phrase from the origin
|
||||
* {@link org.apache.http.HttpResponse}, for example, "Not Modified".
|
||||
* {@link org.apache.hc.core5.http.HttpResponse}, for example, "Not Modified".
|
||||
*/
|
||||
public String getReasonPhrase() {
|
||||
return this.statusLine.getReasonPhrase();
|
||||
|
@ -219,7 +219,7 @@ public class HttpCacheEntry implements Serializable {
|
|||
|
||||
/**
|
||||
* Returns the HTTP response code from the origin
|
||||
* {@link org.apache.http.HttpResponse}.
|
||||
* {@link org.apache.hc.core5.http.HttpResponse}.
|
||||
*/
|
||||
public int getStatusCode() {
|
||||
return this.statusLine.getStatusCode();
|
||||
|
@ -247,9 +247,8 @@ public class HttpCacheEntry implements Serializable {
|
|||
*/
|
||||
public Header[] getAllHeaders() {
|
||||
final HeaderGroup filteredHeaders = new HeaderGroup();
|
||||
for (final HeaderIterator iterator = responseHeaders.iterator(); iterator
|
||||
.hasNext();) {
|
||||
final Header header = (Header) iterator.next();
|
||||
for (final Iterator<Header> iterator = responseHeaders.headerIterator(); iterator.hasNext();) {
|
||||
final Header header = iterator.next();
|
||||
if (!REQUEST_METHOD_HEADER_NAME.equals(header.getName())) {
|
||||
filteredHeaders.addHeader(header);
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
*/
|
||||
package org.apache.http.client.cache;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
|
||||
/**
|
||||
* Given a particular HttpRequest, flush any cache entries that this request
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
package org.apache.http.client.cache;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.annotation.NotThreadSafe;
|
||||
|
||||
/**
|
||||
* Used to limiting the size of an incoming response body of
|
||||
|
|
|
@ -30,14 +30,14 @@ import java.io.IOException;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpException;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
|
||||
|
|
|
@ -36,12 +36,15 @@ import java.util.Set;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.HttpCacheInvalidator;
|
||||
|
@ -52,9 +55,6 @@ import org.apache.http.client.cache.Resource;
|
|||
import org.apache.http.client.cache.ResourceFactory;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
class BasicHttpCache implements HttpCache {
|
||||
private static final Set<String> safeRequestMethods = new HashSet<>(
|
||||
|
@ -199,7 +199,7 @@ class BasicHttpCache implements HttpCache {
|
|||
&& status != HttpStatus.SC_PARTIAL_CONTENT) {
|
||||
return false;
|
||||
}
|
||||
final Header hdr = resp.getFirstHeader(HTTP.CONTENT_LEN);
|
||||
final Header hdr = resp.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
|
||||
if (hdr == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ class BasicHttpCache implements HttpCache {
|
|||
|
||||
CloseableHttpResponse generateIncompleteResponseError(
|
||||
final HttpResponse response, final Resource resource) {
|
||||
final Integer contentLength = Integer.valueOf(response.getFirstHeader(HTTP.CONTENT_LEN).getValue());
|
||||
final Integer contentLength = Integer.valueOf(response.getFirstHeader(HttpHeaders.CONTENT_LENGTH).getValue());
|
||||
final HttpResponse error =
|
||||
new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_BAD_GATEWAY, "Bad Gateway");
|
||||
error.setHeader("Content-Type","text/plain;charset=UTF-8");
|
||||
|
|
|
@ -28,7 +28,7 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.hc.core5.annotation.ThreadSafe;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.HttpCacheStorage;
|
||||
import org.apache.http.client.cache.HttpCacheUpdateCallback;
|
||||
|
|
|
@ -33,8 +33,8 @@ import java.security.SecureRandom;
|
|||
import java.util.Formatter;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.annotation.GuardedBy;
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.hc.core5.annotation.GuardedBy;
|
||||
import org.apache.hc.core5.annotation.ThreadSafe;
|
||||
|
||||
/**
|
||||
* Should produce reasonably unique tokens.
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache;
|
||||
|
||||
import org.apache.http.util.Args;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* <p>Java Beans-style configuration for caching {@link org.apache.http.client.HttpClient}.
|
||||
|
|
|
@ -30,13 +30,15 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.TrailerSupplier;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
@Immutable
|
||||
class CacheEntity implements HttpEntity, Serializable {
|
||||
|
@ -51,13 +53,15 @@ class CacheEntity implements HttpEntity, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Header getContentType() {
|
||||
return this.cacheEntry.getFirstHeader(HTTP.CONTENT_TYPE);
|
||||
public String getContentType() {
|
||||
final Header header = this.cacheEntry.getFirstHeader(HttpHeaders.CONTENT_TYPE);
|
||||
return header != null ? header.getValue() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header getContentEncoding() {
|
||||
return this.cacheEntry.getFirstHeader(HTTP.CONTENT_ENCODING);
|
||||
public String getContentEncoding() {
|
||||
final Header header = this.cacheEntry.getFirstHeader(HttpHeaders.CONTENT_ENCODING);
|
||||
return header != null ? header.getValue() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -94,7 +98,13 @@ class CacheEntity implements HttpEntity, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void consumeContent() throws IOException {
|
||||
public TrailerSupplier getTrailers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTrailerNames() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,17 +33,17 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
import org.apache.http.client.cache.ResourceFactory;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* Update a {@link HttpCacheEntry} with new or updated information based on the latest
|
||||
|
@ -149,9 +149,9 @@ class CacheEntryUpdater {
|
|||
}
|
||||
|
||||
private boolean entryDateHeaderNewerThenResponse(final HttpCacheEntry entry, final HttpResponse response) {
|
||||
final Date entryDate = DateUtils.parseDate(entry.getFirstHeader(HTTP.DATE_HEADER)
|
||||
final Date entryDate = DateUtils.parseDate(entry.getFirstHeader(HttpHeaders.DATE)
|
||||
.getValue());
|
||||
final Date responseDate = DateUtils.parseDate(response.getFirstHeader(HTTP.DATE_HEADER)
|
||||
final Date responseDate = DateUtils.parseDate(response.getFirstHeader(HttpHeaders.DATE)
|
||||
.getValue());
|
||||
if (entryDate == null || responseDate == null) {
|
||||
return false;
|
||||
|
@ -163,8 +163,8 @@ class CacheEntryUpdater {
|
|||
}
|
||||
|
||||
private boolean entryAndResponseHaveDateHeader(final HttpCacheEntry entry, final HttpResponse response) {
|
||||
if (entry.getFirstHeader(HTTP.DATE_HEADER) != null
|
||||
&& response.getFirstHeader(HTTP.DATE_HEADER) != null) {
|
||||
if (entry.getFirstHeader(HttpHeaders.DATE) != null
|
||||
&& response.getFirstHeader(HttpHeaders.DATE) != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,17 +33,17 @@ import java.util.Date;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.HttpCacheInvalidator;
|
||||
import org.apache.http.client.cache.HttpCacheStorage;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
/**
|
||||
* Given a particular HttpRequest, flush any cache entries that this request
|
||||
|
@ -282,8 +282,8 @@ class CacheInvalidator implements HttpCacheInvalidator {
|
|||
|
||||
private boolean responseDateOlderThanEntryDate(final HttpResponse response,
|
||||
final HttpCacheEntry entry) {
|
||||
final Header entryDateHeader = entry.getFirstHeader(HTTP.DATE_HEADER);
|
||||
final Header responseDateHeader = response.getFirstHeader(HTTP.DATE_HEADER);
|
||||
final Header entryDateHeader = entry.getFirstHeader(HttpHeaders.DATE);
|
||||
final Header responseDateHeader = response.getFirstHeader(HttpHeaders.DATE);
|
||||
if (entryDateHeader == null || responseDateHeader == null) {
|
||||
/* be conservative; should probably flush */
|
||||
return false;
|
||||
|
|
|
@ -31,16 +31,16 @@ import java.net.MalformedURLException;
|
|||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.utils.URIUtils;
|
||||
|
@ -162,10 +162,10 @@ class CacheKeyGenerator {
|
|||
if (!first) {
|
||||
buf.append("&");
|
||||
}
|
||||
buf.append(URLEncoder.encode(headerName, Consts.UTF_8.name()));
|
||||
buf.append(URLEncoder.encode(headerName, StandardCharsets.UTF_8.name()));
|
||||
buf.append("=");
|
||||
buf.append(URLEncoder.encode(getFullHeaderValue(req.getHeaders(headerName)),
|
||||
Consts.UTF_8.name()));
|
||||
StandardCharsets.UTF_8.name()));
|
||||
first = false;
|
||||
}
|
||||
buf.append("}");
|
||||
|
|
|
@ -28,14 +28,14 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
|
@ -180,7 +180,7 @@ class CacheValidityPolicy {
|
|||
}
|
||||
|
||||
protected long getContentLengthValue(final HttpCacheEntry entry) {
|
||||
final Header cl = entry.getFirstHeader(HTTP.CONTENT_LEN);
|
||||
final Header cl = entry.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
|
||||
if (cl == null) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ class CacheValidityPolicy {
|
|||
}
|
||||
|
||||
protected boolean hasContentLengthHeader(final HttpCacheEntry entry) {
|
||||
return null != entry.getFirstHeader(HTTP.CONTENT_LEN);
|
||||
return null != entry.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,12 +28,12 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,20 +28,20 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
/**
|
||||
* Rebuilds an {@link HttpResponse} from a {@link net.sf.ehcache.CacheEntry}
|
||||
|
@ -63,7 +63,7 @@ class CachedHttpResponseGenerator {
|
|||
}
|
||||
|
||||
/**
|
||||
* If I was able to use a {@link CacheEntity} to response to the {@link org.apache.http.HttpRequest} then
|
||||
* If I was able to use a {@link CacheEntity} to response to the {@link org.apache.hc.core5.http.HttpRequest} then
|
||||
* generate an {@link HttpResponse} based on the cache entry.
|
||||
* @param request {@link HttpRequestWrapper} to generate the response for
|
||||
* @param entry {@link CacheEntity} to transform into an {@link HttpResponse}
|
||||
|
@ -107,9 +107,9 @@ class CachedHttpResponseGenerator {
|
|||
// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
|
||||
|
||||
// - Date, unless its omission is required by section 14.8.1
|
||||
Header dateHeader = entry.getFirstHeader(HTTP.DATE_HEADER);
|
||||
Header dateHeader = entry.getFirstHeader(HttpHeaders.DATE);
|
||||
if (dateHeader == null) {
|
||||
dateHeader = new BasicHeader(HTTP.DATE_HEADER, DateUtils.formatDate(new Date()));
|
||||
dateHeader = new BasicHeader(HttpHeaders.DATE, DateUtils.formatDate(new Date()));
|
||||
}
|
||||
response.addHeader(dateHeader);
|
||||
|
||||
|
@ -151,16 +151,16 @@ class CachedHttpResponseGenerator {
|
|||
return;
|
||||
}
|
||||
|
||||
Header contentLength = response.getFirstHeader(HTTP.CONTENT_LEN);
|
||||
Header contentLength = response.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
|
||||
if (contentLength == null) {
|
||||
contentLength = new BasicHeader(HTTP.CONTENT_LEN, Long.toString(entity
|
||||
contentLength = new BasicHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(entity
|
||||
.getContentLength()));
|
||||
response.setHeader(contentLength);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean transferEncodingIsPresent(final HttpResponse response) {
|
||||
final Header hdr = response.getFirstHeader(HTTP.TRANSFER_ENCODING);
|
||||
final Header hdr = response.getFirstHeader(HttpHeaders.TRANSFER_ENCODING);
|
||||
return hdr != null;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ import java.util.Date;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
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.HttpStatus;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
|
|
|
@ -37,19 +37,25 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpMessage;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolException;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.RequestLine;
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.hc.core5.annotation.ThreadSafe;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpException;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpMessage;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.ProtocolException;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.RequestLine;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
import org.apache.hc.core5.http.protocol.HttpCoreContext;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.hc.core5.util.VersionInfo;
|
||||
import org.apache.http.client.cache.CacheResponseStatus;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheContext;
|
||||
|
@ -64,12 +70,6 @@ import org.apache.http.client.utils.DateUtils;
|
|||
import org.apache.http.client.utils.URIUtils;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.impl.execchain.ClientExecChain;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpCoreContext;
|
||||
import org.apache.http.util.Args;
|
||||
import org.apache.http.util.VersionInfo;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -306,7 +306,6 @@ public class CachingExec implements ClientExecChain {
|
|||
context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target);
|
||||
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
|
||||
context.setAttribute(HttpCoreContext.HTTP_RESPONSE, out);
|
||||
context.setAttribute(HttpCoreContext.HTTP_REQ_SENT, Boolean.TRUE);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -602,8 +601,8 @@ public class CachingExec implements ClientExecChain {
|
|||
|
||||
private boolean revalidationResponseIsTooOld(final HttpResponse backendResponse,
|
||||
final HttpCacheEntry cacheEntry) {
|
||||
final Header entryDateHeader = cacheEntry.getFirstHeader(HTTP.DATE_HEADER);
|
||||
final Header responseDateHeader = backendResponse.getFirstHeader(HTTP.DATE_HEADER);
|
||||
final Header entryDateHeader = cacheEntry.getFirstHeader(HttpHeaders.DATE);
|
||||
final Header responseDateHeader = backendResponse.getFirstHeader(HttpHeaders.DATE);
|
||||
if (entryDateHeader != null && responseDateHeader != null) {
|
||||
final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
|
||||
final Date respDate = DateUtils.parseDate(responseDateHeader.getValue());
|
||||
|
@ -866,11 +865,11 @@ public class CachingExec implements ClientExecChain {
|
|||
if (existing == null) {
|
||||
return false;
|
||||
}
|
||||
final Header entryDateHeader = existing.getFirstHeader(HTTP.DATE_HEADER);
|
||||
final Header entryDateHeader = existing.getFirstHeader(HttpHeaders.DATE);
|
||||
if (entryDateHeader == null) {
|
||||
return false;
|
||||
}
|
||||
final Header responseDateHeader = backendResponse.getFirstHeader(HTTP.DATE_HEADER);
|
||||
final Header responseDateHeader = backendResponse.getFirstHeader(HttpHeaders.DATE);
|
||||
if (responseDateHeader == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,10 +32,10 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.io.SequenceInputStream;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.http.entity.AbstractHttpEntity;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
import org.apache.http.entity.AbstractHttpEntity;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
@NotThreadSafe
|
||||
class CombinedEntity extends AbstractHttpEntity {
|
||||
|
|
|
@ -28,10 +28,10 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.ProtocolException;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.ProtocolException;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
|
@ -44,8 +44,8 @@ class ConditionalRequestBuilder {
|
|||
|
||||
/**
|
||||
* When a {@link HttpCacheEntry} is stale but 'might' be used as a response
|
||||
* to an {@link org.apache.http.HttpRequest} we will attempt to revalidate
|
||||
* the entry with the origin. Build the origin {@link org.apache.http.HttpRequest}
|
||||
* to an {@link org.apache.hc.core5.http.HttpRequest} we will attempt to revalidate
|
||||
* the entry with the origin. Build the origin {@link org.apache.hc.core5.http.HttpRequest}
|
||||
* here and return it.
|
||||
*
|
||||
* @param request the original request from the caller
|
||||
|
@ -55,7 +55,7 @@ class ConditionalRequestBuilder {
|
|||
*/
|
||||
public HttpRequestWrapper buildConditionalRequest(final HttpRequestWrapper request, final HttpCacheEntry cacheEntry)
|
||||
throws ProtocolException {
|
||||
final HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(request.getOriginal());
|
||||
final HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(request.getOriginal(), request.getTarget());
|
||||
newRequest.setHeaders(request.getAllHeaders());
|
||||
final Header eTag = cacheEntry.getFirstHeader(HeaderConstants.ETAG);
|
||||
if (eTag != null) {
|
||||
|
@ -84,9 +84,9 @@ class ConditionalRequestBuilder {
|
|||
|
||||
/**
|
||||
* When a {@link HttpCacheEntry} does not exist for a specific
|
||||
* {@link org.apache.http.HttpRequest} we attempt to see if an existing
|
||||
* {@link org.apache.hc.core5.http.HttpRequest} we attempt to see if an existing
|
||||
* {@link HttpCacheEntry} is appropriate by building a conditional
|
||||
* {@link org.apache.http.HttpRequest} using the variants' ETag values.
|
||||
* {@link org.apache.hc.core5.http.HttpRequest} using the variants' ETag values.
|
||||
* If no such values exist, the request is unmodified
|
||||
*
|
||||
* @param request the original request from the caller
|
||||
|
@ -95,7 +95,7 @@ class ConditionalRequestBuilder {
|
|||
*/
|
||||
public HttpRequestWrapper buildConditionalRequestFromVariants(final HttpRequestWrapper request,
|
||||
final Map<String, Variant> variants) {
|
||||
final HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(request.getOriginal());
|
||||
final HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(request.getOriginal(), request.getTarget());
|
||||
newRequest.setHeaders(request.getAllHeaders());
|
||||
|
||||
// we do not support partial content so all etags are used
|
||||
|
@ -125,7 +125,7 @@ class ConditionalRequestBuilder {
|
|||
* @return an unconditional validation request
|
||||
*/
|
||||
public HttpRequestWrapper buildUnconditionalRequest(final HttpRequestWrapper request, final HttpCacheEntry entry) {
|
||||
final HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(request.getOriginal());
|
||||
final HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(request.getOriginal(), request.getTarget());
|
||||
newRequest.setHeaders(request.getAllHeaders());
|
||||
newRequest.addHeader(HeaderConstants.CACHE_CONTROL,HeaderConstants.CACHE_CONTROL_NO_CACHE);
|
||||
newRequest.addHeader(HeaderConstants.PRAGMA,HeaderConstants.CACHE_CONTROL_NO_CACHE);
|
||||
|
|
|
@ -26,12 +26,12 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache;
|
||||
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.apache.hc.core5.annotation.ThreadSafe;
|
||||
|
||||
/**
|
||||
* Implements a bounded failure cache. The oldest entries are discarded when
|
||||
* the maximum size is exceeded.
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.io.ObjectInputStream;
|
|||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.HttpCacheEntrySerializationException;
|
||||
import org.apache.http.client.cache.HttpCacheEntrySerializer;
|
||||
|
|
|
@ -26,13 +26,13 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache;
|
||||
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.hc.core5.annotation.ThreadSafe;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* An implementation that backs off exponentially based on the number of
|
||||
* consecutive failed attempts stored in the
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
|
||||
/**
|
||||
* The error count with a creation timestamp and its associated key.
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.hc.core5.annotation.ThreadSafe;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.http.client.cache.InputLimit;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
import org.apache.http.client.cache.ResourceFactory;
|
||||
|
|
|
@ -29,7 +29,7 @@ package org.apache.http.impl.client.cache;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.http.client.cache.InputLimit;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
import org.apache.http.client.cache.ResourceFactory;
|
||||
|
|
|
@ -30,9 +30,9 @@ import java.io.IOException;
|
|||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ import java.io.OutputStream;
|
|||
import java.io.RandomAccessFile;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
|
||||
@Immutable
|
||||
class IOUtils {
|
||||
|
|
|
@ -26,14 +26,14 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache;
|
||||
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.hc.core5.annotation.ThreadSafe;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* Immediately schedules any incoming validation request. Relies on
|
||||
* {@link CacheConfig} to configure the used {@link java.util.concurrent.ThreadPoolExecutor}.
|
||||
|
|
|
@ -33,12 +33,12 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.hc.core5.annotation.ThreadSafe;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.HttpCacheStorage;
|
||||
import org.apache.http.client.cache.HttpCacheUpdateCallback;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
|
@ -26,21 +26,19 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderIterator;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.message.AbstractHttpMessage;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.StatusLine;
|
||||
import org.apache.hc.core5.http.message.AbstractHttpMessage;
|
||||
import org.apache.hc.core5.http.message.BasicStatusLine;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
|
@ -57,6 +55,11 @@ final class OptionsHttp11Response extends AbstractHttpMessage implements HttpRes
|
|||
return statusLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return statusLine.getStatusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatusLine(final StatusLine statusline) {
|
||||
// No-op on purpose, this class is not going to be doing any work.
|
||||
|
@ -109,27 +112,27 @@ final class OptionsHttp11Response extends AbstractHttpMessage implements HttpRes
|
|||
|
||||
@Override
|
||||
public boolean containsHeader(final String name) {
|
||||
return this.headergroup.containsHeader(name);
|
||||
return super.containsHeader(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header[] getHeaders(final String name) {
|
||||
return this.headergroup.getHeaders(name);
|
||||
return super.getHeaders(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header getFirstHeader(final String name) {
|
||||
return this.headergroup.getFirstHeader(name);
|
||||
return super.getFirstHeader(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header getLastHeader(final String name) {
|
||||
return this.headergroup.getLastHeader(name);
|
||||
return super.getLastHeader(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header[] getAllHeaders() {
|
||||
return this.headergroup.getAllHeaders();
|
||||
return super.getAllHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -138,7 +141,7 @@ final class OptionsHttp11Response extends AbstractHttpMessage implements HttpRes
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addHeader(final String name, final String value) {
|
||||
public void addHeader(final String name, final Object value) {
|
||||
// No-op on purpose, this class is not going to be doing any work.
|
||||
}
|
||||
|
||||
|
@ -148,7 +151,7 @@ final class OptionsHttp11Response extends AbstractHttpMessage implements HttpRes
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setHeader(final String name, final String value) {
|
||||
public void setHeader(final String name, final Object value) {
|
||||
// No-op on purpose, this class is not going to be doing any work.
|
||||
}
|
||||
|
||||
|
@ -168,25 +171,14 @@ final class OptionsHttp11Response extends AbstractHttpMessage implements HttpRes
|
|||
}
|
||||
|
||||
@Override
|
||||
public HeaderIterator headerIterator() {
|
||||
return this.headergroup.iterator();
|
||||
public Iterator<Header> headerIterator() {
|
||||
return super.headerIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HeaderIterator headerIterator(final String name) {
|
||||
return this.headergroup.iterator(name);
|
||||
public Iterator<Header> headerIterator(final String name) {
|
||||
return super.headerIterator(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpParams getParams() {
|
||||
if (this.params == null) {
|
||||
this.params = new BasicHttpParams();
|
||||
}
|
||||
return this.params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParams(final HttpParams params) {
|
||||
// No-op on purpose, this class is not going to be doing any work.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,10 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* Proxies for HTTP message objects.
|
||||
|
|
|
@ -30,24 +30,25 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HeaderElements;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.entity.AbstractHttpEntity;
|
||||
import org.apache.hc.core5.http.entity.ContentType;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.hc.core5.http.message.BasicStatusLine;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.entity.AbstractHttpEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
|
@ -110,7 +111,7 @@ class RequestProtocolCompliance {
|
|||
throws ClientProtocolException {
|
||||
|
||||
if (requestMustNotHaveEntity(request)) {
|
||||
((HttpEntityEnclosingRequest) request).setEntity(null);
|
||||
request.setEntity(null);
|
||||
}
|
||||
|
||||
verifyRequestWithExpectContinueFlagHas100continueHeader(request);
|
||||
|
@ -159,8 +160,7 @@ class RequestProtocolCompliance {
|
|||
}
|
||||
|
||||
private boolean requestMustNotHaveEntity(final HttpRequest request) {
|
||||
return HeaderConstants.TRACE_METHOD.equals(request.getRequestLine().getMethod())
|
||||
&& request instanceof HttpEntityEnclosingRequest;
|
||||
return HeaderConstants.TRACE_METHOD.equals(request.getRequestLine().getMethod());
|
||||
}
|
||||
|
||||
private void decrementOPTIONSMaxForwardsIfGreaterThen0(final HttpRequest request) {
|
||||
|
@ -184,29 +184,19 @@ class RequestProtocolCompliance {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!(request instanceof HttpEntityEnclosingRequest)) {
|
||||
return;
|
||||
}
|
||||
|
||||
addContentTypeHeaderIfMissing((HttpEntityEnclosingRequest) request);
|
||||
addContentTypeHeaderIfMissing(request);
|
||||
}
|
||||
|
||||
private void addContentTypeHeaderIfMissing(final HttpEntityEnclosingRequest request) {
|
||||
if (request.getEntity().getContentType() == null) {
|
||||
((AbstractHttpEntity) request.getEntity()).setContentType(
|
||||
ContentType.APPLICATION_OCTET_STREAM.getMimeType());
|
||||
private void addContentTypeHeaderIfMissing(final HttpRequest request) {
|
||||
final HttpEntity entity = request.getEntity();
|
||||
if (entity != null && entity.getContentType() == null) {
|
||||
((AbstractHttpEntity) entity).setContentType(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyRequestWithExpectContinueFlagHas100continueHeader(final HttpRequest request) {
|
||||
if (request instanceof HttpEntityEnclosingRequest) {
|
||||
|
||||
if (((HttpEntityEnclosingRequest) request).expectContinue()
|
||||
&& ((HttpEntityEnclosingRequest) request).getEntity() != null) {
|
||||
add100ContinueHeaderIfMissing(request);
|
||||
} else {
|
||||
remove100ContinueHeaderIfExists(request);
|
||||
}
|
||||
if (request.containsHeader(HttpHeaders.EXPECT) && request.getEntity() != null) {
|
||||
add100ContinueHeaderIfMissing(request);
|
||||
} else {
|
||||
remove100ContinueHeaderIfExists(request);
|
||||
}
|
||||
|
@ -215,12 +205,12 @@ class RequestProtocolCompliance {
|
|||
private void remove100ContinueHeaderIfExists(final HttpRequest request) {
|
||||
boolean hasHeader = false;
|
||||
|
||||
final Header[] expectHeaders = request.getHeaders(HTTP.EXPECT_DIRECTIVE);
|
||||
final Header[] expectHeaders = request.getHeaders(HttpHeaders.EXPECT);
|
||||
List<HeaderElement> expectElementsThatAreNot100Continue = new ArrayList<>();
|
||||
|
||||
for (final Header h : expectHeaders) {
|
||||
for (final HeaderElement elt : h.getElements()) {
|
||||
if (!(HTTP.EXPECT_CONTINUE.equalsIgnoreCase(elt.getName()))) {
|
||||
if (!(HeaderElements.CONTINUE.equalsIgnoreCase(elt.getName()))) {
|
||||
expectElementsThatAreNot100Continue.add(elt);
|
||||
} else {
|
||||
hasHeader = true;
|
||||
|
@ -230,7 +220,7 @@ class RequestProtocolCompliance {
|
|||
if (hasHeader) {
|
||||
request.removeHeader(h);
|
||||
for (final HeaderElement elt : expectElementsThatAreNot100Continue) {
|
||||
final BasicHeader newHeader = new BasicHeader(HTTP.EXPECT_DIRECTIVE, elt.getName());
|
||||
final BasicHeader newHeader = new BasicHeader(HeaderElements.CONTINUE, elt.getName());
|
||||
request.addHeader(newHeader);
|
||||
}
|
||||
return;
|
||||
|
@ -243,16 +233,16 @@ class RequestProtocolCompliance {
|
|||
private void add100ContinueHeaderIfMissing(final HttpRequest request) {
|
||||
boolean hasHeader = false;
|
||||
|
||||
for (final Header h : request.getHeaders(HTTP.EXPECT_DIRECTIVE)) {
|
||||
for (final Header h : request.getHeaders(HttpHeaders.EXPECT)) {
|
||||
for (final HeaderElement elt : h.getElements()) {
|
||||
if (HTTP.EXPECT_CONTINUE.equalsIgnoreCase(elt.getName())) {
|
||||
if (HeaderElements.CONTINUE.equalsIgnoreCase(elt.getName())) {
|
||||
hasHeader = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasHeader) {
|
||||
request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
|
||||
request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,10 @@ package org.apache.http.impl.client.cache;
|
|||
import java.lang.ref.PhantomReference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
@Immutable
|
||||
class ResourceReference extends PhantomReference<HttpCacheEntry> {
|
||||
|
|
|
@ -33,17 +33,17 @@ import java.util.Set;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpMessage;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpMessage;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
/**
|
||||
* Determines if an HttpResponse can be cached.
|
||||
|
@ -123,7 +123,7 @@ class ResponseCachingPolicy {
|
|||
return false;
|
||||
}
|
||||
|
||||
final Header contentLength = response.getFirstHeader(HTTP.CONTENT_LEN);
|
||||
final Header contentLength = response.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
|
||||
if (contentLength != null) {
|
||||
final int contentLengthValue = Integer.parseInt(contentLength.getValue());
|
||||
if (contentLengthValue > this.maxObjectSizeBytes) {
|
||||
|
@ -143,7 +143,7 @@ class ResponseCachingPolicy {
|
|||
return false;
|
||||
}
|
||||
|
||||
final Header[] dateHeaders = response.getHeaders(HTTP.DATE_HEADER);
|
||||
final Header[] dateHeaders = response.getHeaders(HttpHeaders.DATE);
|
||||
|
||||
if (dateHeaders.length != 1) {
|
||||
return false;
|
||||
|
@ -279,7 +279,7 @@ class ResponseCachingPolicy {
|
|||
return false;
|
||||
}
|
||||
final Header expiresHdr = response.getFirstHeader(HeaderConstants.EXPIRES);
|
||||
final Header dateHdr = response.getFirstHeader(HTTP.DATE_HEADER);
|
||||
final Header dateHdr = response.getFirstHeader(HttpHeaders.DATE);
|
||||
if (expiresHdr == null || dateHdr == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -31,21 +31,21 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.hc.core5.annotation.Immutable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HeaderElements;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
|
@ -99,7 +99,7 @@ class ResponseProtocolCompliance {
|
|||
|
||||
private void warningsWithNonMatchingWarnDatesAreRemoved(
|
||||
final HttpResponse response) {
|
||||
final Date responseDate = DateUtils.parseDate(response.getFirstHeader(HTTP.DATE_HEADER).getValue());
|
||||
final Date responseDate = DateUtils.parseDate(response.getFirstHeader(HttpHeaders.DATE).getValue());
|
||||
if (responseDate == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ class ResponseProtocolCompliance {
|
|||
}
|
||||
|
||||
private void identityIsNotUsedInContentEncoding(final HttpResponse response) {
|
||||
final Header[] hdrs = response.getHeaders(HTTP.CONTENT_ENCODING);
|
||||
final Header[] hdrs = response.getHeaders(HttpHeaders.CONTENT_ENCODING);
|
||||
if (hdrs == null || hdrs.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -153,21 +153,21 @@ class ResponseProtocolCompliance {
|
|||
}
|
||||
final String newHeaderValue = buf.toString();
|
||||
if (!"".equals(newHeaderValue)) {
|
||||
newHeaders.add(new BasicHeader(HTTP.CONTENT_ENCODING, newHeaderValue));
|
||||
newHeaders.add(new BasicHeader(HttpHeaders.CONTENT_ENCODING, newHeaderValue));
|
||||
}
|
||||
}
|
||||
if (!modified) {
|
||||
return;
|
||||
}
|
||||
response.removeHeaders(HTTP.CONTENT_ENCODING);
|
||||
response.removeHeaders(HttpHeaders.CONTENT_ENCODING);
|
||||
for (final Header h : newHeaders) {
|
||||
response.addHeader(h);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensure206ContainsDateHeader(final HttpResponse response) {
|
||||
if (response.getFirstHeader(HTTP.DATE_HEADER) == null) {
|
||||
response.addHeader(HTTP.DATE_HEADER, DateUtils.formatDate(new Date()));
|
||||
if (response.getFirstHeader(HttpHeaders.DATE) == null) {
|
||||
response.addHeader(HttpHeaders.DATE, DateUtils.formatDate(new Date()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -193,15 +193,15 @@ class ResponseProtocolCompliance {
|
|||
return;
|
||||
}
|
||||
|
||||
if (response.getFirstHeader(HTTP.CONTENT_LEN) == null) {
|
||||
response.addHeader(HTTP.CONTENT_LEN, "0");
|
||||
if (response.getFirstHeader(HttpHeaders.CONTENT_LENGTH) == null) {
|
||||
response.addHeader(HttpHeaders.CONTENT_LENGTH, "0");
|
||||
}
|
||||
}
|
||||
|
||||
private void ensure304DoesNotContainExtraEntityHeaders(final HttpResponse response) {
|
||||
final String[] disallowedEntityHeaders = { HeaderConstants.ALLOW, HTTP.CONTENT_ENCODING,
|
||||
"Content-Language", HTTP.CONTENT_LEN, "Content-MD5",
|
||||
"Content-Range", HTTP.CONTENT_TYPE, HeaderConstants.LAST_MODIFIED
|
||||
final String[] disallowedEntityHeaders = { HeaderConstants.ALLOW, HttpHeaders.CONTENT_ENCODING,
|
||||
"Content-Language", HttpHeaders.CONTENT_LENGTH, "Content-MD5",
|
||||
"Content-Range", HttpHeaders.CONTENT_TYPE, HeaderConstants.LAST_MODIFIED
|
||||
};
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
|
||||
for(final String hdr : disallowedEntityHeaders) {
|
||||
|
@ -224,10 +224,9 @@ class ResponseProtocolCompliance {
|
|||
}
|
||||
|
||||
final HttpRequest originalRequest = request.getOriginal();
|
||||
if (originalRequest instanceof HttpEntityEnclosingRequest) {
|
||||
if (((HttpEntityEnclosingRequest)originalRequest).expectContinue()) {
|
||||
return;
|
||||
}
|
||||
final Header header = originalRequest.getFirstHeader(HttpHeaders.EXPECT);
|
||||
if (header != null && header.getValue().equalsIgnoreCase(HeaderElements.CONTINUE)) {
|
||||
return;
|
||||
}
|
||||
consumeBody(response);
|
||||
throw new ClientProtocolException(UNEXPECTED_100_CONTINUE);
|
||||
|
@ -245,7 +244,7 @@ class ResponseProtocolCompliance {
|
|||
|
||||
private void removeResponseTransferEncoding(final HttpResponse response) {
|
||||
response.removeHeaders("TE");
|
||||
response.removeHeaders(HTTP.TRANSFER_ENCODING);
|
||||
response.removeHeaders(HttpHeaders.TRANSFER_ENCODING);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ import java.lang.reflect.InvocationHandler;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
|
||||
/**
|
||||
* A proxy class that can enhance an arbitrary {@link HttpResponse} with
|
||||
|
|
|
@ -30,15 +30,15 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.annotation.NotThreadSafe;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.cache.InputLimit;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
import org.apache.http.client.cache.ResourceFactory;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.util.List;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
|
||||
/** This class provides for parsing and understanding Warning headers. As
|
||||
|
|
|
@ -30,9 +30,6 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.Element;
|
||||
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.HttpCacheEntrySerializer;
|
||||
import org.apache.http.client.cache.HttpCacheStorage;
|
||||
|
@ -41,6 +38,9 @@ import org.apache.http.client.cache.HttpCacheUpdateException;
|
|||
import org.apache.http.impl.client.cache.CacheConfig;
|
||||
import org.apache.http.impl.client.cache.DefaultHttpCacheEntrySerializer;
|
||||
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.Element;
|
||||
|
||||
/**
|
||||
* <p>This class is a storage backend for cache entries that uses the
|
||||
* popular <a href="http://ehcache.org">Ehcache</a> cache implementation.
|
||||
|
|
|
@ -68,5 +68,5 @@ public interface KeyHashingScheme {
|
|||
* as its key for looking up cache entries
|
||||
* @return a cache key suitable for use with memcached
|
||||
*/
|
||||
public String hash(String storageKey);
|
||||
String hash(String storageKey);
|
||||
}
|
||||
|
|
|
@ -39,13 +39,13 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.StatusLine;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicStatusLine;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -28,11 +28,12 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.http.client.cache.HttpCacheContext;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
|
@ -40,9 +41,8 @@ import org.apache.http.client.methods.HttpRequestWrapper;
|
|||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.impl.execchain.ClientExecChain;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.easymock.IExpectationSetters;
|
||||
import org.easymock.EasyMock;
|
||||
import org.easymock.IExpectationSetters;
|
||||
import org.junit.Before;
|
||||
|
||||
public abstract class AbstractProtocolTest {
|
||||
|
@ -85,7 +85,7 @@ public abstract class AbstractProtocolTest {
|
|||
|
||||
body = HttpTestUtils.makeBody(entityLength);
|
||||
|
||||
request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1));
|
||||
request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1), host);
|
||||
|
||||
context = HttpCacheContext.create();
|
||||
context.setTargetHost(host);
|
||||
|
|
|
@ -28,18 +28,18 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.HttpException;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.impl.execchain.ClientExecChain;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
|
||||
public class DummyBackend implements ClientExecChain {
|
||||
|
||||
|
|
|
@ -32,24 +32,24 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpMessage;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.RequestLine;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpMessage;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.RequestLine;
|
||||
import org.apache.hc.core5.http.StatusLine;
|
||||
import org.apache.hc.core5.http.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.hc.core5.http.message.BasicStatusLine;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.Assert;
|
||||
|
||||
public class HttpTestUtils {
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicStatusLine;
|
||||
|
||||
public class OKStatus extends BasicStatusLine {
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache;
|
||||
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.easymock.IArgumentMatcher;
|
||||
|
||||
public class RequestEquivalent implements IArgumentMatcher {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.easymock.IArgumentMatcher;
|
||||
|
||||
public class ResponseEquivalent implements IArgumentMatcher {
|
||||
|
|
|
@ -32,10 +32,11 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.ProtocolException;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.ProtocolException;
|
||||
import org.apache.hc.core5.http.StatusLine;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
|
@ -44,7 +45,6 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -53,6 +53,7 @@ public class TestAsynchronousValidationRequest {
|
|||
|
||||
private AsynchronousValidator mockParent;
|
||||
private CachingExec mockClient;
|
||||
private HttpHost host;
|
||||
private HttpRoute route;
|
||||
private HttpRequestWrapper request;
|
||||
private HttpClientContext context;
|
||||
|
@ -65,8 +66,9 @@ public class TestAsynchronousValidationRequest {
|
|||
public void setUp() {
|
||||
mockParent = mock(AsynchronousValidator.class);
|
||||
mockClient = mock(CachingExec.class);
|
||||
route = new HttpRoute(new HttpHost("foo.example.com", 80));
|
||||
request = HttpRequestWrapper.wrap(new HttpGet("/"));
|
||||
host = new HttpHost("foo.example.com", 80);
|
||||
route = new HttpRoute(host);
|
||||
request = HttpRequestWrapper.wrap(new HttpGet("/"), host);
|
||||
context = HttpClientContext.create();
|
||||
mockExecAware = mock(HttpExecutionAware.class);
|
||||
mockCacheEntry = mock(HttpCacheEntry.class);
|
||||
|
|
|
@ -37,9 +37,10 @@ import java.io.IOException;
|
|||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
|
@ -47,7 +48,6 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -59,6 +59,7 @@ public class TestAsynchronousValidator {
|
|||
private AsynchronousValidator impl;
|
||||
|
||||
private CachingExec mockClient;
|
||||
private HttpHost host;
|
||||
private HttpRoute route;
|
||||
private HttpRequestWrapper request;
|
||||
private HttpClientContext context;
|
||||
|
@ -70,8 +71,9 @@ public class TestAsynchronousValidator {
|
|||
@Before
|
||||
public void setUp() {
|
||||
mockClient = mock(CachingExec.class);
|
||||
route = new HttpRoute(new HttpHost("foo.example.com", 80));
|
||||
request = HttpRequestWrapper.wrap(new HttpGet("/"));
|
||||
host = new HttpHost("foo.example.com", 80);
|
||||
route = new HttpRoute(host);
|
||||
request = HttpRequestWrapper.wrap(new HttpGet("/"), host);
|
||||
context = HttpClientContext.create();
|
||||
context.setTargetHost(new HttpHost("foo.example.com"));
|
||||
mockExecAware = mock(HttpExecutionAware.class);
|
||||
|
@ -160,8 +162,8 @@ public class TestAsynchronousValidator {
|
|||
when(mockCacheEntry.getHeaders(HeaderConstants.VARY)).thenReturn(variantHeaders);
|
||||
mockSchedulingStrategy.schedule(isA(AsynchronousValidationRequest.class));
|
||||
|
||||
impl.revalidateCacheEntry(mockClient, route, HttpRequestWrapper.wrap(req1), context, mockExecAware, mockCacheEntry);
|
||||
impl.revalidateCacheEntry(mockClient, route, HttpRequestWrapper.wrap(req2), context, mockExecAware, mockCacheEntry);
|
||||
impl.revalidateCacheEntry(mockClient, route, HttpRequestWrapper.wrap(req1, host), context, mockExecAware, mockCacheEntry);
|
||||
impl.revalidateCacheEntry(mockClient, route, HttpRequestWrapper.wrap(req2, host), context, mockExecAware, mockCacheEntry);
|
||||
|
||||
verify(mockCacheEntry, times(2)).hasVariants();
|
||||
verify(mockCacheEntry, times(2)).getHeaders(HeaderConstants.VARY);
|
||||
|
|
|
@ -41,13 +41,17 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.entity.BasicHttpEntity;
|
||||
import org.apache.hc.core5.http.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
|
@ -58,10 +62,6 @@ import org.apache.http.client.methods.HttpOptions;
|
|||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpTrace;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.entity.BasicHttpEntity;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -33,14 +33,14 @@ import static org.junit.Assert.fail;
|
|||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class TestCacheEntryUpdater {
|
|||
new BasicHeader("Date", DateUtils.formatDate(responseDate)),
|
||||
new BasicHeader("ETag", "\"etag\"")};
|
||||
entry = HttpTestUtils.makeCacheEntry(headers);
|
||||
response.setHeaders(new Header[]{});
|
||||
response.setHeaders();
|
||||
|
||||
final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
|
||||
new Date(), new Date(), response);
|
||||
|
@ -112,9 +112,8 @@ public class TestCacheEntryUpdater {
|
|||
new BasicHeader("Cache-Control", "max-age=0"),};
|
||||
entry = HttpTestUtils.makeCacheEntry(headers);
|
||||
|
||||
response.setHeaders(new Header[] {
|
||||
new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
|
||||
new BasicHeader("Cache-Control", "public")});
|
||||
response.setHeaders(new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
|
||||
new BasicHeader("Cache-Control", "public"));
|
||||
|
||||
final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
|
||||
new Date(), new Date(), response);
|
||||
|
@ -136,9 +135,8 @@ public class TestCacheEntryUpdater {
|
|||
new BasicHeader("ETag", "\"etag\"")};
|
||||
|
||||
entry = HttpTestUtils.makeCacheEntry(headers);
|
||||
response.setHeaders(new Header[]{
|
||||
new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
|
||||
new BasicHeader("Cache-Control", "public"),});
|
||||
response.setHeaders(new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
|
||||
new BasicHeader("Cache-Control", "public"));
|
||||
|
||||
final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
|
||||
new Date(), new Date(), response);
|
||||
|
|
|
@ -36,21 +36,19 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.HttpCacheStorage;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -103,7 +101,7 @@ public class TestCacheInvalidator {
|
|||
|
||||
@Test
|
||||
public void testInvalidatesUrisInContentLocationHeadersOnPUTs() throws Exception {
|
||||
final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
final HttpRequest putRequest = new BasicHttpRequest("PUT","/",HTTP_1_1);
|
||||
putRequest.setEntity(HttpTestUtils.makeBody(128));
|
||||
putRequest.setHeader("Content-Length","128");
|
||||
|
||||
|
@ -125,7 +123,7 @@ public class TestCacheInvalidator {
|
|||
|
||||
@Test
|
||||
public void testInvalidatesUrisInLocationHeadersOnPUTs() throws Exception {
|
||||
final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
final HttpRequest putRequest = new BasicHttpRequest("PUT","/",HTTP_1_1);
|
||||
putRequest.setEntity(HttpTestUtils.makeBody(128));
|
||||
putRequest.setHeader("Content-Length","128");
|
||||
|
||||
|
@ -147,7 +145,7 @@ public class TestCacheInvalidator {
|
|||
|
||||
@Test
|
||||
public void testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs() throws Exception {
|
||||
final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
final HttpRequest putRequest = new BasicHttpRequest("PUT","/",HTTP_1_1);
|
||||
putRequest.setEntity(HttpTestUtils.makeBody(128));
|
||||
putRequest.setHeader("Content-Length","128");
|
||||
|
||||
|
@ -169,7 +167,7 @@ public class TestCacheInvalidator {
|
|||
|
||||
@Test
|
||||
public void testDoesNotInvalidateUrisInContentLocationHeadersOnPUTsToDifferentHosts() throws Exception {
|
||||
final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
final HttpRequest putRequest = new BasicHttpRequest("PUT","/",HTTP_1_1);
|
||||
putRequest.setEntity(HttpTestUtils.makeBody(128));
|
||||
putRequest.setHeader("Content-Length","128");
|
||||
|
||||
|
|
|
@ -30,14 +30,14 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -34,14 +34,14 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -341,7 +341,7 @@ public class TestCacheValidityPolicy {
|
|||
@Test
|
||||
public void testCorrectContentLengthDoesntInvalidateEntry() {
|
||||
final int contentLength = 128;
|
||||
final Header[] headers = { new BasicHeader(HTTP.CONTENT_LEN, Integer.toString(contentLength)) };
|
||||
final Header[] headers = { new BasicHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(contentLength)) };
|
||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers, HttpTestUtils.getRandomBytes(contentLength));
|
||||
assertTrue(impl.contentLengthHeaderMatchesActualLength(entry));
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ public class TestCacheValidityPolicy {
|
|||
@Test
|
||||
public void testWrongContentLengthInvalidatesEntry() {
|
||||
final int contentLength = 128;
|
||||
final Header[] headers = {new BasicHeader(HTTP.CONTENT_LEN, Integer.toString(contentLength+1))};
|
||||
final Header[] headers = {new BasicHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(contentLength+1))};
|
||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers, HttpTestUtils.getRandomBytes(contentLength));
|
||||
assertFalse(impl.contentLengthHeaderMatchesActualLength(entry));
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ public class TestCacheValidityPolicy {
|
|||
@Test
|
||||
public void testNullResourceInvalidatesEntry() {
|
||||
final int contentLength = 128;
|
||||
final Header[] headers = {new BasicHeader(HTTP.CONTENT_LEN, Integer.toString(contentLength))};
|
||||
final Header[] headers = {new BasicHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(contentLength))};
|
||||
final HttpCacheEntry entry = HttpTestUtils.makeHeadCacheEntry(headers);
|
||||
assertFalse(impl.contentLengthHeaderMatchesActualLength(entry));
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache;
|
||||
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -35,11 +35,12 @@ import static org.mockito.Mockito.when;
|
|||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -47,6 +48,7 @@ import org.junit.Test;
|
|||
@SuppressWarnings({"boxing","static-access"}) // test code
|
||||
public class TestCachedHttpResponseGenerator {
|
||||
|
||||
private HttpHost host;
|
||||
private HttpCacheEntry entry;
|
||||
private HttpRequestWrapper request;
|
||||
private CacheValidityPolicy mockValidityPolicy;
|
||||
|
@ -54,8 +56,9 @@ public class TestCachedHttpResponseGenerator {
|
|||
|
||||
@Before
|
||||
public void setUp() {
|
||||
host = new HttpHost("foo.example.com", 80);
|
||||
entry = HttpTestUtils.makeCacheEntry(new HashMap<String, String>());
|
||||
request = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
request = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
mockValidityPolicy = mock(CacheValidityPolicy.class);
|
||||
impl = new CachedHttpResponseGenerator(mockValidityPolicy);
|
||||
}
|
||||
|
@ -159,7 +162,7 @@ public class TestCachedHttpResponseGenerator {
|
|||
|
||||
@Test
|
||||
public void testResponseDoesNotContainEntityToServeHEADRequestIfEntryContainsResource() throws Exception {
|
||||
final HttpRequestWrapper headRequest = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultHEADRequest());
|
||||
final HttpRequestWrapper headRequest = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultHEADRequest(), host);
|
||||
final HttpResponse response = impl.generateResponse(headRequest, entry);
|
||||
|
||||
Assert.assertNull(response.getEntity());
|
||||
|
|
|
@ -28,14 +28,14 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -45,11 +45,17 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.HeaderElements;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.entity.InputStreamEntity;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.hc.core5.http.message.BasicStatusLine;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
|
@ -58,14 +64,9 @@ import org.apache.http.client.methods.HttpRequestWrapper;
|
|||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.impl.execchain.ClientExecChain;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.easymock.IExpectationSetters;
|
||||
import org.easymock.EasyMock;
|
||||
import org.easymock.IExpectationSetters;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -252,7 +253,7 @@ public class TestCachingExec extends TestCachingExecChain {
|
|||
mockImplMethods(GET_CURRENT_DATE, HANDLE_BACKEND_RESPONSE);
|
||||
|
||||
final HttpRequestWrapper validate = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final CloseableHttpResponse originResponse = Proxies.enhanceResponse(
|
||||
new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, "Not Found"));
|
||||
final CloseableHttpResponse finalResponse = Proxies.enhanceResponse(
|
||||
|
@ -284,7 +285,7 @@ public class TestCachingExec extends TestCachingExecChain {
|
|||
mockImplMethods(GET_CURRENT_DATE);
|
||||
|
||||
final HttpRequestWrapper validate = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse originResponse = Proxies.enhanceResponse(
|
||||
new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not Modified"));
|
||||
final HttpCacheEntry updatedEntry = HttpTestUtils.makeCacheEntry();
|
||||
|
@ -318,9 +319,9 @@ public class TestCachingExec extends TestCachingExecChain {
|
|||
EasyMock.resetToStrict(mockBackend);
|
||||
|
||||
final HttpRequestWrapper validate = HttpRequestWrapper.wrap(
|
||||
new HttpGet("http://foo.example.com/resource"));
|
||||
new HttpGet("http://foo.example.com/resource"), host);
|
||||
final HttpRequestWrapper relativeValidate = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/resource", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/resource", HttpVersion.HTTP_1_1), host);
|
||||
final CloseableHttpResponse originResponse = Proxies.enhanceResponse(
|
||||
new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "Okay"));
|
||||
|
||||
|
@ -346,7 +347,7 @@ public class TestCachingExec extends TestCachingExecChain {
|
|||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||
resp1.setHeader("Date", DateUtils.formatDate(new Date()));
|
||||
resp1.setHeader("Server", "MockOrigin/1.0");
|
||||
resp1.setHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
|
||||
resp1.setHeader(HttpHeaders.TRANSFER_ENCODING, HeaderElements.CHUNKED_ENCODING);
|
||||
|
||||
final AtomicInteger size = new AtomicInteger();
|
||||
final AtomicInteger maxlength = new AtomicInteger(Integer.MAX_VALUE);
|
||||
|
@ -380,7 +381,7 @@ public class TestCachingExec extends TestCachingExecChain {
|
|||
EasyMock.<HttpExecutionAware>isNull());
|
||||
EasyMock.expect(resp).andReturn(Proxies.enhanceResponse(resp1));
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
|
||||
replayMocks();
|
||||
final CloseableHttpResponse resp2 = impl.execute(route, req1, context, null);
|
||||
|
|
|
@ -48,15 +48,18 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.StatusLine;
|
||||
import org.apache.hc.core5.http.entity.EntityUtils;
|
||||
import org.apache.hc.core5.http.entity.InputStreamEntity;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.client.cache.CacheResponseStatus;
|
||||
|
@ -72,19 +75,16 @@ import org.apache.http.client.methods.HttpUriRequest;
|
|||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.impl.execchain.ClientExecChain;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.easymock.Capture;
|
||||
import org.easymock.IExpectationSetters;
|
||||
import org.easymock.EasyMock;
|
||||
import org.easymock.IExpectationSetters;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
@SuppressWarnings("boxing") // test code
|
||||
public abstract class TestCachingExecChain {
|
||||
|
||||
|
@ -142,7 +142,7 @@ public abstract class TestCachingExecChain {
|
|||
host = new HttpHost("foo.example.com", 80);
|
||||
route = new HttpRoute(host);
|
||||
request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/stuff",
|
||||
HttpVersion.HTTP_1_1));
|
||||
HttpVersion.HTTP_1_1), host);
|
||||
context = HttpCacheContext.create();
|
||||
context.setTargetHost(host);
|
||||
entry = HttpTestUtils.makeCacheEntry();
|
||||
|
@ -218,13 +218,13 @@ public abstract class TestCachingExecChain {
|
|||
public void testCacheableResponsesGoIntoCache() throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control", "max-age=3600");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
|
||||
replayMocks();
|
||||
impl.execute(route, req1, context, null);
|
||||
|
@ -238,7 +238,7 @@ public abstract class TestCachingExecChain {
|
|||
final Date now = new Date();
|
||||
final Date fiveSecondsAgo = new Date(now.getTime() - 5 * 1000L);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(now));
|
||||
resp1.setHeader("Cache-Control", "max-age=3600");
|
||||
|
@ -246,7 +246,7 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control", "no-cache");
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("ETag", "\"old-etag\"");
|
||||
|
@ -255,7 +255,7 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
|
||||
replayMocks();
|
||||
impl.execute(route, req1, context, null);
|
||||
|
@ -272,7 +272,7 @@ public abstract class TestCachingExecChain {
|
|||
final Date now = new Date();
|
||||
final Date fiveSecondsAgo = new Date(now.getTime() - 5 * 1000L);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(fiveSecondsAgo));
|
||||
resp1.setHeader("Cache-Control", "max-age=3600");
|
||||
|
@ -280,7 +280,7 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control", "max-age=0");
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("ETag", "\"new-etag\"");
|
||||
|
@ -289,7 +289,7 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
|
||||
replayMocks();
|
||||
impl.execute(route, req1, context, null);
|
||||
|
@ -332,7 +332,7 @@ public abstract class TestCachingExecChain {
|
|||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(new HeapResourceFactory(),
|
||||
mockStorage, configDefault), configDefault);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control", "no-cache");
|
||||
|
||||
|
@ -389,7 +389,7 @@ public abstract class TestCachingExecChain {
|
|||
public void testSetsModuleGeneratedResponseContextForCacheOptionsResponse() throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(new BasicHttpRequest("OPTIONS", "*",
|
||||
HttpVersion.HTTP_1_1));
|
||||
HttpVersion.HTTP_1_1), host);
|
||||
req.setHeader("Max-Forwards", "0");
|
||||
|
||||
impl.execute(route, req, context, null);
|
||||
|
@ -402,7 +402,7 @@ public abstract class TestCachingExecChain {
|
|||
throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req.setHeader("Range", "bytes=0-50");
|
||||
req.setHeader("If-Range", "W/\"weak-etag\"");
|
||||
|
||||
|
@ -416,7 +416,7 @@ public abstract class TestCachingExecChain {
|
|||
throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/",
|
||||
HttpVersion.HTTP_1_0));
|
||||
HttpVersion.HTTP_1_0), host);
|
||||
req.setHeader("Cache-Control", "no-cache");
|
||||
final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_NO_CONTENT, "No Content");
|
||||
|
@ -438,7 +438,7 @@ public abstract class TestCachingExecChain {
|
|||
public void testSetsCacheMissContextIfRequestNotServableFromCache() throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req.setHeader("Cache-Control", "no-cache");
|
||||
final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_NO_CONTENT, "No Content");
|
||||
|
@ -455,7 +455,7 @@ public abstract class TestCachingExecChain {
|
|||
public void testSetsViaHeaderOnResponseIfRequestNotServableFromCache() throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req.setHeader("Cache-Control", "no-cache");
|
||||
final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_NO_CONTENT, "No Content");
|
||||
|
@ -472,7 +472,7 @@ public abstract class TestCachingExecChain {
|
|||
public void testSetsViaHeaderOnResponseForCacheMiss() throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
resp1.setEntity(HttpTestUtils.makeBody(128));
|
||||
|
@ -493,9 +493,9 @@ public abstract class TestCachingExecChain {
|
|||
public void testSetsCacheHitContextIfRequestServedFromCache() throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
resp1.setEntity(HttpTestUtils.makeBody(128));
|
||||
|
@ -517,9 +517,9 @@ public abstract class TestCachingExecChain {
|
|||
public void testSetsViaHeaderOnResponseIfRequestServedFromCache() throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
resp1.setEntity(HttpTestUtils.makeBody(128));
|
||||
|
@ -543,9 +543,9 @@ public abstract class TestCachingExecChain {
|
|||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req2.addHeader("If-Modified-Since", DateUtils.formatDate(now));
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -573,10 +573,10 @@ public abstract class TestCachingExecChain {
|
|||
final Date inTenMinutes = new Date(now.getTime() + 600 * 1000L);
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req1.addHeader("If-Modified-Since", DateUtils.formatDate(oneHourAgo));
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req2.addHeader("If-Modified-Since", DateUtils.formatDate(oneHourAgo));
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
|
@ -609,9 +609,9 @@ public abstract class TestCachingExecChain {
|
|||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -644,9 +644,9 @@ public abstract class TestCachingExecChain {
|
|||
final Date tenSecondsAfter = new Date(now.getTime() + 10 * 1000L);
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -674,9 +674,9 @@ public abstract class TestCachingExecChain {
|
|||
public void testReturns304ForIfNoneMatchHeaderIfRequestServedFromCache() throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req2.addHeader("If-None-Match", "*");
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -700,9 +700,9 @@ public abstract class TestCachingExecChain {
|
|||
public void testReturns200ForIfNoneMatchHeaderFails() throws Exception {
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -734,9 +734,9 @@ public abstract class TestCachingExecChain {
|
|||
final Date now = new Date();
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -766,9 +766,9 @@ public abstract class TestCachingExecChain {
|
|||
final Date now = new Date();
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req2.addHeader("If-None-Match", "\"abc\"");
|
||||
req2.addHeader("If-Modified-Since", DateUtils.formatDate(now));
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
|
@ -798,10 +798,10 @@ public abstract class TestCachingExecChain {
|
|||
.setSharedCache(true).build());
|
||||
final Date now = new Date();
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpOptions(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req1.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req2.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_NO_CONTENT, "No Content");
|
||||
|
@ -836,9 +836,9 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -873,9 +873,9 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -910,9 +910,9 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -940,9 +940,9 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -969,9 +969,9 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -999,9 +999,9 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -1036,9 +1036,9 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -1076,9 +1076,9 @@ public abstract class TestCachingExecChain {
|
|||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -1115,9 +1115,9 @@ public abstract class TestCachingExecChain {
|
|||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -1155,7 +1155,7 @@ public abstract class TestCachingExecChain {
|
|||
final Date now = new Date();
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
req1.addHeader("Accept-Encoding", "gzip");
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
|
@ -1168,11 +1168,11 @@ public abstract class TestCachingExecChain {
|
|||
resp1.setHeader("Cache-Control", "public, max-age=3600");
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
req2.addHeader("Accept-Encoding", "deflate");
|
||||
|
||||
final HttpRequestWrapper req2Server = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
req2Server.addHeader("Accept-Encoding", "deflate");
|
||||
req2Server.addHeader("If-None-Match", "\"gzip_etag\"");
|
||||
|
||||
|
@ -1186,11 +1186,11 @@ public abstract class TestCachingExecChain {
|
|||
resp2.setHeader("Cache-Control", "public, max-age=3600");
|
||||
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
req3.addHeader("Accept-Encoding", "gzip,deflate");
|
||||
|
||||
final HttpRequestWrapper req3Server = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
req3Server.addHeader("Accept-Encoding", "gzip,deflate");
|
||||
req3Server.addHeader("If-None-Match", "\"gzip_etag\",\"deflate_etag\"");
|
||||
|
||||
|
@ -1226,7 +1226,7 @@ public abstract class TestCachingExecChain {
|
|||
final Date now = new Date();
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
req1.addHeader("Accept-Encoding", "gzip");
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
|
@ -1239,11 +1239,11 @@ public abstract class TestCachingExecChain {
|
|||
resp1.setHeader("Cache-Control", "public, max-age=3600");
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
req2.addHeader("Accept-Encoding", "deflate");
|
||||
|
||||
final HttpRequestWrapper req2Server = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
req2Server.addHeader("Accept-Encoding", "deflate");
|
||||
req2Server.addHeader("If-None-Match", "\"gzip_etag\"");
|
||||
|
||||
|
@ -1257,12 +1257,12 @@ public abstract class TestCachingExecChain {
|
|||
resp2.setHeader("Cache-Control", "public, max-age=3600");
|
||||
|
||||
final HttpRequestWrapper req4 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
req4.addHeader("Accept-Encoding", "gzip,identity");
|
||||
req4.addHeader("If-None-Match", "\"gzip_etag\"");
|
||||
|
||||
final HttpRequestWrapper req4Server = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
req4Server.addHeader("Accept-Encoding", "gzip,identity");
|
||||
req4Server.addHeader("If-None-Match", "\"gzip_etag\"");
|
||||
|
||||
|
@ -1296,7 +1296,7 @@ public abstract class TestCachingExecChain {
|
|||
final Date now = new Date();
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com"));
|
||||
"http://foo.example.com"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
|
||||
"OK");
|
||||
|
@ -1502,7 +1502,6 @@ public abstract class TestCachingExecChain {
|
|||
ctx.setTargetHost(host);
|
||||
impl.execute(route, request, context, null);
|
||||
impl.execute(route, request, ctx, null);
|
||||
assertTrue(ctx.isRequestSent());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1527,7 +1526,7 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req1.addHeader("If-None-Match", "\"etag\"");
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
|
@ -1554,11 +1553,11 @@ public abstract class TestCachingExecChain {
|
|||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req1.addHeader("If-None-Match", "etag");
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req2.addHeader("If-None-Match", "etag");
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
|
@ -1594,11 +1593,11 @@ public abstract class TestCachingExecChain {
|
|||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req1.addHeader("If-None-Match", "etag");
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req2.addHeader("If-None-Match", "etag");
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
|
@ -1637,11 +1636,11 @@ public abstract class TestCachingExecChain {
|
|||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
req1.addHeader("If-None-Match", "etag");
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet(
|
||||
"http://foo.example.com/"));
|
||||
"http://foo.example.com/"), host);
|
||||
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_NOT_MODIFIED, "Not modified");
|
||||
|
|
|
@ -32,8 +32,8 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.apache.hc.core5.http.entity.EntityUtils;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -30,17 +30,18 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolException;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
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.HttpVersion;
|
||||
import org.apache.hc.core5.http.ProtocolException;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -48,14 +49,16 @@ import org.junit.Test;
|
|||
public class TestConditionalRequestBuilder {
|
||||
|
||||
private ConditionalRequestBuilder impl;
|
||||
private HttpHost host;
|
||||
private HttpRequestWrapper request;
|
||||
private HttpCacheEntry entry;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
impl = new ConditionalRequestBuilder();
|
||||
host = new HttpHost("foo.example.com", 80);
|
||||
request = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
entry = HttpTestUtils.makeCacheEntry();
|
||||
}
|
||||
|
||||
|
@ -67,7 +70,7 @@ public class TestConditionalRequestBuilder {
|
|||
|
||||
final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
|
||||
basicRequest.addHeader("Accept-Encoding", "gzip");
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest, host);
|
||||
|
||||
final Header[] headers = new Header[] {
|
||||
new BasicHeader("Date", DateUtils.formatDate(new Date())),
|
||||
|
@ -105,7 +108,7 @@ public class TestConditionalRequestBuilder {
|
|||
new BasicHeader("ETag", etag)
|
||||
};
|
||||
final HttpRequest basicRequest = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest, host);
|
||||
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
|
||||
final HttpRequest result = impl.buildConditionalRequest(requestWrapper, cacheEntry);
|
||||
Assert.assertEquals(lmDate,
|
||||
|
@ -122,7 +125,7 @@ public class TestConditionalRequestBuilder {
|
|||
|
||||
final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
|
||||
basicRequest.addHeader("Accept-Encoding", "gzip");
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest, host);
|
||||
|
||||
final Header[] headers = new Header[] {
|
||||
new BasicHeader("Date", DateUtils.formatDate(new Date())),
|
||||
|
@ -152,7 +155,7 @@ public class TestConditionalRequestBuilder {
|
|||
@Test
|
||||
public void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() throws Exception {
|
||||
final HttpRequest basicRequest = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest, host);
|
||||
final Date now = new Date();
|
||||
final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
|
@ -181,7 +184,7 @@ public class TestConditionalRequestBuilder {
|
|||
@Test
|
||||
public void testCacheEntryWithProxyRevalidateDoesEndToEndRevalidation() throws Exception {
|
||||
final HttpRequest basicRequest = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest, host);
|
||||
final Date now = new Date();
|
||||
final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
|
@ -218,7 +221,7 @@ public class TestConditionalRequestBuilder {
|
|||
public void testBuildUnconditionalRequestUsesRequestUri()
|
||||
throws Exception {
|
||||
final String uri = "/theURI";
|
||||
request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1));
|
||||
request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1), host);
|
||||
final HttpRequest result = impl.buildUnconditionalRequest(request, entry);
|
||||
Assert.assertEquals(uri, result.getRequestLine().getUri());
|
||||
}
|
||||
|
|
|
@ -30,18 +30,18 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.impl.execchain.ClientExecChain;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TestExponentialBackingOffSchedulingStrategy {
|
||||
|
||||
private ScheduledExecutorService mockExecutor;
|
||||
|
@ -159,8 +159,9 @@ public class TestExponentialBackingOffSchedulingStrategy {
|
|||
final ClientExecChain clientExecChain = mock(ClientExecChain.class);
|
||||
final CachingExec cachingHttpClient = new CachingExec(clientExecChain);
|
||||
final AsynchronousValidator mockValidator = new AsynchronousValidator(impl);
|
||||
final HttpRoute httpRoute = new HttpRoute(new HttpHost("foo.example.com", 80));
|
||||
final HttpRequestWrapper httpRequestWrapper = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/"));
|
||||
final HttpHost host = new HttpHost("foo.example.com", 80);
|
||||
final HttpRoute httpRoute = new HttpRoute(host);
|
||||
final HttpRequestWrapper httpRequestWrapper = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/"), host);
|
||||
final HttpClientContext httpClientContext = new HttpClientContext();
|
||||
return new AsynchronousValidationRequest(mockValidator, cachingHttpClient, httpRoute, httpRequestWrapper,
|
||||
httpClientContext, null, null, "identifier", errorCount);
|
||||
|
|
|
@ -39,15 +39,15 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.StatusLine;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicStatusLine;
|
||||
import org.apache.http.client.cache.HeaderConstants;
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.HttpCacheEntrySerializer;
|
||||
import org.apache.http.client.cache.Resource;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -36,9 +36,10 @@ import static org.mockito.Mockito.when;
|
|||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.cache.HttpCacheStorage;
|
||||
import org.apache.http.client.cache.ResourceFactory;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
|
@ -48,7 +49,6 @@ import org.apache.http.client.protocol.HttpClientContext;
|
|||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.impl.execchain.ClientExecChain;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -95,7 +95,7 @@ public class TestHttpCacheJiraNumber1147 {
|
|||
final HttpCacheStorage httpCacheStorage = new ManagedHttpCacheStorage(cacheConfig);
|
||||
|
||||
final ClientExecChain backend = mock(ClientExecChain.class);
|
||||
final HttpRequestWrapper get = HttpRequestWrapper.wrap(new HttpGet("http://somehost/"));
|
||||
final HttpRequestWrapper get = HttpRequestWrapper.wrap(new HttpGet("http://somehost/"), new HttpHost("somehost"));
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final HttpHost target = new HttpHost("somehost", 80);
|
||||
final HttpRoute route = new HttpRoute(target);
|
||||
|
|
|
@ -28,11 +28,11 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
public class TestImmediateSchedulingStrategy {
|
||||
|
||||
private ExecutorService mockExecutor;
|
||||
|
|
|
@ -29,12 +29,12 @@ package org.apache.http.impl.client.cache;
|
|||
import java.net.SocketTimeoutException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class TestProtocolAllowedBehavior extends AbstractProtocolTest {
|
|||
public void testNonSharedCacheReturnsStaleResponseWhenRevalidationFailsForProxyRevalidate()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET","/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET","/", HttpVersion.HTTP_1_1), host);
|
||||
final Date now = new Date();
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
originResponse.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
|
||||
|
@ -59,7 +59,7 @@ public class TestProtocolAllowedBehavior extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequest().andReturn(originResponse);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET","/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET","/", HttpVersion.HTTP_1_1), host);
|
||||
|
||||
backendExpectsAnyRequest().andThrow(new SocketTimeoutException());
|
||||
|
||||
|
@ -76,13 +76,13 @@ public class TestProtocolAllowedBehavior extends AbstractProtocolTest {
|
|||
public void testNonSharedCacheMayCacheResponsesWithCacheControlPrivate()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET","/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET","/", HttpVersion.HTTP_1_1), host);
|
||||
originResponse.setHeader("Cache-Control","private,max-age=3600");
|
||||
|
||||
backendExpectsAnyRequest().andReturn(originResponse);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET","/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET","/", HttpVersion.HTTP_1_1), host);
|
||||
|
||||
replayMocks();
|
||||
behaveAsNonSharedCache();
|
||||
|
|
|
@ -29,26 +29,24 @@ package org.apache.http.impl.client.cache;
|
|||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.cache.HttpCacheContext;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.impl.execchain.ClientExecChain;
|
||||
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.easymock.Capture;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Assert;
|
||||
|
@ -73,7 +71,7 @@ import org.junit.Test;
|
|||
@SuppressWarnings("boxing") // test code
|
||||
public class TestProtocolDeviations {
|
||||
|
||||
private static ProtocolVersion HTTP_1_1 = new ProtocolVersion("HTTP", 1, 1);
|
||||
private static final ProtocolVersion HTTP_1_1 = new ProtocolVersion("HTTP", 1, 1);
|
||||
|
||||
private static final int MAX_BYTES = 1024;
|
||||
private static final int MAX_ENTRIES = 100;
|
||||
|
@ -174,13 +172,13 @@ public class TestProtocolDeviations {
|
|||
*/
|
||||
@Ignore
|
||||
public void testHTTP1_1RequestsWithBodiesOfKnownLengthMustHaveContentLength() throws Exception {
|
||||
final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
|
||||
final BasicHttpRequest post = new BasicHttpRequest("POST", "/",
|
||||
HTTP_1_1);
|
||||
post.setEntity(mockEntity);
|
||||
|
||||
replayMocks();
|
||||
|
||||
final HttpResponse response = impl.execute(route, HttpRequestWrapper.wrap(post), context, null);
|
||||
final HttpResponse response = impl.execute(route, HttpRequestWrapper.wrap(post, host), context, null);
|
||||
|
||||
verifyMocks();
|
||||
|
||||
|
@ -215,7 +213,7 @@ public class TestProtocolDeviations {
|
|||
@Ignore
|
||||
public void testHTTP1_1RequestsWithUnknownBodyLengthAreRejectedOrHaveContentLengthAdded()
|
||||
throws Exception {
|
||||
final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
|
||||
final BasicHttpRequest post = new BasicHttpRequest("POST", "/",
|
||||
HTTP_1_1);
|
||||
|
||||
final byte[] bytes = new byte[128];
|
||||
|
@ -238,7 +236,7 @@ public class TestProtocolDeviations {
|
|||
replayMocks();
|
||||
EasyMock.replay(mockBody);
|
||||
|
||||
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(post), context, null);
|
||||
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(post, host), context, null);
|
||||
|
||||
verifyMocks();
|
||||
EasyMock.verify(mockBody);
|
||||
|
@ -263,7 +261,7 @@ public class TestProtocolDeviations {
|
|||
*/
|
||||
@Test
|
||||
public void testOPTIONSRequestsWithBodiesAndNoContentTypeHaveOneSupplied() throws Exception {
|
||||
final BasicHttpEntityEnclosingRequest options = new BasicHttpEntityEnclosingRequest("OPTIONS",
|
||||
final BasicHttpRequest options = new BasicHttpRequest("OPTIONS",
|
||||
"/", HTTP_1_1);
|
||||
options.setEntity(body);
|
||||
options.setHeader("Content-Length", "1");
|
||||
|
@ -277,13 +275,11 @@ public class TestProtocolDeviations {
|
|||
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
|
||||
replayMocks();
|
||||
|
||||
impl.execute(route, HttpRequestWrapper.wrap(options), context, null);
|
||||
impl.execute(route, HttpRequestWrapper.wrap(options, host), context, null);
|
||||
|
||||
verifyMocks();
|
||||
|
||||
final HttpRequest forwarded = reqCap.getValue();
|
||||
Assert.assertTrue(forwarded instanceof HttpEntityEnclosingRequest);
|
||||
final HttpEntityEnclosingRequest reqWithBody = (HttpEntityEnclosingRequest) forwarded;
|
||||
final HttpRequest reqWithBody = reqCap.getValue();
|
||||
final HttpEntity reqBody = reqWithBody.getEntity();
|
||||
Assert.assertNotNull(reqBody);
|
||||
Assert.assertNotNull(reqBody.getContentType());
|
||||
|
@ -319,7 +315,7 @@ public class TestProtocolDeviations {
|
|||
|
||||
replayMocks();
|
||||
try {
|
||||
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
|
||||
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request, host), context, null);
|
||||
Assert.assertTrue(HttpStatus.SC_PARTIAL_CONTENT != result.getStatusLine()
|
||||
.getStatusCode());
|
||||
} catch (final ClientProtocolException acceptableBehavior) {
|
||||
|
@ -347,7 +343,7 @@ public class TestProtocolDeviations {
|
|||
EasyMock.isA(HttpClientContext.class),
|
||||
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
|
||||
replayMocks();
|
||||
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
|
||||
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request, host), context, null);
|
||||
verifyMocks();
|
||||
Assert.assertSame(originResponse, result);
|
||||
}
|
||||
|
@ -370,7 +366,7 @@ public class TestProtocolDeviations {
|
|||
EasyMock.isA(HttpClientContext.class),
|
||||
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
|
||||
replayMocks();
|
||||
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
|
||||
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request, host), context, null);
|
||||
verifyMocks();
|
||||
Assert.assertSame(originResponse, result);
|
||||
}
|
||||
|
@ -394,7 +390,7 @@ public class TestProtocolDeviations {
|
|||
EasyMock.isA(HttpClientContext.class),
|
||||
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
|
||||
replayMocks();
|
||||
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
|
||||
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request, host), context, null);
|
||||
verifyMocks();
|
||||
Assert.assertSame(originResponse, result);
|
||||
}
|
||||
|
|
|
@ -37,23 +37,20 @@ import java.util.Arrays;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HeaderElement;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.easymock.Capture;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Before;
|
||||
|
@ -114,9 +111,8 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
*/
|
||||
private void cacheGenerated304ForValidatorShouldNotContainEntityHeader(
|
||||
final String headerName, final String headerValue, final String validatorHeader,
|
||||
final String validator, final String conditionalHeader) throws Exception,
|
||||
IOException {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final String validator, final String conditionalHeader) throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control","max-age=3600");
|
||||
resp1.setHeader(validatorHeader, validator);
|
||||
|
@ -124,7 +120,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader(conditionalHeader, validator);
|
||||
|
||||
replayMocks();
|
||||
|
@ -138,15 +134,13 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
}
|
||||
|
||||
private void cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
||||
final String headerName, final String headerValue) throws Exception,
|
||||
IOException {
|
||||
final String headerName, final String headerValue) throws Exception {
|
||||
cacheGenerated304ForValidatorShouldNotContainEntityHeader(headerName,
|
||||
headerValue, "ETag", "\"etag\"", "If-None-Match");
|
||||
}
|
||||
|
||||
private void cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
||||
final String headerName, final String headerValue) throws Exception,
|
||||
IOException {
|
||||
final String headerName, final String headerValue) throws Exception {
|
||||
cacheGenerated304ForValidatorShouldNotContainEntityHeader(headerName,
|
||||
headerValue, "Last-Modified", DateUtils.formatDate(twoMinutesAgo),
|
||||
"If-Modified-Since");
|
||||
|
@ -224,8 +218,8 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
private void cacheGenerated304ForStrongValidatorShouldNotContainContentRange(
|
||||
final String validatorHeader, final String validator, final String conditionalHeader)
|
||||
throws Exception, IOException, ClientProtocolException {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req1.setHeader("Range","bytes=0-127");
|
||||
final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_PARTIAL_CONTENT, "Partial Content");
|
||||
resp1.setHeader("Cache-Control","max-age=3600");
|
||||
|
@ -234,7 +228,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("If-Range", validator);
|
||||
req2.setHeader("Range","bytes=0-127");
|
||||
req2.setHeader(conditionalHeader, validator);
|
||||
|
@ -309,9 +303,8 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
}
|
||||
|
||||
private void shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
||||
final String entityHeader, final String entityHeaderValue) throws Exception,
|
||||
IOException {
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final String entityHeader, final String entityHeaderValue) throws Exception {
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req.setHeader("If-None-Match", "\"etag\"");
|
||||
|
||||
final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not Modified");
|
||||
|
@ -373,7 +366,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void shouldStripContentRangeFromOrigin304ResponseToStringValidation()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req.setHeader("If-Range","\"etag\"");
|
||||
req.setHeader("Range","bytes=0-127");
|
||||
|
||||
|
@ -405,7 +398,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
*/
|
||||
private HttpRequestWrapper requestToPopulateStaleCacheEntry() throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
|
||||
resp1.setHeader("Cache-Control","public,max-age=5");
|
||||
|
@ -416,7 +409,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
}
|
||||
|
||||
private void testDoesNotReturnStaleResponseOnError(final HttpRequestWrapper req2)
|
||||
throws Exception, IOException {
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = requestToPopulateStaleCacheEntry();
|
||||
|
||||
backendExpectsAnyRequest().andThrow(new IOException());
|
||||
|
@ -439,7 +432,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFirstHandOneWithCacheControl()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req.setHeader("Cache-Control","no-cache");
|
||||
testDoesNotReturnStaleResponseOnError(req);
|
||||
}
|
||||
|
@ -448,7 +441,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFirstHandOneWithPragma()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req.setHeader("Pragma","no-cache");
|
||||
testDoesNotReturnStaleResponseOnError(req);
|
||||
}
|
||||
|
@ -457,7 +450,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMaxAge()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req.setHeader("Cache-Control","max-age=0");
|
||||
testDoesNotReturnStaleResponseOnError(req);
|
||||
}
|
||||
|
@ -466,7 +459,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void testDoesNotReturnStaleResponseIfClientExplicitlySpecifiesLargerMaxAge()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req.setHeader("Cache-Control","max-age=20");
|
||||
testDoesNotReturnStaleResponseOnError(req);
|
||||
}
|
||||
|
@ -476,7 +469,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMinFresh()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req.setHeader("Cache-Control","min-fresh=2");
|
||||
|
||||
testDoesNotReturnStaleResponseOnError(req);
|
||||
|
@ -486,7 +479,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMaxStale()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req.setHeader("Cache-Control","max-stale=2");
|
||||
|
||||
testDoesNotReturnStaleResponseOnError(req);
|
||||
|
@ -497,7 +490,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
throws Exception {
|
||||
final HttpRequestWrapper req1 = requestToPopulateStaleCacheEntry();
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req2.setHeader("Cache-Control","max-stale=20");
|
||||
|
||||
backendExpectsAnyRequest().andThrow(new IOException()).times(0,1);
|
||||
|
@ -548,7 +541,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void testReturnsCachedResponsesAppropriatelyWhenNoOriginCommunication()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control", "public, max-age=5");
|
||||
resp1.setHeader("ETag","\"etag\"");
|
||||
|
@ -557,7 +550,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
|
||||
backendExpectsAnyRequest().andThrow(new IOException()).anyTimes();
|
||||
|
||||
|
@ -680,11 +673,11 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void testDoesNotModifyContentLengthOnRequests()
|
||||
throws Exception {
|
||||
final HttpEntityEnclosingRequest post =
|
||||
new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
|
||||
final HttpRequest post =
|
||||
new BasicHttpRequest("POST", "/", HttpVersion.HTTP_1_1);
|
||||
post.setEntity(HttpTestUtils.makeBody(128));
|
||||
post.setHeader("Content-Length","128");
|
||||
request = HttpRequestWrapper.wrap(post);
|
||||
request = HttpRequestWrapper.wrap(post, host);
|
||||
testDoesNotModifyHeaderOnRequests("Content-Length");
|
||||
}
|
||||
|
||||
|
@ -699,12 +692,12 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void testDoesNotModifyContentMD5OnRequests()
|
||||
throws Exception {
|
||||
final HttpEntityEnclosingRequest post =
|
||||
new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
|
||||
final HttpRequest post =
|
||||
new BasicHttpRequest("POST", "/", HttpVersion.HTTP_1_1);
|
||||
post.setEntity(HttpTestUtils.makeBody(128));
|
||||
post.setHeader("Content-Length","128");
|
||||
post.setHeader("Content-MD5","Q2hlY2sgSW50ZWdyaXR5IQ==");
|
||||
request = HttpRequestWrapper.wrap(post);
|
||||
request = HttpRequestWrapper.wrap(post, host);
|
||||
testDoesNotModifyHeaderOnRequests("Content-MD5");
|
||||
}
|
||||
|
||||
|
@ -719,12 +712,12 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void testDoesNotModifyContentRangeOnRequests()
|
||||
throws Exception {
|
||||
final HttpEntityEnclosingRequest put =
|
||||
new BasicHttpEntityEnclosingRequest("PUT", "/", HttpVersion.HTTP_1_1);
|
||||
final HttpRequest put =
|
||||
new BasicHttpRequest("PUT", "/", HttpVersion.HTTP_1_1);
|
||||
put.setEntity(HttpTestUtils.makeBody(128));
|
||||
put.setHeader("Content-Length","128");
|
||||
put.setHeader("Content-Range","bytes 0-127/256");
|
||||
request = HttpRequestWrapper.wrap(put);
|
||||
request = HttpRequestWrapper.wrap(put, host);
|
||||
testDoesNotModifyHeaderOnRequests("Content-Range");
|
||||
}
|
||||
|
||||
|
@ -742,12 +735,12 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void testDoesNotModifyContentTypeOnRequests()
|
||||
throws Exception {
|
||||
final HttpEntityEnclosingRequest post =
|
||||
new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
|
||||
final HttpRequest post =
|
||||
new BasicHttpRequest("POST", "/", HttpVersion.HTTP_1_1);
|
||||
post.setEntity(HttpTestUtils.makeBody(128));
|
||||
post.setHeader("Content-Length","128");
|
||||
post.setHeader("Content-Type","application/octet-stream");
|
||||
request = HttpRequestWrapper.wrap(post);
|
||||
request = HttpRequestWrapper.wrap(post, host);
|
||||
testDoesNotModifyHeaderOnRequests("Content-Type");
|
||||
}
|
||||
|
||||
|
@ -796,8 +789,8 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void testDoesNotModifyIfMatchOnRequests()
|
||||
throws Exception {
|
||||
request = HttpRequestWrapper.wrap(HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("DELETE", "/", HttpVersion.HTTP_1_1)));
|
||||
request = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("DELETE", "/", HttpVersion.HTTP_1_1), host);
|
||||
request.setHeader("If-Match", "\"etag\"");
|
||||
testDoesNotModifyHeaderOnRequests("If-Match");
|
||||
}
|
||||
|
@ -827,8 +820,8 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void testDoesNotModifyIfUnmodifiedSinceOnRequests()
|
||||
throws Exception {
|
||||
request = HttpRequestWrapper.wrap(HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("DELETE", "/", HttpVersion.HTTP_1_1)));
|
||||
request = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("DELETE", "/", HttpVersion.HTTP_1_1), host);
|
||||
request.setHeader("If-Unmodified-Since", DateUtils.formatDate(new Date()));
|
||||
testDoesNotModifyHeaderOnRequests("If-Unmodified-Since");
|
||||
}
|
||||
|
@ -923,7 +916,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
final String lmDate = DateUtils.formatDate(twentySecondsAgo);
|
||||
|
||||
final HttpRequestWrapper req1 =
|
||||
HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
|
||||
resp1.setHeader("Last-Modified", lmDate);
|
||||
|
@ -933,7 +926,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
|
||||
EasyMock.expect(
|
||||
|
@ -971,7 +964,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
final String etag = "\"etag\"";
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
|
||||
resp1.setHeader("Last-Modified", lmDate);
|
||||
|
@ -982,7 +975,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
|
||||
EasyMock.expect(
|
||||
|
@ -1022,7 +1015,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
final Date oneSecondFromNow = new Date(now.getTime() + 1 * 1000L);
|
||||
final Date twoSecondsFromNow = new Date(now.getTime() + 2 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("ETag","\"etag\"");
|
||||
resp1.setHeader("Date", DateUtils.formatDate(now));
|
||||
|
@ -1032,9 +1025,9 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpRequestWrapper revalidate = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/",HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/",HttpVersion.HTTP_1_1), host);
|
||||
revalidate.setHeader("If-None-Match","\"etag\"");
|
||||
|
||||
final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
|
@ -1078,7 +1071,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
throws Exception {
|
||||
final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("ETag","\"etag\"");
|
||||
resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
|
||||
|
@ -1087,7 +1080,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_NOT_MODIFIED, "Not Modified");
|
||||
resp2.setHeader("ETag","\"etag\"");
|
||||
|
@ -1152,7 +1145,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void testSendsAllVariantEtagsInConditionalRequest()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1), host);
|
||||
req1.setHeader("User-Agent","agent1");
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control","max-age=3600");
|
||||
|
@ -1162,7 +1155,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1), host);
|
||||
req2.setHeader("User-Agent","agent2");
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("Cache-Control","max-age=3600");
|
||||
|
@ -1173,7 +1166,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1), host);
|
||||
req3.setHeader("User-Agent","agent3");
|
||||
final HttpResponse resp3 = HttpTestUtils.make200Response();
|
||||
|
||||
|
@ -1219,7 +1212,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
throws Exception {
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req1.setHeader("User-Agent", "agent1");
|
||||
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
|
@ -1232,7 +1225,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req2.setHeader("User-Agent", "agent2");
|
||||
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
|
@ -1244,7 +1237,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req3.setHeader("User-Agent", "agent3");
|
||||
|
||||
final HttpResponse resp3 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not Modified");
|
||||
|
@ -1254,7 +1247,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp3);
|
||||
|
||||
final HttpRequestWrapper req4 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req4.setHeader("User-Agent", "agent1");
|
||||
|
||||
replayMocks();
|
||||
|
@ -1275,7 +1268,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
throws Exception {
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req1.setHeader("User-Agent", "agent1");
|
||||
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
|
@ -1287,7 +1280,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req2.setHeader("User-Agent", "agent2");
|
||||
|
||||
final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not Modified");
|
||||
|
@ -1297,7 +1290,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req3.setHeader("User-Agent", "agent2");
|
||||
|
||||
replayMocks();
|
||||
|
@ -1317,7 +1310,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void variantNegotiationsDoNotIncludeEtagsForPartialResponses()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req1.setHeader("User-Agent", "agent1");
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control", "max-age=3600");
|
||||
|
@ -1326,7 +1319,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("User-Agent", "agent2");
|
||||
req2.setHeader("Range", "bytes=0-49");
|
||||
final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
|
@ -1341,7 +1334,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req3.setHeader("User-Agent", "agent3");
|
||||
|
||||
final HttpResponse resp3 = HttpTestUtils.make200Response();
|
||||
|
@ -1385,7 +1378,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void cachedEntryShouldNotBeUsedIfMoreRecentMentionInContentLocation()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new HttpGet("http://foo.example.com/"));
|
||||
new HttpGet("http://foo.example.com/"), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control","max-age=3600");
|
||||
resp1.setHeader("ETag", "\"old-etag\"");
|
||||
|
@ -1394,7 +1387,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new HttpPost("http://foo.example.com/bar"));
|
||||
new HttpPost("http://foo.example.com/bar"), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("ETag", "\"new-etag\"");
|
||||
resp2.setHeader("Date", DateUtils.formatDate(now));
|
||||
|
@ -1403,7 +1396,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(
|
||||
new HttpGet("http://foo.example.com"));
|
||||
new HttpGet("http://foo.example.com"), host);
|
||||
final HttpResponse resp3 = HttpTestUtils.make200Response();
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp3);
|
||||
|
@ -1426,7 +1419,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void responseToGetWithQueryFrom1_0OriginAndNoExpiresIsNotCached()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new HttpGet("http://foo.example.com/bar?baz=quux"));
|
||||
new HttpGet("http://foo.example.com/bar?baz=quux"), host);
|
||||
final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, "OK");
|
||||
resp2.setEntity(HttpTestUtils.makeBody(200));
|
||||
resp2.setHeader("Content-Length","200");
|
||||
|
@ -1443,7 +1436,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void responseToGetWithQueryFrom1_0OriginVia1_1ProxyAndNoExpiresIsNotCached()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new HttpGet("http://foo.example.com/bar?baz=quux"));
|
||||
new HttpGet("http://foo.example.com/bar?baz=quux"), host);
|
||||
final HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, "OK");
|
||||
resp2.setEntity(HttpTestUtils.makeBody(200));
|
||||
resp2.setHeader("Content-Length","200");
|
||||
|
@ -1468,21 +1461,21 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void shouldInvalidateNonvariantCacheEntryForUnknownMethod()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control","max-age=3600");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("FROB", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("FROB", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("Cache-Control","max-age=3600");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp3 = HttpTestUtils.make200Response();
|
||||
resp3.setHeader("ETag", "\"etag\"");
|
||||
|
||||
|
@ -1501,7 +1494,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void shouldInvalidateAllVariantsForUnknownMethod()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req1.setHeader("User-Agent", "agent1");
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control","max-age=3600");
|
||||
|
@ -1510,7 +1503,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req2.setHeader("User-Agent", "agent2");
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("Cache-Control","max-age=3600");
|
||||
|
@ -1519,7 +1512,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("FROB", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("FROB", "/", HttpVersion.HTTP_1_1), host);
|
||||
req3.setHeader("User-Agent", "agent3");
|
||||
final HttpResponse resp3 = HttpTestUtils.make200Response();
|
||||
resp3.setHeader("Cache-Control","max-age=3600");
|
||||
|
@ -1527,7 +1520,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp3);
|
||||
|
||||
final HttpRequestWrapper req4 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req4.setHeader("User-Agent", "agent1");
|
||||
final HttpResponse resp4 = HttpTestUtils.make200Response();
|
||||
resp4.setHeader("ETag", "\"etag1\"");
|
||||
|
@ -1535,7 +1528,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp4);
|
||||
|
||||
final HttpRequestWrapper req5 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req5.setHeader("User-Agent", "agent2");
|
||||
final HttpResponse resp5 = HttpTestUtils.make200Response();
|
||||
resp5.setHeader("ETag", "\"etag2\"");
|
||||
|
@ -1564,7 +1557,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void cacheShouldUpdateWithNewCacheableResponse()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
|
||||
resp1.setHeader("Cache-Control", "max-age=3600");
|
||||
|
@ -1572,7 +1565,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control", "max-age=0");
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("Date", DateUtils.formatDate(now));
|
||||
|
@ -1581,7 +1574,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
|
||||
replayMocks();
|
||||
impl.execute(route, req1, context, null);
|
||||
|
@ -1606,7 +1599,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void expiresEqualToDateWithNoCacheControlIsNotCacheable()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(now));
|
||||
resp1.setHeader("Expires", DateUtils.formatDate(now));
|
||||
|
@ -1614,7 +1607,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control", "max-stale=1000");
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("ETag", "\"etag2\"");
|
||||
|
@ -1632,7 +1625,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void expiresPriorToDateWithNoCacheControlIsNotCacheable()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(now));
|
||||
resp1.setHeader("Expires", DateUtils.formatDate(tenSecondsAgo));
|
||||
|
@ -1640,7 +1633,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control", "max-stale=1000");
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("ETag", "\"etag2\"");
|
||||
|
@ -1664,7 +1657,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void otherFreshnessRequestDirectivesNotAllowedWithNoCache()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req1.setHeader("Cache-Control", "min-fresh=10, no-cache");
|
||||
req1.addHeader("Cache-Control", "max-stale=0, max-age=0");
|
||||
|
||||
|
@ -1713,7 +1706,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void cacheMissResultsIn504WithOnlyIfCached()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req.setHeader("Cache-Control", "only-if-cached");
|
||||
|
||||
replayMocks();
|
||||
|
@ -1727,13 +1720,13 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void cacheHitOkWithOnlyIfCached()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control","max-age=3600");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control", "only-if-cached");
|
||||
|
||||
replayMocks();
|
||||
|
@ -1747,14 +1740,14 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void returns504ForStaleEntryWithOnlyIfCached()
|
||||
throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
|
||||
resp1.setHeader("Cache-Control","max-age=5");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control", "only-if-cached");
|
||||
|
||||
replayMocks();
|
||||
|
@ -1770,14 +1763,14 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
public void returnsStaleCacheEntryWithOnlyIfCachedAndMaxStale()
|
||||
throws Exception {
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
|
||||
resp1.setHeader("Cache-Control","max-age=5");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control", "max-stale=20, only-if-cached");
|
||||
|
||||
replayMocks();
|
||||
|
@ -1790,7 +1783,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
@Test
|
||||
public void issues304EvenWithWeakETag() throws Exception {
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
|
||||
resp1.setHeader("Cache-Control", "max-age=300");
|
||||
|
@ -1798,7 +1791,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
|
|||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("If-None-Match","W/\"weak-sauce\"");
|
||||
|
||||
replayMocks();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -33,15 +33,15 @@ import static org.junit.Assert.assertTrue;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.entity.InputStreamEntity;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -70,13 +70,13 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
public void testStaleIfErrorInResponseIsTrueReturnsStaleEntryWithWarning()
|
||||
throws Exception{
|
||||
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||
"public, max-age=5, stale-if-error=60");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
@ -93,13 +93,13 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
public void testConsumesErrorResponseWhenServingStale()
|
||||
throws Exception{
|
||||
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||
"public, max-age=5, stale-if-error=60");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
final byte[] body101 = HttpTestUtils.getRandomBytes(101);
|
||||
final ByteArrayInputStream buf = new ByteArrayInputStream(body101);
|
||||
|
@ -121,13 +121,13 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
public void testStaleIfErrorInResponseYieldsToMustRevalidate()
|
||||
throws Exception{
|
||||
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||
"public, max-age=5, stale-if-error=60, must-revalidate");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
@ -145,13 +145,13 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
throws Exception{
|
||||
assertTrue(config.isSharedCache());
|
||||
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||
"public, max-age=5, stale-if-error=60, proxy-revalidate");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
@ -172,13 +172,13 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
impl = new CachingExec(mockBackend, new BasicHttpCache(configUnshared), configUnshared);
|
||||
|
||||
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||
"public, max-age=5, stale-if-error=60, proxy-revalidate");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
@ -195,13 +195,13 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
public void testStaleIfErrorInResponseYieldsToExplicitFreshnessRequest()
|
||||
throws Exception{
|
||||
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||
"public, max-age=5, stale-if-error=60");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control","min-fresh=2");
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
|
||||
|
@ -219,13 +219,13 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
public void testStaleIfErrorInRequestIsTrueReturnsStaleEntryWithWarning()
|
||||
throws Exception{
|
||||
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||
"public, max-age=5");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control","public, stale-if-error=60");
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
|
||||
|
@ -243,14 +243,14 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
public void testStaleIfErrorInRequestIsTrueReturnsStaleNonRevalidatableEntryWithWarning()
|
||||
throws Exception {
|
||||
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
|
||||
resp1.setHeader("Cache-Control", "public, max-age=5");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control", "public, stale-if-error=60");
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
|
||||
|
@ -269,13 +269,13 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
throws Exception{
|
||||
final Date now = new Date();
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||
"public, max-age=5, stale-if-error=2");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
@ -294,13 +294,13 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
throws Exception{
|
||||
final Date now = new Date();
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||
"public, max-age=5");
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest(), host);
|
||||
req2.setHeader("Cache-Control","stale-if-error=2");
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
|
||||
|
@ -335,7 +335,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
impl = new CachingExec(mockBackend, cache, config, new AsynchronousValidator(config));
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
final Date now = new Date();
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
|
@ -346,7 +346,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1).times(1,2);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
|
||||
replayMocks();
|
||||
impl.execute(route, req1, context, null);
|
||||
|
@ -380,7 +380,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
impl = new CachingExec(mockBackend, cache, config, new AsynchronousValidator(config));
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/",
|
||||
HttpVersion.HTTP_1_1));
|
||||
HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
final Date now = new Date();
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
|
@ -390,7 +390,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1).times(1, 2);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/",
|
||||
HttpVersion.HTTP_1_1));
|
||||
HttpVersion.HTTP_1_1), host);
|
||||
|
||||
replayMocks();
|
||||
impl.execute(route, req1, context, null);
|
||||
|
@ -423,7 +423,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
impl = new CachingExec(mockBackend, cache, config, new AsynchronousValidator(config));
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
final Date now = new Date();
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
|
@ -434,7 +434,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1).times(1,2);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req2.setHeader("If-None-Match","\"etag\"");
|
||||
|
||||
replayMocks();
|
||||
|
@ -471,7 +471,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
impl = new CachingExec(mockBackend, cache, config);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, must-revalidate");
|
||||
resp1.setHeader("ETag","\"etag\"");
|
||||
|
@ -480,7 +480,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, must-revalidate");
|
||||
resp2.setHeader("ETag","\"etag\"");
|
||||
|
@ -522,7 +522,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
impl = new CachingExec(mockBackend, cache, config);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, proxy-revalidate");
|
||||
resp1.setHeader("ETag","\"etag\"");
|
||||
|
@ -531,7 +531,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, proxy-revalidate");
|
||||
resp2.setHeader("ETag","\"etag\"");
|
||||
|
@ -573,7 +573,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
impl = new CachingExec(mockBackend, cache, config);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15");
|
||||
resp1.setHeader("ETag","\"etag\"");
|
||||
|
@ -582,7 +582,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), host);
|
||||
req2.setHeader("Cache-Control","min-fresh=2");
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
resp2.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15");
|
||||
|
|
|
@ -32,24 +32,25 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestRequestProtocolCompliance {
|
||||
|
||||
private HttpHost host;
|
||||
private RequestProtocolCompliance impl;
|
||||
private HttpRequest req;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
host = new HttpHost("foo.example.com", 80);
|
||||
req = HttpTestUtils.makeDefaultRequest();
|
||||
impl = new RequestProtocolCompliance(false);
|
||||
}
|
||||
|
@ -84,27 +85,25 @@ public class TestRequestProtocolCompliance {
|
|||
|
||||
@Test
|
||||
public void doesNotModifyACompliantRequest() throws Exception {
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req, host);
|
||||
impl.makeRequestCompliant(wrapper);
|
||||
assertTrue(HttpTestUtils.equivalent(req, wrapper));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removesEntityFromTRACERequest() throws Exception {
|
||||
final HttpEntityEnclosingRequest reqst =
|
||||
new BasicHttpEntityEnclosingRequest("TRACE", "/", HttpVersion.HTTP_1_1);
|
||||
reqst.setEntity(HttpTestUtils.makeBody(50));
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(reqst);
|
||||
final HttpRequest request =
|
||||
new BasicHttpRequest("TRACE", "/", HttpVersion.HTTP_1_1);
|
||||
request.setEntity(HttpTestUtils.makeBody(50));
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request, host);
|
||||
impl.makeRequestCompliant(wrapper);
|
||||
if (wrapper instanceof HttpEntityEnclosingRequest) {
|
||||
assertNull(((HttpEntityEnclosingRequest) wrapper).getEntity());
|
||||
}
|
||||
assertNull(wrapper.getEntity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void upgrades1_0RequestTo1_1() throws Exception {
|
||||
req = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_0);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req, host);
|
||||
impl.makeRequestCompliant(wrapper);
|
||||
assertEquals(HttpVersion.HTTP_1_1, wrapper.getProtocolVersion());
|
||||
}
|
||||
|
@ -113,7 +112,7 @@ public class TestRequestProtocolCompliance {
|
|||
public void downgrades1_2RequestTo1_1() throws Exception {
|
||||
final ProtocolVersion HTTP_1_2 = new ProtocolVersion("HTTP", 1, 2);
|
||||
req = new BasicHttpRequest("GET", "/", HTTP_1_2);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req, host);
|
||||
impl.makeRequestCompliant(wrapper);
|
||||
assertEquals(HttpVersion.HTTP_1_1, wrapper.getProtocolVersion());
|
||||
}
|
||||
|
@ -122,7 +121,7 @@ public class TestRequestProtocolCompliance {
|
|||
public void stripsMinFreshFromRequestIfNoCachePresent()
|
||||
throws Exception {
|
||||
req.setHeader("Cache-Control", "no-cache, min-fresh=10");
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req, host);
|
||||
impl.makeRequestCompliant(wrapper);
|
||||
assertEquals("no-cache",
|
||||
wrapper.getFirstHeader("Cache-Control").getValue());
|
||||
|
@ -132,7 +131,7 @@ public class TestRequestProtocolCompliance {
|
|||
public void stripsMaxFreshFromRequestIfNoCachePresent()
|
||||
throws Exception {
|
||||
req.setHeader("Cache-Control", "no-cache, max-stale=10");
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req, host);
|
||||
impl.makeRequestCompliant(wrapper);
|
||||
assertEquals("no-cache",
|
||||
wrapper.getFirstHeader("Cache-Control").getValue());
|
||||
|
@ -142,7 +141,7 @@ public class TestRequestProtocolCompliance {
|
|||
public void stripsMaxAgeFromRequestIfNoCachePresent()
|
||||
throws Exception {
|
||||
req.setHeader("Cache-Control", "no-cache, max-age=10");
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req, host);
|
||||
impl.makeRequestCompliant(wrapper);
|
||||
assertEquals("no-cache",
|
||||
wrapper.getFirstHeader("Cache-Control").getValue());
|
||||
|
@ -152,7 +151,7 @@ public class TestRequestProtocolCompliance {
|
|||
public void doesNotStripMinFreshFromRequestWithoutNoCache()
|
||||
throws Exception {
|
||||
req.setHeader("Cache-Control", "min-fresh=10");
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req, host);
|
||||
impl.makeRequestCompliant(wrapper);
|
||||
assertEquals("min-fresh=10",
|
||||
wrapper.getFirstHeader("Cache-Control").getValue());
|
||||
|
@ -162,7 +161,7 @@ public class TestRequestProtocolCompliance {
|
|||
public void correctlyStripsMinFreshFromMiddleIfNoCache()
|
||||
throws Exception {
|
||||
req.setHeader("Cache-Control", "no-cache,min-fresh=10,no-store");
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req, host);
|
||||
impl.makeRequestCompliant(wrapper);
|
||||
assertEquals("no-cache,no-store",
|
||||
wrapper.getFirstHeader("Cache-Control").getValue());
|
||||
|
|
|
@ -29,16 +29,16 @@ package org.apache.http.impl.client.cache;
|
|||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.hc.core5.http.message.BasicStatusLine;
|
||||
import org.apache.http.client.methods.HttpOptions;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -32,29 +32,32 @@ import static junit.framework.TestCase.assertTrue;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.entity.InputStreamEntity;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.http.client.methods.HttpRequestWrapper;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestResponseProtocolCompliance {
|
||||
|
||||
private HttpHost host;
|
||||
private ResponseProtocolCompliance impl;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
host = new HttpHost("foo.example.com", 80);
|
||||
impl = new ResponseProtocolCompliance();
|
||||
}
|
||||
|
||||
|
@ -88,7 +91,7 @@ public class TestResponseProtocolCompliance {
|
|||
|
||||
@Test
|
||||
public void consumesBodyIfOriginSendsOneInResponseToHEAD() throws Exception {
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(new HttpHead("http://foo.example.com/"));
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(new HttpHead("http://foo.example.com/"), host);
|
||||
final int nbytes = 128;
|
||||
final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||
setMinimalResponseHeaders(resp);
|
||||
|
@ -105,7 +108,7 @@ public class TestResponseProtocolCompliance {
|
|||
|
||||
@Test(expected=ClientProtocolException.class)
|
||||
public void throwsExceptionIfOriginReturnsPartialResponseWhenNotRequested() throws Exception {
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"), host);
|
||||
final int nbytes = 128;
|
||||
final HttpResponse resp = makePartialResponse(nbytes);
|
||||
resp.setEntity(HttpTestUtils.makeBody(nbytes));
|
||||
|
@ -115,7 +118,7 @@ public class TestResponseProtocolCompliance {
|
|||
|
||||
@Test
|
||||
public void consumesPartialContentFromOriginEvenIfNotRequested() throws Exception {
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"), host);
|
||||
final int nbytes = 128;
|
||||
final HttpResponse resp = makePartialResponse(nbytes);
|
||||
|
||||
|
@ -132,13 +135,13 @@ public class TestResponseProtocolCompliance {
|
|||
|
||||
@Test
|
||||
public void consumesBodyOf100ContinueResponseIfItArrives() throws Exception {
|
||||
final HttpEntityEnclosingRequest req = new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
|
||||
final HttpRequest req = new BasicHttpRequest("POST", "/", HttpVersion.HTTP_1_1);
|
||||
final int nbytes = 128;
|
||||
req.setHeader("Content-Length","" + nbytes);
|
||||
req.setHeader("Content-Type", "application/octet-stream");
|
||||
final HttpEntity postBody = new ByteArrayEntity(HttpTestUtils.getRandomBytes(nbytes));
|
||||
req.setEntity(postBody);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req, host);
|
||||
|
||||
final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_CONTINUE, "Continue");
|
||||
final Flag closed = new Flag();
|
||||
|
|
|
@ -30,17 +30,17 @@ import java.io.IOException;
|
|||
import java.lang.reflect.Proxy;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.entity.EntityUtils;
|
||||
import org.apache.hc.core5.http.entity.StringEntity;
|
||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -30,30 +30,30 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.MethodNotSupportedException;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpException;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.MethodNotSupportedException;
|
||||
import org.apache.hc.core5.http.bootstrap.io.HttpServer;
|
||||
import org.apache.hc.core5.http.bootstrap.io.ServerBootstrap;
|
||||
import org.apache.hc.core5.http.config.SocketConfig;
|
||||
import org.apache.hc.core5.http.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.io.HttpRequestHandler;
|
||||
import org.apache.hc.core5.http.protocol.BasicHttpContext;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.cache.CacheResponseStatus;
|
||||
import org.apache.http.client.cache.HttpCacheContext;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.config.SocketConfig;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.impl.bootstrap.HttpServer;
|
||||
import org.apache.http.impl.bootstrap.ServerBootstrap;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpRequestHandler;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -253,7 +253,7 @@ public class TestStaleWhileRevalidationReleasesConnection {
|
|||
* @param response the response
|
||||
* @param context the context
|
||||
*
|
||||
* @throws org.apache.http.HttpException in case of a problem
|
||||
* @throws org.apache.hc.core5.http.HttpException in case of a problem
|
||||
* @throws java.io.IOException in case of an IO problem
|
||||
*/
|
||||
@Override
|
||||
|
@ -271,7 +271,7 @@ public class TestStaleWhileRevalidationReleasesConnection {
|
|||
(method + " not supported by " + getClass().getName());
|
||||
}
|
||||
|
||||
response.setStatusCode(org.apache.http.HttpStatus.SC_OK);
|
||||
response.setStatusCode(org.apache.hc.core5.http.HttpStatus.SC_OK);
|
||||
response.addHeader("Cache-Control",getCacheContent(request));
|
||||
final byte[] content = getHeaderContent(request);
|
||||
final ByteArrayEntity bae = new ByteArrayEntity(content);
|
||||
|
@ -285,7 +285,7 @@ public class TestStaleWhileRevalidationReleasesConnection {
|
|||
public byte[] getHeaderContent(final HttpRequest request) {
|
||||
final Header contentHeader = request.getFirstHeader(DEFAULT_CLIENT_CONTROLLED_CONTENT_HEADER);
|
||||
if(contentHeader!=null) {
|
||||
return contentHeader.getValue().getBytes(Consts.UTF_8);
|
||||
return contentHeader.getValue().getBytes(StandardCharsets.UTF_8);
|
||||
} else {
|
||||
return DEFAULT_CONTENT;
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ package org.apache.http.impl.client.cache;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -37,10 +37,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.Element;
|
||||
|
||||
import org.apache.http.client.cache.HttpCacheEntry;
|
||||
import org.apache.http.client.cache.HttpCacheEntrySerializer;
|
||||
import org.apache.http.client.cache.HttpCacheUpdateCallback;
|
||||
|
@ -49,6 +45,10 @@ import org.apache.http.impl.client.cache.CacheConfig;
|
|||
import org.apache.http.impl.client.cache.HttpTestUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.Element;
|
||||
|
||||
@SuppressWarnings("boxing") // test code
|
||||
public class TestEhcacheHttpCacheStorage extends TestCase {
|
||||
|
||||
|
|
|
@ -26,11 +26,6 @@
|
|||
*/
|
||||
package org.apache.http.impl.client.cache.ehcache;
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
import net.sf.ehcache.config.Configuration;
|
||||
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
||||
|
||||
import org.apache.http.client.cache.HttpCacheStorage;
|
||||
import org.apache.http.impl.client.cache.CacheConfig;
|
||||
import org.apache.http.impl.client.cache.CachingExec;
|
||||
|
@ -43,6 +38,11 @@ import org.junit.AfterClass;
|
|||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
import net.sf.ehcache.config.Configuration;
|
||||
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
||||
|
||||
public class TestEhcacheProtocolRequirements extends TestProtocolRequirements{
|
||||
|
||||
protected final String TEST_EHCACHE_NAME = "TestEhcacheProtocolRequirements-cache";
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue