2010-12-14 19:30:09 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
import qualified Network.HTTP.Enumerator as H
|
|
|
|
import qualified Network.Wai as W
|
2010-12-15 20:51:13 +03:00
|
|
|
import Network.Wai.Middleware.Gzip (gzip)
|
2010-12-14 19:30:09 +03:00
|
|
|
import Network.Wai.Handler.SimpleServer (run)
|
|
|
|
import qualified Data.ByteString.Char8 as S8
|
|
|
|
import qualified Data.ByteString.Lazy.Char8 ()
|
|
|
|
import Data.Enumerator (($$), joinI, run_)
|
|
|
|
import Blaze.ByteString.Builder (fromByteString)
|
|
|
|
import qualified Data.Enumerator as E
|
|
|
|
|
|
|
|
main :: IO ()
|
2010-12-15 20:51:13 +03:00
|
|
|
main = run 3000 $ gzip False app
|
2010-12-14 19:30:09 +03:00
|
|
|
|
2010-12-19 11:47:29 +03:00
|
|
|
app :: W.Application
|
2010-12-14 19:30:09 +03:00
|
|
|
app W.Request { W.pathInfo = path } =
|
|
|
|
case H.parseUrl $ "http://wiki.yesodweb.com" ++ S8.unpack path of
|
|
|
|
Nothing -> return notFound
|
|
|
|
Just hreq -> return $ W.ResponseEnumerator $ run_ . H.http hreq . go
|
|
|
|
where
|
|
|
|
go f s h = joinI $ E.map fromByteString $$ f s $ filter safe h
|
|
|
|
safe (x, _) = not $ x `elem` ["Content-Encoding", "Transfer-Encoding"]
|
|
|
|
|
2010-12-19 11:47:29 +03:00
|
|
|
notFound :: W.Response
|
2010-12-14 19:30:09 +03:00
|
|
|
notFound = W.ResponseLBS W.status404 [("Content-Type", "text/plain")] "Not found"
|