Closed iffy closed 4 years ago
Here's a potential fix, which could be made backward compatible or not depending on the default value of halt
:
diff --git a/jester.nim b/jester.nim
index d7a7e64..0f24490 100644
--- a/jester.nim
+++ b/jester.nim
@@ -578,8 +578,9 @@ template resp*(code: HttpCode): typed =
result.matched = true
break route
-template redirect*(url: string): typed =
+template redirect*(url: string, halt = true): typed =
## Redirects to ``url``. Returns from this request handler immediately.
+ ## If ``halt`` is true, skips executing future handlers, too.
## Any set response headers are preserved for this request.
bind TCActionSend, newHttpHeaders
result[0] = TCActionSend
@@ -587,7 +588,10 @@ template redirect*(url: string): typed =
setHeader(result[2], "Location", url)
result[3] = ""
result.matched = true
- break route
+ if halt:
+ break allRoutes
+ else:
+ break route
Here's my program:
I start that with
nim c -r example.nim
, then do the following:I would expect to see this instead:
I can make a PR to add a failing test case (and maybe figure out how to fix it) if you agree that it should behave as described above.