rPraml commented on code in PR #802:
URL: 
https://github.com/apache/httpcomponents-client/pull/802#discussion_r2786871351


##########
httpclient5/src/main/java/org/apache/hc/client5/http/auth/AuthExchange.java:
##########
@@ -61,7 +61,8 @@ public void reset() {
         this.state = State.UNCHALLENGED;
         this.authOptions = null;
         this.authScheme = null;
-        this.pathPrefix = null;

Review Comment:
   When I debugged the issue in my code, I come to exactly this place, where 
the previously set path prefix was cleared.
   So I think, not setting `pathPrefix = null` here will fix the issue.
   



##########
httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java:
##########
@@ -814,4 +823,124 @@ void testBearerTokenAuthentication() throws Exception {
         });
     }
 
+    @Test
+    void 
testBasicAuthenticationCredentialsCachingDifferentPathPrefixesSameContext() 
throws Exception {
+        final List<RequestSnapshot> requests = new CopyOnWriteArrayList<>();
+        final Authenticator authenticator = new 
BasicTestAuthenticator("test:test", "test realm") {
+            @Override
+            public AuthResult perform(final URIAuthority authority,
+                                      final String requestUri,
+                                      final String credentials) {
+                requests.add(new RequestSnapshot(requestUri, credentials != 
null));
+                return super.perform(authority, requestUri, credentials);
+            }
+        };
+        configureServerWithBasicAuth(authenticator, bootstrap -> 
bootstrap.register("*", new EchoHandler()));
+        final HttpHost target = startServer();
+
+        final List<Integer> responseCodes = new CopyOnWriteArrayList<>();
+
+        configureClient(builder -> builder
+                .addResponseInterceptorLast((response, entity, context) -> 
responseCodes.add(response.getCode())));
+
+        final TestClient client = client();
+
+        final CredentialsProvider credentialsProvider = 
CredentialsProviderBuilder.create()
+                .add(target, "test", "test".toCharArray())
+                .build();
+
+        final HttpClientContext context = HttpClientContext.create();
+        context.setAuthCache(new BasicAuthCache());
+        context.setCredentialsProvider(credentialsProvider);
+
+        for (final String requestPath : new String[]{"/blah/a", "/blubb/b"}) {
+            final HttpGet httpGet = new HttpGet(requestPath);
+            client.execute(target, httpGet, context, response -> {
+                EntityUtils.consume(response.getEntity());
+                return null;
+            });
+        }
+
+        Assertions.assertEquals(Arrays.asList(401, 200, 401, 200), 
responseCodes);

Review Comment:
   Yes, this is the expected result now.



-- 
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]

Reply via email to