From b017ece7d5694cc98300a11afabd772a81bb9be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hamal=20Dvo=C5=99=C3=A1k?= <mordae@anilinux.org> Date: Sat, 4 May 2019 15:46:50 +0200 Subject: [PATCH] Add redirect function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Hamal Dvořák <mordae@anilinux.org> --- lib/Web/Hikaru/Action.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Web/Hikaru/Action.hs b/lib/Web/Hikaru/Action.hs index 8d5cd23..b4b5ca9 100644 --- a/lib/Web/Hikaru/Action.hs +++ b/lib/Web/Hikaru/Action.hs @@ -62,6 +62,7 @@ module Web.Hikaru.Action , sendText , sendString , sendJSON + , redirect , setResponseFile , setResponseBuilder , setResponseBS @@ -843,6 +844,16 @@ where setResponseBS (encode json) + -- | + -- Set the @Location@ header and response status to redirect the user + -- elsewhere. + -- + redirect :: (MonadAction m) => Text -> m () + redirect location = do + setStatus status302 + setHeader hLocation (cs location) + + -- | -- Create response body using a file. -- -- GitLab