Skip to content

Commit 762b18f

Browse files
committed
HttpClientContext to use instance variables for standard attributes
1 parent f2b9a37 commit 762b18f

File tree

55 files changed

+424
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+424
-260
lines changed

httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/HttpCacheContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static HttpCacheContext adapt(final HttpContext context) {
6868
}
6969

7070
public static HttpCacheContext create() {
71-
return new HttpCacheContext(new HttpClientContext());
71+
return new HttpCacheContext();
7272
}
7373

7474
public HttpCacheContext(final HttpContext context) {

httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ private void handleCacheHit(
804804
scope.route,
805805
scope.originalRequest,
806806
new ComplexFuture<>(null),
807-
HttpClientContext.create(),
807+
HttpCacheContext.create(),
808808
scope.execRuntime.fork(),
809809
scope.scheduler,
810810
scope.execCount);

httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private ClassicHttpResponse handleCacheHit(
318318
scope.route,
319319
scope.originalRequest,
320320
scope.execRuntime.fork(null),
321-
HttpClientContext.create());
321+
HttpCacheContext.create());
322322
if (LOG.isDebugEnabled()) {
323323
LOG.debug("{} starting asynchronous revalidation exchange {}", exchangeId, revalidationExchangeId);
324324
}

httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ public Response execute(
232232
final HttpClientContext localContext = HttpClientContext.create();
233233
final CredentialsStore credentialsStoreSnapshot = credentialsStore;
234234
if (credentialsStoreSnapshot != null) {
235-
localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, credentialsStoreSnapshot);
235+
localContext.setCredentialsProvider(credentialsStoreSnapshot);
236236
}
237237
if (this.authCache != null) {
238-
localContext.setAttribute(HttpClientContext.AUTH_CACHE, this.authCache);
238+
localContext.setAuthCache(this.authCache);
239239
}
240240
final CookieStore cookieStoreSnapshot = cookieStore;
241241
if (cookieStoreSnapshot != null) {
242-
localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStoreSnapshot);
242+
localContext.setCookieStore(cookieStoreSnapshot);
243243
}
244244
return new Response(request.internalExecute(this.httpclient, localContext));
245245
}

httpclient5/src/main/java/org/apache/hc/client5/http/ContextBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public ContextBuilder preemptiveBasicAuth(final HttpHost host, final UsernamePas
102102

103103
@Override
104104
protected HttpClientContext createContext() {
105-
return new HttpClientContext();
105+
return HttpClientContext.create();
106106
}
107107

108108
}

httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecChain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Scope(
8181
this.route = Args.notNull(route, "Route");
8282
this.originalRequest = Args.notNull(originalRequest, "Original request");
8383
this.cancellableDependency = Args.notNull(cancellableDependency, "Dependency");
84-
this.clientContext = clientContext != null ? clientContext : HttpClientContext.create();
84+
this.clientContext = Args.notNull(clientContext, "HTTP context");
8585
this.execRuntime = Args.notNull(execRuntime, "Exec runtime");
8686
this.scheduler = scheduler;
8787
this.execCount = execCount != null ? execCount : new AtomicInteger(1);

httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecChain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Scope(final String exchangeId, final HttpRoute route, final ClassicHttpRe
5959
this.route = Args.notNull(route, "Route");
6060
this.originalRequest = Args.notNull(originalRequest, "Original request");
6161
this.execRuntime = Args.notNull(execRuntime, "Exec runtime");
62-
this.clientContext = clientContext != null ? clientContext : HttpClientContext.create();
62+
this.clientContext = Args.notNull(clientContext, "HTTP context");
6363
}
6464

6565
}

httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public List<AuthScheme> select(
7777
Args.notNull(challengeType, "ChallengeType");
7878
Args.notNull(challenges, "Map of auth challenges");
7979
Args.notNull(context, "HTTP context");
80-
final HttpClientContext clientContext = HttpClientContext.adapt(context);
80+
final HttpClientContext clientContext = HttpClientContext.cast(context);
8181
final String exchangeId = clientContext.getExchangeId();
8282

8383
final List<AuthScheme> options = new ArrayList<>();
@@ -88,7 +88,7 @@ public List<AuthScheme> select(
8888
}
8989
return options;
9090
}
91-
final RequestConfig config = clientContext.getRequestConfig();
91+
final RequestConfig config = clientContext.getRequestConfigOrDefault();
9292
Collection<String> authPrefs = challengeType == ChallengeType.TARGET ?
9393
config.getTargetPreferredAuthSchemes() : config.getProxyPreferredAuthSchemes();
9494
if (authPrefs == null) {

httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultConnectionKeepAliveStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public TimeValue getKeepAliveDuration(final HttpResponse response, final HttpCon
7171
}
7272
}
7373
}
74-
final HttpClientContext clientContext = HttpClientContext.adapt(context);
75-
final RequestConfig requestConfig = clientContext.getRequestConfig();
74+
final HttpClientContext clientContext = HttpClientContext.cast(context);
75+
final RequestConfig requestConfig = clientContext.getRequestConfigOrDefault();
7676
return requestConfig.getConnectionKeepAlive();
7777
}
7878

httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultUserTokenHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public Object getUserToken(final HttpRoute route, final HttpContext context) {
6969
@Override
7070
public Object getUserToken(final HttpRoute route, final HttpRequest request, final HttpContext context) {
7171

72-
final HttpClientContext clientContext = HttpClientContext.adapt(context);
72+
final HttpClientContext clientContext = HttpClientContext.cast(context);
7373

7474
final HttpHost target = request != null ? new HttpHost(request.getScheme(), request.getAuthority()) : route.getTargetHost();
7575

0 commit comments

Comments
 (0)