1 {-# OPTIONS_HADDOCK prune #-}
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 Network.HTTP.Lucu.Headers
14 import Network.HTTP.Lucu.HttpVersion
15 import Network.HTTP.Lucu.Parser
16 import Network.HTTP.Lucu.Parser.Http
19 -- |This is the definition of HTTP request methods, which shouldn't
20 -- require any description.
29 | ExtensionMethod !String
32 -- |This is the definition of HTTP reqest.
37 , reqVersion :: !HttpVersion
38 , reqHeaders :: !Headers
42 instance HasHeaders Request where
43 getHeaders = reqHeaders
44 setHeaders req hdr = req { reqHeaders = hdr }
47 requestP :: Parser Request
48 requestP = do _ <- many crlf
49 (method, uri, version) <- requestLineP
54 , reqVersion = version
55 , reqHeaders = headers
59 requestLineP :: Parser (Method, URI, HttpVersion)
60 requestLineP = do method <- methodP
66 return (method, uri, ver)
69 methodP :: Parser Method
70 methodP = ( let methods = [ ("OPTIONS", OPTIONS)
75 , ("DELETE" , DELETE )
77 , ("CONNECT", CONNECT)
79 in choice $ map (\ (str, mth)
80 -> string str >> return mth) methods )
82 fmap ExtensionMethod token
86 uriP = do str <- many1 $ satisfy (\ c -> not (isCtl c || c == ' '))
87 case parseURIReference str of
89 Just uri -> return uri