on master help sign in
Fixed webkit-sample
commitaa0431b805aac12ebbc2c354cdbed9ecc99858c5 authorMichael Snoyman <michael@snoyman.com> dateSun 6 Feb 2011, 18:44 (16 years ago) parentf142c4a
4 files changed+30−61
lazy-test.hs−31 test.hs−30 index.html → webkit-sample/index.html webkit-sample/webkit-sample.hs+30
lazy-test.hsdeleted−31
@@ -1,31 +0,0 @@
1−{-# LANGUAGE Rank2Types #-}
2−import Network.Wai
3−import Network.Wai.Enumerator
4−import qualified Network.Wai.Source as Source
5−import Network.Wai.Handler.SimpleServer
6−import qualified Data.ByteString.Char8 as B8
7−
8−main :: IO ()
9−main = putStrLn "http://localhost:3000/" >> run 3000 app
10−
11−app :: Application
12−app req = case B8.unpack $ pathInfo req of
13− "/post/" -> postResponse $ requestBody req
14− _ -> indexResponse
15−
16−indexResponse :: IO Response
17−indexResponse = return Response
18− { status = Status200
19− , responseHeaders = [(ContentType, B8.pack "text/html")]
20− , responseBody = index
21− }
22−
23−postResponse :: Source -> IO Response
24−postResponse rb = return Response
25− { status = Status200
26− , responseHeaders = [(ContentType, B8.pack "text/plain")]
27− , responseBody = Right $ fromLBS' $ Source.toLBS rb
28− }
29−
30−index :: Either FilePath a
31−index = Left "index.html"
test.hsdeleted−30
@@ -1,30 +0,0 @@
1−{-# LANGUAGE Rank2Types #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−import Network.Wai
4−import Network.Wai.Handler.Webkit
5−import qualified Data.ByteString.Char8 as B8
6−import qualified Network.Wai.Source as Source
7−
8−main :: IO ()
9−main = putStrLn "http://localhost:3000/" >> run "3000" app
10−
11−app :: Application
12−app req = case B8.unpack $ pathInfo req of
13− "/post/" -> postResponse $ Source.toEnumerator $ requestBody req
14− _ -> indexResponse
15−
16−indexResponse :: IO Response
17−indexResponse = return Response
18− { status = status200
19− , responseHeaders = [("Content-Type" , B8.pack "text/html")]
20− , responseBody = index
21− }
22−
23−postResponse :: Enumerator -> IO Response
24−postResponse rb = return Response
25− { status = status200
26− , responseHeaders = [("Content-Type", B8.pack "text/plain")]
27− , responseBody = ResponseEnumerator rb
28− }
29−
30−index = ResponseFile "index.html"
index.html → webkit-sample/index.htmlrenamed

The content is the same.

webkit-sample/webkit-sample.hsnew file+30
@@ -0,0 +1,30 @@
1+{-# LANGUAGE Rank2Types #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+import Network.Wai
4+import Network.Wai.Handler.Webkit
5+import Data.ByteString (ByteString)
6+import qualified Data.ByteString.Lazy as L
7+import Data.Enumerator (consume, Iteratee)
8+import Blaze.ByteString.Builder (fromLazyByteString)
9+
10+main :: IO ()
11+main = putStrLn "http://localhost:3000/" >> run "Webkit Sample" app
12+
13+app :: Application
14+app req = case pathInfo req of
15+ "/post/" -> do
16+ bss <- consume
17+ postResponse $ L.fromChunks bss
18+ _ -> indexResponse
19+
20+indexResponse :: Iteratee ByteString IO Response
21+indexResponse = return $ ResponseFile
22+ status200
23+ [("Content-Type" , "text/html")]
24+ "index.html"
25+
26+postResponse :: L.ByteString -> Iteratee ByteString IO Response
27+postResponse lbs = return $ ResponseBuilder
28+ status200
29+ [("Content-Type", "text/plain")]
30+ (fromLazyByteString lbs)