Last active
June 27, 2017 16:37
Revisions
-
aaronlevin revised this gist
Nov 30, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,6 @@ application req continuation = _ -> continuation (responseLBS status401 [] "ERROR") main :: IO () main = run 8080 application -
aaronlevin created this gist
Nov 30, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ {-# LANGUAGE OverloadedStrings #-} module Main where import Network.Wai (pathInfo, Request, requestMethod, Response, responseLBS, ResponseReceived) import Network.Wai.Handler.Warp (run) import Network.HTTP.Types (status200, status401) -- note: type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived application :: Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived application req continuation = let method = requestMethod req path = pathInfo req in case (method, path) of ("GET", ["hello" , "world"]) -> continuation (responseLBS status200 [] "!") _ -> continuation (responseLBS status401 [] "ERROR") main :: IO () main = run 8080 application {- $ curl -iXGET 'localhost:8080/hello/world' HTTP/1.1 200 OK Transfer-Encoding: chunked Date: Wed, 30 Nov 2016 10:33:23 GMT Server: Warp/3.2.8 ! $ curl -iXGET 'localhost:8080/hello/wd' HTTP/1.1 401 Unauthorized Transfer-Encoding: chunked Date: Wed, 30 Nov 2016 10:33:29 GMT Server: Warp/3.2.8 ERROR $ curl -iXGET 'localhost:8080/hel' HTTP/1.1 401 Unauthorized Transfer-Encoding: chunked Date: Wed, 30 Nov 2016 10:33:34 GMT Server: Warp/3.2.8 ERROR -}