Add refresh header to rescue page.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 6 Dec 2014 22:07:54 +0000 (23:07 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 6 Dec 2014 22:14:47 +0000 (23:14 +0100)
src/main/java/net/pterodactylus/sone/web/RescuePage.java

index 24a8f11..1ba86e9 100644 (file)
@@ -19,11 +19,15 @@ package net.pterodactylus.sone.web;
 
 import static net.pterodactylus.sone.utils.NumberParsers.parseLong;
 
+import java.util.Arrays;
+import java.util.Collections;
+
 import net.pterodactylus.sone.core.SoneRescuer;
 import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Header;
 import net.pterodactylus.util.web.Method;
 
 /**
@@ -71,4 +75,16 @@ public class RescuePage extends SoneTemplatePage {
                templateContext.set("soneRescuer", soneRescuer);
        }
 
+       @Override
+       protected Iterable<Header> getAdditionalHeaders(FreenetRequest request) {
+               LocalSone currentSone = getCurrentSone(request.getToadletContext(), false).get();
+               SoneRescuer soneRescuer = webInterface.getCore().getSoneRescuer(currentSone);
+               if ((request.getMethod() == Method.GET) && soneRescuer.isFetching()) {
+                       final Header header = new Header("Refresh");
+                       header.addValue("5; url=rescue.html");
+                       return Arrays.asList(header);
+               }
+               return Collections.emptyList();
+       }
+
 }