X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FDownloader.java;h=1ec4379a92b355cc1261e0d80d2c057dee0ff8ee;hb=76c54eff86f51689ab73d1b53796206d139d6fc3;hp=4976c483aef7ab8be33fb21ee757f205b13b292f;hpb=3052163b494bf89d178638a047ca80008578a782;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/Downloader.java b/src/be/nikiroo/utils/Downloader.java index 4976c48..1ec4379 100644 --- a/src/be/nikiroo/utils/Downloader.java +++ b/src/be/nikiroo/utils/Downloader.java @@ -216,7 +216,13 @@ public class Downloader { * @param url * the {@link URL} to open * @param originalUrl - * the original {@link URL} before any redirection occurs + * the original {@link URL} before any redirection occurs, which + * is also used for the cache ID if needed (so we can retrieve + * the content with this URL if needed) + * @param currentReferer + * the current referer, for websites that needs this info + * @param cookiesValues + * the cookies * @param postParams * the POST parameters * @param getParams @@ -233,17 +239,18 @@ public class Downloader { * @throws IOException * in case of I/O error */ - private InputStream open(URL url, final URL originalUrl, - URL currentReferer, Map cookiesValues, - Map postParams, Map getParams, - String oauth, boolean stable) throws IOException { + public InputStream open(URL url, final URL originalUrl, URL currentReferer, + Map cookiesValues, Map postParams, + Map getParams, String oauth, boolean stable) + throws IOException { tracer.trace("Request: " + url); if (cache != null) { - InputStream in = cache.load(url, false, stable); + InputStream in = cache.load(originalUrl, false, stable); if (in != null) { - tracer.trace("Take from cache: " + url); + tracer.trace("Use the cache: " + url); + tracer.trace("Original URL : " + originalUrl); return in; } } @@ -327,9 +334,11 @@ public class Downloader { } if (in != null && cache != null) { - tracer.trace("Save to cache: " + url); + tracer.trace("Save to cache: " + originalUrl); try { - cache.save(in, url); + cache.save(in, originalUrl); + in.close(); + in = cache.load(originalUrl, true, false); } catch (IOException e) { tracer.error(new IOException( "Cannot save URL to cache, will ignore cache: " + url, @@ -381,7 +390,6 @@ public class Downloader { builder.append(';'); } - // TODO: check if format is ok builder.append(cookie.toString()); }