ok2c commented on code in PR #3327:
URL:
https://github.com/apache/httpcomponents-client/pull/3327#discussion_r4743264222
##########
httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthenticationHandler.java:
##########
@@ -164,37 +164,31 @@ public boolean isChallengeExpected(final AuthExchange
authExchange) {
return authScheme != null && authScheme.isChallengeExpected();
}
- private Map<String, AuthChallenge> extractChallengeMap(
- final ChallengeType challengeType,
- final HttpResponse response) throws ParseException {
- final List<AuthChallenge> authChallenges = new ArrayList<>(10);
- MessageSupport.parseHeadersStrict(
- response,
- challengeType == ChallengeType.PROXY ?
HttpHeaders.PROXY_AUTHENTICATE : HttpHeaders.WWW_AUTHENTICATE,
- (buffer, cursor) ->
- parser.parse(challengeType, authChallenges, buffer,
cursor));
-
- return authChallenges.stream()
- .collect(Collectors.toMap(
- c -> c.getSchemeName().toLowerCase(Locale.ROOT),
- c -> c,
- (c1, c2) -> c1));
- }
-
public Map<String, AuthChallenge> extractChallengeMap(
final ChallengeType challengeType,
final HttpResponse response,
final HttpClientContext context) {
- try {
- return extractChallengeMap(challengeType, response);
- } catch (final ParseException ex) {
- if (LOG.isWarnEnabled()) {
- final HttpClientContext clientContext =
HttpClientContext.cast(context);
- final String exchangeId = clientContext.getExchangeId();
- LOG.warn("{} Malformed challenge", exchangeId);
+ final Map<String, AuthChallenge> challengeMap = new HashMap<>();
Review Comment:
@shinseongsu Damn. Good catch! Can we make it a tiny bit nicer?
```
public Map<String, AuthChallenge> extractChallengeMap(
final ChallengeType challengeType,
final HttpResponse response,
final HttpClientContext context) {
final Map<String, AuthChallenge> challengeMap = new HashMap<>();
final Iterator<Header> it = response.headerIterator(
challengeType == ChallengeType.PROXY ?
HttpHeaders.PROXY_AUTHENTICATE : HttpHeaders.WWW_AUTHENTICATE);
while (it.hasNext()) {
try {
final List<AuthChallenge> authChallenges = new ArrayList<>();
MessageSupport.parseHeaderStrict(it.next(), (buffer, cursor)
->
parser.parse(challengeType, authChallenges, buffer,
cursor));
for (final AuthChallenge authChallenge : authChallenges) {
challengeMap.putIfAbsent(authChallenge.getSchemeName().toLowerCase(Locale.ROOT),
authChallenge);
}
} catch (final ParseException ex) {
if (LOG.isWarnEnabled()) {
final HttpClientContext clientContext =
HttpClientContext.cast(context);
final String exchangeId = clientContext.getExchangeId();
LOG.warn("{} Malformed challenge", exchangeId);
}
}
}
return challengeMap;
}
```
--
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]