X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Futil%2FRestarts.java;fp=src%2Fdolda%2Fjsvc%2Futil%2FRestarts.java;h=19536675aac529a42e1c3256aa9ee240e94e72b2;hb=c25c3aadf42cf04fe8dbbfb60624589ba60112bd;hp=0000000000000000000000000000000000000000;hpb=a7d2eb2686c6e87d97d66051ba577178e5432511;p=jsvc.git diff --git a/src/dolda/jsvc/util/Restarts.java b/src/dolda/jsvc/util/Restarts.java new file mode 100644 index 0000000..1953667 --- /dev/null +++ b/src/dolda/jsvc/util/Restarts.java @@ -0,0 +1,46 @@ +package dolda.jsvc.util; + +import dolda.jsvc.*; +import java.net.*; + +public class Restarts { + public static RequestRestart redirect(final URL to) { + return(new RequestRestart() { + public void respond(Request req) { + req.status(303); + req.outheaders().put("Location", to.toString()); + } + }); + } + + public static RequestRestart redirect(final String path) { + return(new RequestRestart() { + public void respond(Request req) { + req.status(303); + URL url; + try { + url = new URL(req.url(), path); + } catch(MalformedURLException e) { + throw(new RuntimeException("Bad relative URL: + " + path, e)); + } + req.outheaders().put("Location", url.toString()); + } + }); + } + + public static RequestRestart redirectctx(final String path) { + return(new RequestRestart() { + public void respond(Request req) { + req.status(303); + URL url; + String rel = req.ctx().rootpath() + "/" + Misc.stripslashes(path, true, false); + try { + url = new URL(req.url(), rel); + } catch(MalformedURLException e) { + throw(new RuntimeException("Bad relative URL: + " + rel, e)); + } + req.outheaders().put("Location", url.toString()); + } + }); + } +}