diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java index 1aa831d5b0..ce93fb93ec 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java @@ -188,10 +188,14 @@ public class I2PSnarkServlet extends DefaultServlet { } else { String base = URIUtil.addPaths(req.getRequestURI(), "/"); String listing = getListHTML(resource, base, true, method.equals("POST") ? req.getParameterMap() : null); - if (listing != null) + if (method.equals("POST")) { + // P-R-G + sendRedirect(req, resp, ""); + } else if (listing != null) { resp.getWriter().write(listing); - else // shouldn't happen + } else { // shouldn't happen resp.sendError(404); + } } } else { super.service(req, resp); @@ -209,6 +213,9 @@ public class I2PSnarkServlet extends DefaultServlet { processRequest(req); else // nonce is constant, shouldn't happen _manager.addMessage("Please retry form submission (bad nonce)"); + // P-R-G (or G-R-G to hide the params from the address bar) + sendRedirect(req, resp, peerString); + return; } PrintWriter out = resp.getWriter(); @@ -807,6 +814,22 @@ public class I2PSnarkServlet extends DefaultServlet { } } + /** + * Redirect a POST to a GET (P-R-G), preserving the peer string + * @since 0.9.5 + */ + private void sendRedirect(HttpServletRequest req, HttpServletResponse resp, String p) throws IOException { + String url = req.getRequestURL().toString(); + StringBuilder buf = new StringBuilder(128); + if (url.endsWith("_post")) + url = url.substring(0, url.length() - 5); + buf.append(url); + if (p.length() > 0) + buf.append('?').append(p); + resp.setHeader("Location", buf.toString()); + resp.sendError(302, "Moved"); + } + /** @since 0.9 */ private void processTrackerForm(String action, HttpServletRequest req) { if (action.equals(_("Delete selected")) || action.equals(_("Save tracker configuration"))) { @@ -1768,10 +1791,11 @@ public class I2PSnarkServlet extends DefaultServlet { out.write(_("I2CP options")); out.write(":
\n" + - + " \n" + // spacer " \n" + + " \n" + // spacer ""); } @@ -1837,6 +1861,7 @@ public class I2PSnarkServlet extends DefaultServlet { "" + "" + "\n" + + " \n" + // spacer "\n" + "\n" + "\n" + @@ -1844,7 +1869,9 @@ public class I2PSnarkServlet extends DefaultServlet { // "\n" + "\n" + "\n" + - "\n"); + "" + + " \n" + // spacer + "\n"); out.write(buf.toString()); } @@ -2001,7 +2028,7 @@ public class I2PSnarkServlet extends DefaultServlet { * @param base The base URL * @param parent True if the parent directory should be included * @param postParams map of POST parameters or null if not a POST - * @return String of HTML + * @return String of HTML or null if postParams != null * @since 0.7.14 */ private String getListHTML(Resource r, String base, boolean parent, Map postParams) @@ -2013,8 +2040,6 @@ public class I2PSnarkServlet extends DefaultServlet { Arrays.sort(ls, Collator.getInstance()); } // if r is not a directory, we are only showing torrent info section - StringBuilder buf=new StringBuilder(4096); - buf.append(DOCTYPE + ""); String title = URIUtil.decodePath(base); if (title.startsWith("/i2psnark/")) title = title.substring("/i2psnark/".length()); @@ -2028,9 +2053,14 @@ public class I2PSnarkServlet extends DefaultServlet { torrentName = title; Snark snark = _manager.getTorrentByBaseName(torrentName); - if (snark != null && postParams != null) + if (snark != null && postParams != null) { + // caller must P-R-G savePriorities(snark, postParams); + return null; + } + StringBuilder buf=new StringBuilder(4096); + buf.append(DOCTYPE).append("<HTML><HEAD><TITLE>"); if (title.endsWith("/")) title = title.substring(0, title.length() - 1); String directory = title;