5 {-# OPTIONS_HADDOCK prune #-}
7 -- |Definition of things related on HTTP request.
9 -- In general you don't have to use this module directly.
10 module Network.HTTP.Lucu.Request
16 import Control.Applicative
17 import Control.Monad.Unicode
18 import Data.Ascii (Ascii)
19 import Data.Attoparsec.Char8
20 import qualified Data.ByteString.Char8 as C8
21 import Network.HTTP.Lucu.Headers
22 import Network.HTTP.Lucu.HttpVersion
23 import Network.HTTP.Lucu.Parser.Http
25 import Prelude.Unicode
27 -- |This is the definition of HTTP request methods, which shouldn't
28 -- require any description.
37 | ExtensionMethod !Ascii
40 -- |This is the definition of HTTP reqest.
45 , reqVersion ∷ !HttpVersion
46 , reqHeaders ∷ !Headers
50 instance HasHeaders Request where
51 getHeaders = reqHeaders
52 setHeaders req hdr = req { reqHeaders = hdr }
54 requestP ∷ Parser Request
55 requestP = do skipMany crlf
56 (method, uri, version) ← requestLineP
61 , reqVersion = version
62 , reqHeaders = headers
65 requestLineP ∷ Parser (Method, URI, HttpVersion)
66 requestLineP = do method ← methodP
72 return (method, uri, ver)
74 methodP ∷ Parser Method
76 [ string "OPTIONS" ≫ return OPTIONS
77 , string "GET" ≫ return GET
78 , string "HEAD" ≫ return HEAD
79 , string "POST" ≫ return POST
80 , string "PUT" ≫ return PUT
81 , string "DELETE" ≫ return DELETE
82 , string "TRACE" ≫ return TRACE
83 , string "CONNECT" ≫ return CONNECT
84 , ExtensionMethod <$> token
89 do bs ← takeWhile1 (\c → (¬) (isCtl c ∨ c ≡ '\x20'))
90 let str = C8.unpack bs
91 case parseURIReference str of
92 Nothing -> fail ("Unparsable URI: " ⧺ str)
93 Just uri -> return uri