1 module Network.HTTP.Lucu.Request
4 , requestP -- Parser Request
8 import qualified Data.ByteString.Lazy.Char8 as B
9 import Data.ByteString.Lazy.Char8 (ByteString)
10 import Network.HTTP.Lucu.Headers
11 import Network.HTTP.Lucu.HttpVersion
12 import Network.HTTP.Lucu.Parser
13 import Network.HTTP.Lucu.Parser.Http
24 | ExtensionMethod String
32 , reqVersion :: HttpVersion
33 , reqHeaders :: Headers
37 instance HasHeaders Request where
38 getHeaders = reqHeaders
39 setHeaders req hdr = req { reqHeaders = hdr }
42 requestP :: Parser Request
43 requestP = do many crlf
44 (method, uri, version) <- requestLineP
49 , reqVersion = version
50 , reqHeaders = headers
54 requestLineP :: Parser (Method, URI, HttpVersion)
55 requestLineP = do method <- methodP
61 return (method, uri, ver)
64 methodP :: Parser Method
65 methodP = (let methods = [ ("OPTIONS", OPTIONS)
70 , ("DELETE" , DELETE )
72 , ("CONNECT", CONNECT)
74 in foldl (<|>) (fail "") $ map (\ (str, mth)
75 -> string str >> return mth) methods)
77 token >>= return . ExtensionMethod
81 uriP = do str <- many1 $ satisfy (\ c -> not (isCtl c || c == ' '))
82 case parseURIReference str of
84 Just uri -> return uri