Skip to content

Commit

Permalink
Decompose
Browse files Browse the repository at this point in the history
  • Loading branch information
BadhriNadh committed Apr 5, 2023
1 parent df05d60 commit ad4990a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/org/kohsuke/github/GitHubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,7 @@ private void detectInvalidCached404Response(GitHubConnectorResponse connectorRes
// scenarios. If GitHub ever fixes their issue and/or begins providing accurate ETags to
// their 404 responses, this will result in at worst two requests being made for each 404
// responses. However, only the second request will count against rate limit.
if (connectorResponse.statusCode() == 404 && Objects.equals(connectorResponse.request().method(), "GET")
&& connectorResponse.header("ETag") != null
&& !Objects.equals(connectorResponse.request().header("Cache-Control"), "no-cache")) {
if (isCacheableResourceNotFound(connectorResponse)) {
LOGGER.log(FINE,
"Encountered GitHub invalid cached 404 from " + connectorResponse.request().url()
+ ". Retrying with \"Cache-Control\"=\"no-cache\"...");
Expand All @@ -652,6 +650,12 @@ private void detectInvalidCached404Response(GitHubConnectorResponse connectorRes
}
}

private boolean isCacheableResourceNotFound(GitHubConnectorResponse connectorResponse){
return connectorResponse.statusCode() == 404 && Objects.equals(connectorResponse.request().method(), "GET")
&& connectorResponse.header("ETag") != null
&& !Objects.equals(connectorResponse.request().header("Cache-Control"), "no-cache");
}

private void noteRateLimit(@Nonnull RateLimitTarget rateLimitTarget,
@Nonnull GitHubConnectorResponse connectorResponse) {
try {
Expand Down

0 comments on commit ad4990a

Please sign in to comment.