From b2f452ea2e5fdc2771e8f16139eb599b91ab9a38 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 16 Oct 2010 04:59:09 +0200 Subject: [PATCH] In case of a permanent redirect, follow. --- .../pterodactylus/sone/core/FreenetInterface.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index d823cc1..2c98a7e 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -86,16 +86,21 @@ public class FreenetInterface extends AbstractService { * @return The result of the fetch, or {@code null} if an error occured */ public FetchResult fetchUri(FreenetURI uri) { - logger.entering(FreenetInterface.class.getName(), "fetchUri(FreenetURI)", uri); FetchResult fetchResult = null; - try { - fetchResult = client.fetch(uri); - } catch (FetchException fe1) { - logger.log(Level.WARNING, "Could not fetch “" + uri + "”!", fe1); - } finally { - logger.exiting(FreenetInterface.class.getName(), "fetchUri(FreenetURI)", fetchResult); + FreenetURI currentUri = new FreenetURI(uri); + while (true) { + try { + fetchResult = client.fetch(currentUri); + return fetchResult; + } catch (FetchException fe1) { + if (fe1.getMode() == FetchException.PERMANENT_REDIRECT) { + currentUri = fe1.newURI; + continue; + } + logger.log(Level.WARNING, "Could not fetch “" + uri + "”!", fe1); + return null; + } } - return fetchResult; } /** -- 2.7.4