3 -- |Definition of things related on HTTP request.
5 -- In general you don't have to use this module directly.
6 module Network.HTTP.Lucu.Request
13 import qualified Data.ByteString.Lazy.Char8 as B
14 import Data.ByteString.Lazy.Char8 (ByteString)
15 import Network.HTTP.Lucu.Headers
16 import Network.HTTP.Lucu.HttpVersion
17 import Network.HTTP.Lucu.Parser
18 import Network.HTTP.Lucu.Parser.Http
21 -- |This is the definition of HTTP request methods, which shouldn't
22 -- require any description.
31 | ExtensionMethod !String
34 -- |This is the definition of HTTP reqest.
39 , reqVersion :: !HttpVersion
40 , reqHeaders :: !Headers
44 instance HasHeaders Request where
45 getHeaders = reqHeaders
46 setHeaders req hdr = req { reqHeaders = hdr }
49 requestP :: Parser Request
50 requestP = do many crlf
51 (method, uri, version) <- requestLineP
56 , reqVersion = version
57 , reqHeaders = headers
61 requestLineP :: Parser (Method, URI, HttpVersion)
62 requestLineP = do method <- methodP
68 return (method, uri, ver)
71 methodP :: Parser Method
72 methodP = (let methods = [ ("OPTIONS", OPTIONS)
77 , ("DELETE" , DELETE )
79 , ("CONNECT", CONNECT)
81 in foldl (<|>) (fail "") $ map (\ (str, mth)
82 -> string str >> return mth) methods)
84 token >>= return . ExtensionMethod
88 uriP = do str <- many1 $ satisfy (\ c -> not (isCtl c || c == ' '))
89 case parseURIReference str of
91 Just uri -> return uri