| 1 |
{-# LANGUAGE OverloadedStrings #-} |
| 2 |
|
| 3 |
module Network.Wai.Application.Classic.Redirect ( |
| 4 |
redirectApp |
| 5 |
) where |
| 6 |
|
| 7 |
import Data.ByteString.Char8 |
| 8 |
import Network.HTTP.Types |
| 9 |
import Network.Wai |
| 10 |
import Network.Wai.Application.Classic.Field |
| 11 |
import Network.Wai.Application.Classic.Path |
| 12 |
import Network.Wai.Application.Classic.Types |
| 13 |
|
| 14 |
redirectApp :: ClassicAppSpec -> RedirectRoute -> Application |
| 15 |
redirectApp _ route req respond = |
| 16 |
respond $ responseLBS status hdr "" |
| 17 |
where |
| 18 |
path = rawPathInfo req |
| 19 |
src = redirectSrc route |
| 20 |
dst = redirectDst route |
| 21 |
-- Scheme must not be included because of no way to tell |
| 22 |
-- http or https. |
| 23 |
rurl = "//" `append` (dst </> (path <\> src)) |
| 24 |
hdr = locationHeader rurl |
| 25 |
status = movedPermanently301 |