Skip to content

Commit 8fd94e5

Browse files
committed
[refactor] Simplify code
1 parent 2a78746 commit 8fd94e5

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

  • extensions/modules/http-client/src/main/java/org/exist/xquery/modules/httpclient

extensions/modules/http-client/src/main/java/org/exist/xquery/modules/httpclient/RequestBuilder.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,9 @@ private void applySingleBody(final HttpRequest.Builder builder, final String upp
285285
* @return true if the request should be re-sent with an {@code Authorization} header on a 401.
286286
*/
287287
public boolean shouldAttemptChallenge() {
288-
return allOptions.userCredentials().username() != null && !allOptions.userCredentials().sendAuthorization() && allOptions.userCredentials().authMethod() != null
289-
&& ("basic".equalsIgnoreCase(allOptions.userCredentials().authMethod()) || "digest".equalsIgnoreCase(allOptions.userCredentials().authMethod()));
288+
final UserCredentials userCredentials = allOptions.userCredentials();
289+
return userCredentials.username() != null && !userCredentials.sendAuthorization() && userCredentials.authMethod() != null
290+
&& ("basic".equalsIgnoreCase(userCredentials.authMethod()) || "digest".equalsIgnoreCase(userCredentials.authMethod()));
290291
}
291292

292293
/**
@@ -299,21 +300,23 @@ public boolean shouldAttemptChallenge() {
299300
* (unsupported scheme, missing data, or a scheme mismatch with {@code @auth-method}).
300301
*/
301302
public String challengeResponse(final String wwwAuthenticate) {
302-
if (allOptions.userCredentials().username() == null || allOptions.userCredentials().authMethod() == null) {
303+
final UserCredentials userCredentials = allOptions.userCredentials();
304+
if (userCredentials.username() == null || userCredentials.authMethod() == null) {
303305
return null;
304306
}
305-
if ("basic".equalsIgnoreCase(allOptions.userCredentials().authMethod())) {
307+
if ("basic".equalsIgnoreCase(userCredentials.authMethod())) {
306308
return "Basic " + base64Credentials();
307309
}
308-
if ("digest".equalsIgnoreCase(allOptions.userCredentials().authMethod())) {
310+
if ("digest".equalsIgnoreCase(userCredentials.authMethod())) {
309311
return digestResponse(wwwAuthenticate);
310312
}
311313
return null;
312314
}
313315

314316
private String base64Credentials() {
317+
final UserCredentials userCredentials = allOptions.userCredentials();
315318
return Base64.getEncoder().encodeToString(
316-
(allOptions.userCredentials().username() + ":" + (allOptions.userCredentials().password() != null ? allOptions.userCredentials().password() : "")).getBytes(StandardCharsets.UTF_8));
319+
(userCredentials.username() + ":" + (userCredentials.password() != null ? userCredentials.password() : "")).getBytes(StandardCharsets.UTF_8));
317320
}
318321

319322
/**

0 commit comments

Comments
 (0)