1 package dolda.jsvc.util;
6 public class Restarts {
7 public static RequestRestart redirect(final URL to) {
8 return(new RequestRestart() {
9 public void respond(Request req) {
11 req.outheaders().put("Location", to.toString());
16 public static RequestRestart redirect(final String path) {
17 return(new RequestRestart() {
18 public void respond(Request req) {
22 url = new URL(req.url(), path);
23 } catch(MalformedURLException e) {
24 throw(new RuntimeException("Bad relative URL: + " + path, e));
26 req.outheaders().put("Location", url.toString());
31 public static RequestRestart redirectctx(final String path) {
32 return(new RequestRestart() {
33 public void respond(Request req) {
36 String rel = req.ctx().rootpath() + "/" + Misc.stripslashes(path, true, false);
38 url = new URL(req.url(), rel);
39 } catch(MalformedURLException e) {
40 throw(new RuntimeException("Bad relative URL: + " + rel, e));
42 req.outheaders().put("Location", url.toString());