{-# 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 :: ClassicAppSpec -> RedirectRoute -> Application
redirectApp ClassicAppSpec
_ RedirectRoute
route Request
req Response -> IO ResponseReceived
respond =
Response -> IO ResponseReceived
respond (Response -> IO ResponseReceived)
-> Response -> IO ResponseReceived
forall a b. (a -> b) -> a -> b
$ Status -> ResponseHeaders -> ByteString -> Response
responseLBS Status
status ResponseHeaders
hdr ByteString
""
where
path :: ByteString
path = Request -> ByteString
rawPathInfo Request
req
src :: ByteString
src = RedirectRoute -> ByteString
redirectSrc RedirectRoute
route
dst :: ByteString
dst = RedirectRoute -> ByteString
redirectDst RedirectRoute
route
rurl :: ByteString
rurl = ByteString
"//" ByteString -> ByteString -> ByteString
`append` (ByteString
dst ByteString -> ByteString -> ByteString
</> (ByteString
path ByteString -> ByteString -> ByteString
<\> ByteString
src))
hdr :: ResponseHeaders
hdr = ByteString -> ResponseHeaders
locationHeader ByteString
rurl
status :: Status
status = Status
movedPermanently301