From f426ca2909548dce6ac311d217c47b8180780f16 Mon Sep 17 00:00:00 2001 From: Johan Compagner Date: Fri, 28 Jul 2023 14:57:01 +0200 Subject: [PATCH] SharedHttpCacheStorage doesn't resolve redirect correctly if the uri that is given isn't normalized #2666 make sure that the incoming uri param is normalized when used further up. This way it is not an extra redirect (so there are 2 redirects to the final source) --- .../transport/SharedHttpCacheStorage.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/SharedHttpCacheStorage.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/SharedHttpCacheStorage.java index d29a3ea36e..8621450136 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/SharedHttpCacheStorage.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/SharedHttpCacheStorage.java @@ -90,14 +90,15 @@ protected boolean removeEldestEntry(final Map.Entry 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() { @@ -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; } @@ -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; }