Skip to content

Commit cbbf369

Browse files
committed
replace Jooby.redirect for Results.redirect (code cleanup)
1 parent f2a389b commit cbbf369

4 files changed

Lines changed: 218 additions & 159 deletions

File tree

coverage-report/src/test/java/org/jooby/RedirectFeature.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ public String here() {
4444

4545
{
4646

47-
get("/l1/l2/l3", redirect("/l1"));
47+
get("/l1/l2/l3", () -> Results.redirect("/l1"));
4848

4949
get("/l1", (req, rsp) -> rsp.send(req.path()));
5050

51-
get("/blog/admin", redirect("post/new"));
51+
get("/blog/admin", () -> Results.redirect("post/new"));
5252

5353
get("/blog/admin/post/new", (req, rsp) -> rsp.send(req.path()));
5454

5555
get("/blog/post/new", (req, rsp) -> rsp.send(req.path()));
5656

57-
get("/d1/d2/d3", redirect(".."));
57+
get("/d1/d2/d3", () -> Results.redirect(".."));
5858

59-
get("/d1/d2/d3b", redirect("../d2"));
59+
get("/d1/d2/d3b", () -> Results.redirect("../d2"));
6060

61-
get("/d1/d2/d3c", redirect("./d2"));
61+
get("/d1/d2/d3c", () -> Results.redirect("./d2"));
6262

63-
get("/back", redirect("back"));
63+
get("/back", () -> Results.redirect("back"));
6464

6565
get("/d1", (req, rsp) -> rsp.send(req.path()));
6666

jooby/src/main/java/org/jooby/Jooby.java

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,132 +2487,6 @@ public Route.Definition head(final @Nonnull String path, final @Nonnull Route.Ha
24872487
return this;
24882488
}
24892489

2490-
/**
2491-
* Redirect to the given url with status code defaulting to {@link Status#FOUND}.
2492-
*
2493-
* <pre>
2494-
* rsp.redirect("/foo/bar");
2495-
* rsp.redirect("http://example.com");
2496-
* rsp.redirect("http://example.com");
2497-
* rsp.redirect("../login");
2498-
* </pre>
2499-
*
2500-
* Redirects can be a fully qualified URI for redirecting to a different site:
2501-
*
2502-
* <pre>
2503-
* rsp.redirect("http://google.com");
2504-
* </pre>
2505-
*
2506-
* Redirects can be relative to the root of the host name. For example, if you were
2507-
* on <code>http://example.com/admin/post/new</code>, the following redirect to /admin would
2508-
* land you at <code>http://example.com/admin</code>:
2509-
*
2510-
* <pre>
2511-
* rsp.redirect("/admin");
2512-
* </pre>
2513-
*
2514-
* Redirects can be relative to the current URL. A redirection of post/new, from
2515-
* <code>http://example.com/blog/admin/</code> (notice the trailing slash), would give you
2516-
* <code>http://example.com/blog/admin/post/new.</code>
2517-
*
2518-
* <pre>
2519-
* rsp.redirect("post/new");
2520-
* </pre>
2521-
*
2522-
* Redirecting to post/new from <code>http://example.com/blog/admin</code> (no trailing slash),
2523-
* will take you to <code>http://example.com/blog/post/new</code>.
2524-
*
2525-
* <p>
2526-
* If you found the above behavior confusing, think of path segments as directories (have trailing
2527-
* slashes) and files, it will start to make sense.
2528-
* </p>
2529-
*
2530-
* Pathname relative redirects are also possible. If you were on
2531-
* <code>http://example.com/admin/post/new</code>, the following redirect would land you at
2532-
* <code>http//example.com/admin</code>:
2533-
*
2534-
* <pre>
2535-
* rsp.redirect("..");
2536-
* </pre>
2537-
*
2538-
* A back redirection will redirect the request back to the <code>Referer</code>, defaulting to
2539-
* <code>/</code> when missing.
2540-
*
2541-
* <pre>
2542-
* rsp.redirect("back");
2543-
* </pre>
2544-
*
2545-
* @param location Either a relative or absolute location.
2546-
* @return A route handler.
2547-
*/
2548-
public Route.Handler redirect(final String location) {
2549-
return redirect(Status.FOUND, location);
2550-
}
2551-
2552-
/**
2553-
* Redirect to the given url with status code defaulting to {@link Status#FOUND}.
2554-
*
2555-
* <pre>
2556-
* rsp.redirect("/foo/bar");
2557-
* rsp.redirect("http://example.com");
2558-
* rsp.redirect("http://example.com");
2559-
* rsp.redirect("../login");
2560-
* </pre>
2561-
*
2562-
* Redirects can be a fully qualified URI for redirecting to a different site:
2563-
*
2564-
* <pre>
2565-
* rsp.redirect("http://google.com");
2566-
* </pre>
2567-
*
2568-
* Redirects can be relative to the root of the host name. For example, if you were
2569-
* on <code>http://example.com/admin/post/new</code>, the following redirect to /admin would
2570-
* land you at <code>http://example.com/admin</code>:
2571-
*
2572-
* <pre>
2573-
* rsp.redirect("/admin");
2574-
* </pre>
2575-
*
2576-
* Redirects can be relative to the current URL. A redirection of post/new, from
2577-
* <code>http://example.com/blog/admin/</code> (notice the trailing slash), would give you
2578-
* <code>http://example.com/blog/admin/post/new.</code>
2579-
*
2580-
* <pre>
2581-
* rsp.redirect("post/new");
2582-
* </pre>
2583-
*
2584-
* Redirecting to post/new from <code>http://example.com/blog/admin</code> (no trailing slash),
2585-
* will take you to <code>http://example.com/blog/post/new</code>.
2586-
*
2587-
* <p>
2588-
* If you found the above behavior confusing, think of path segments as directories (have trailing
2589-
* slashes) and files, it will start to make sense.
2590-
* </p>
2591-
*
2592-
* Pathname relative redirects are also possible. If you were on
2593-
* <code>http://example.com/admin/post/new</code>, the following redirect would land you at
2594-
* <code>http//example.com/admin</code>:
2595-
*
2596-
* <pre>
2597-
* rsp.redirect("..");
2598-
* </pre>
2599-
*
2600-
* A back redirection will redirect the request back to the <code>Referer</code>, defaulting to
2601-
* <code>/</code> when missing.
2602-
*
2603-
* <pre>
2604-
* rsp.redirect("back");
2605-
* </pre>
2606-
*
2607-
* @param status A redirect status.
2608-
* @param location Either a relative or absolute location.
2609-
* @return A route handler.
2610-
*/
2611-
public Route.Handler redirect(final Status status, final String location) {
2612-
requireNonNull(location, "A location is required.");
2613-
return (req, rsp) -> rsp.redirect(status, location);
2614-
}
2615-
26162490
/**
26172491
* Keep track of routes in the order user define them.
26182492
*

0 commit comments

Comments
 (0)