ok2c commented on code in PR #960: URL: https://github.com/apache/httpcomponents-client/pull/960#discussion_r4659261923
########## httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthSupport.java: ########## @@ -0,0 +1,99 @@ +/* + * ==================================================================== + * 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.hc.client5.http.impl.auth; + +import org.apache.hc.client5.http.auth.AuthExchange; +import org.apache.hc.client5.http.auth.AuthScheme; +import org.apache.hc.client5.http.auth.AuthStateCacheable; +import org.apache.hc.client5.http.protocol.HttpClientContext; +import org.apache.hc.core5.annotation.Contract; +import org.apache.hc.core5.annotation.Internal; +import org.apache.hc.core5.annotation.ThreadingBehavior; +import org.apache.hc.core5.function.Supplier; +import org.apache.hc.core5.http.HttpHost; + +/** + * Shared target authentication exchange priming logic used by {@link org.apache.hc.client5.http.impl.classic.ProtocolExec}, + * {@link org.apache.hc.client5.http.impl.async.AsyncProtocolExec}, and the caching execution handlers, which need to + * know what the former two would do to a request before it reaches them, without actually sending one. + * + * @since 5.7 + */ +@Internal +@Contract(threading = ThreadingBehavior.STATELESS) +public final class AuthSupport { + + private AuthSupport() { + } + + /** + * Resets the given target {@link AuthExchange} when the path prefix of a previous exchange no longer + * applies to the current request, then attempts to preemptively populate it from the auth cache. This + * is the exact step {@code ProtocolExec} and {@code AsyncProtocolExec} perform before entering their + * 401/407 challenge-response loop; it is factored out here so it can also be used to determine, without + * sending a request, what those classes would do. + */ + public static void primeAuthExchange( + final HttpHost target, + final Supplier<String> pathPrefixSupplier, + final AuthExchange targetAuthExchange, + final AuthCacheKeeper authCacheKeeper, + final HttpClientContext context) { + if (!targetAuthExchange.isConnectionBased() && Review Comment: @arturobernalg Why do we need this? What good does it this support method make? Saves two if statements and makes it harder to understand the flow of the authentication logic? I am not in favor of this change in its present state, especially so late in the release cycle. Could you please provide test cases that demonstrate what the current implementation does incorrectly? I very much rather disable caching for those cases for the 5.7 release. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
