File: Redirect.hs

package info (click to toggle)
haskell-wai-app-file-cgi 3.1.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 200 kB
  • sloc: haskell: 995; sh: 18; makefile: 3
file content (25 lines) | stat: -rw-r--r-- 745 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{-# LANGUAGE OverloadedStrings #-}

module Network.Wai.Application.Classic.Redirect (
    redirectApp
  ) where

import Data.ByteString.Char8
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Application.Classic.Field
import Network.Wai.Application.Classic.Path
import Network.Wai.Application.Classic.Types

redirectApp :: ClassicAppSpec -> RedirectRoute -> Application
redirectApp _ route req respond =
    respond $ responseLBS status hdr ""
  where
    path = rawPathInfo req
    src = redirectSrc route
    dst = redirectDst route
    -- Scheme must not be included because of no way to tell
    -- http or https.
    rurl = "//" `append` (dst </> (path <\> src))
    hdr = locationHeader rurl
    status = movedPermanently301