Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/land/oras/auth/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,13 @@ public <T> TokenResponse refreshToken(
String wwwAuthHeader = response.headers().getOrDefault(Const.WWW_AUTHENTICATE_HEADER.toLowerCase(), "");
LOG.debug("WWW-Authenticate header: {}", wwwAuthHeader);
if (wwwAuthHeader.isEmpty()) {
logResponse(response);
throw new OrasException(response.statusCode(), "No WWW-Authenticate header found in response");
}

Matcher matcher = WWW_AUTH_VALUE_PATTERN.matcher(wwwAuthHeader);
if (!matcher.matches()) {
logResponse(response);
throw new OrasException(response.statusCode(), "Invalid WWW-Authenticate header");
}

Expand Down Expand Up @@ -915,6 +917,21 @@ private <T> ResponseWrapper<T> toResponseWrapper(HttpResponse<T> response, @Null
service);
}

/**
* Log the response
* @param response The response
*/
private void logResponse(HttpClient.ResponseWrapper<?> response) {
LOG.debug("Status Code: {}", response.statusCode());
LOG.debug("Headers: {}", response.headers());
LOG.debug("Service: {}", response.service());
String contentType = response.headers().get(Const.CONTENT_TYPE_HEADER.toLowerCase());
boolean isBinaryResponse = contentType != null && contentType.contains("octet-stream");
if (response.response() instanceof String && !isBinaryResponse) {
LOG.debug("Response: {}", response.response());
}
}

/**
* Logs the request in debug/trace mode
* @param request The request
Expand Down
Loading