Skip to content

Commit

Permalink
Extract createResponseURI
Browse files Browse the repository at this point in the history
  • Loading branch information
corneil committed Oct 17, 2024
1 parent 08885cf commit 14ebb44
Showing 1 changed file with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,7 @@ public URI getLocationURI(final HttpRequest request, final HttpResponse response
if (StringUtils.hasText(query) && query.contains(AMZ_CREDENTIAL)) {
if (isHeadOrGetMethod(method)) {
removeAuthorizationHeader(request, false);
try {
if (isHeadMethod(method)) {
return new HttpHead(httpUriRequest).getUri();
}
else {
return new HttpGet(httpUriRequest).getUri();
}
}
catch (URISyntaxException e) {
throw new HttpException("Unable to get location URI", e);
}
return createResponseURI(method, httpUriRequest);
}
}

Expand All @@ -114,12 +104,7 @@ public URI getLocationURI(final HttpRequest request, final HttpResponse response
if (request.getUri().getRawPath().contains(AZURECR_URI_SUFFIX)) {
if (isHeadOrGetMethod(method)) {
removeAuthorizationHeader(request, true);
if (isHeadMethod(method)) {
return new HttpHead(httpUriRequest).getUri();
}
else {
return new HttpGet(httpUriRequest).getUri();
}
return createResponseURI(method, httpUriRequest);
}
}

Expand All @@ -128,12 +113,7 @@ public URI getLocationURI(final HttpRequest request, final HttpResponse response
&& request.getUri().getRawPath().contains(extra.get(CUSTOM_REGISTRY))) {
if (isHeadOrGetMethod(method)) {
removeAuthorizationHeader(request, false);
if (isHeadMethod(method)) {
return new HttpHead(httpUriRequest).getUri();
}
else {
return new HttpGet(httpUriRequest).getUri();
}
return createResponseURI(method, httpUriRequest);
}
}
}
Expand All @@ -143,6 +123,20 @@ public URI getLocationURI(final HttpRequest request, final HttpResponse response
return httpUriRequest;
}

private URI createResponseURI(String method, URI httpUriRequest) throws HttpException {
try {
if (isHeadMethod(method)) {
return new HttpHead(httpUriRequest).getUri();
}
else {
return new HttpGet(httpUriRequest).getUri();
}
}
catch (URISyntaxException e) {
throw new HttpException("Unable to get location URI", e);
}
}

private static void removeAuthorizationHeader(HttpRequest request, boolean onlyBasicAuth) {
for (Header header : request.getHeaders()) {
if (header.getName().equalsIgnoreCase(AUTHORIZATION_HEADER)
Expand Down

0 comments on commit 14ebb44

Please sign in to comment.