Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SharedHttpCacheStorage doesn't resolve redirect correctly if the uri that is given isn't normalized #2666 #2672

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ protected boolean removeEldestEntry(final Map.Entry<File, CacheLine> eldest) {
*/
@Override
public CacheEntry getCacheEntry(URI uri, Logger logger) throws FileNotFoundException {
CacheLine cacheLine = getCacheLine(uri);
URI normalized = uri.normalize();
CacheLine cacheLine = getCacheLine(normalized);
if (!cacheConfig.isUpdate()) { // if not updates are forced ...
int code = cacheLine.getResponseCode();
if (code == HttpURLConnection.HTTP_NOT_FOUND) {
throw new FileNotFoundException(uri.toASCIIString());
throw new FileNotFoundException(normalized.toASCIIString());
}
if (code == HttpURLConnection.HTTP_MOVED_PERM) {
return getCacheEntry(cacheLine.getRedirect(uri), logger);
return getCacheEntry(cacheLine.getRedirect(normalized), logger);
}
}
return new CacheEntry() {
Expand All @@ -106,19 +107,19 @@ public CacheEntry getCacheEntry(URI uri, Logger logger) throws FileNotFoundExcep
public long getLastModified(HttpTransportFactory transportFactory)
throws IOException {
if (cacheConfig.isOffline()) {
return cacheLine.getLastModified(uri, transportFactory,
return cacheLine.getLastModified(normalized, transportFactory,
SharedHttpCacheStorage::mavenIsOffline, logger);
}
try {
return cacheLine.fetchLastModified(uri, transportFactory, logger);
return cacheLine.fetchLastModified(normalized, transportFactory, logger);
} catch (FileNotFoundException | AuthenticationFailedException e) {
//for not found and failed authentication we can't do anything useful
throw e;
} catch (IOException e) {
if (!cacheConfig.isUpdate() && cacheLine.getResponseCode() > 0) {
//if we have something cached, use that ...
logger.warn("Request to " + uri + " failed, trying cache instead");
return cacheLine.getLastModified(uri, transportFactory, nil -> e, logger);
logger.warn("Request to " + normalized + " failed, trying cache instead");
return cacheLine.getLastModified(normalized, transportFactory, nil -> e, logger);
}
throw e;
}
Expand All @@ -128,19 +129,19 @@ public long getLastModified(HttpTransportFactory transportFactory)
public File getCacheFile(HttpTransportFactory transportFactory)
throws IOException {
if (cacheConfig.isOffline()) {
return cacheLine.getFile(uri, transportFactory,
return cacheLine.getFile(normalized, transportFactory,
SharedHttpCacheStorage::mavenIsOffline, logger);
}
try {
return cacheLine.fetchFile(uri, transportFactory, logger);
return cacheLine.fetchFile(normalized, transportFactory, logger);
} catch (FileNotFoundException | AuthenticationFailedException e) {
//for not found and failed authentication we can't do anything useful
throw e;
} catch (IOException e) {
if (!cacheConfig.isUpdate() && cacheLine.getResponseCode() > 0) {
//if we have something cached, use that ...
logger.warn("Request to " + uri + " failed, trying cache instead");
return cacheLine.getFile(uri, transportFactory, nil -> e, logger);
logger.warn("Request to " + normalized + " failed, trying cache instead");
return cacheLine.getFile(normalized, transportFactory, nil -> e, logger);
}
throw e;
}
Expand Down
Loading