]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Request.hs
Code reorganisation
[Lucu.git] / Network / HTTP / Lucu / Request.hs
index 13ccf9c9420b8265fa244934ed2d98cebc1a497f..ea855ba30cffc108ac7764766196b63a03ff8ce0 100644 (file)
@@ -6,9 +6,7 @@
   , UnicodeSyntax
   , ViewPatterns
   #-}
--- |Definition of things related on HTTP request.
---
--- In general you don't have to use this module directly.
+-- |Definition of HTTP requests.
 module Network.HTTP.Lucu.Request
     ( Method(..)
     , Request(..)
@@ -27,8 +25,7 @@ import Network.HTTP.Lucu.Parser.Http
 import Network.URI
 import Prelude.Unicode
 
--- |This is the definition of HTTP request methods, which shouldn't
--- require any descriptions.
+-- |Definition of HTTP request methods.
 data Method = OPTIONS
             | GET
             | HEAD
@@ -40,7 +37,7 @@ data Method = OPTIONS
             | ExtensionMethod !Ascii
               deriving (Eq, Show)
 
--- |This is the definition of an HTTP reqest.
+-- |Definition of HTTP requests.
 data Request
     = Request {
         reqMethod  ∷ !Method
@@ -64,6 +61,20 @@ reqHasBody (reqMethod → m)
     | m ≡ PUT   = True
     | otherwise = False
 
+instance Default (Parser Method) where
+    {-# INLINEABLE def #-}
+    def = choice
+          [ string "OPTIONS" ≫ return OPTIONS
+          , string "GET"     ≫ return GET
+          , string "HEAD"    ≫ return HEAD
+          , string "POST"    ≫ return POST
+          , string "PUT"     ≫ return PUT
+          , string "DELETE"  ≫ return DELETE
+          , string "TRACE"   ≫ return TRACE
+          , string "CONNECT" ≫ return CONNECT
+          , ExtensionMethod <$> token
+          ]
+
 instance Default (Parser Request) where
     {-# INLINEABLE def #-}
     def = do skipMany crlf
@@ -78,7 +89,7 @@ instance Default (Parser Request) where
 
 requestLine ∷ Parser (Method, URI, HttpVersion)
 {-# INLINEABLE requestLine #-}
-requestLine = do meth ← method
+requestLine = do meth ← def
                  sp
                  u ← uri
                  sp
@@ -86,20 +97,6 @@ requestLine = do meth ← method
                  crlf
                  return (meth, u, ver)
 
-method ∷ Parser Method
-{-# INLINEABLE method #-}
-method = choice
-         [ string "OPTIONS" ≫ return OPTIONS
-         , string "GET"     ≫ return GET
-         , string "HEAD"    ≫ return HEAD
-         , string "POST"    ≫ return POST
-         , string "PUT"     ≫ return PUT
-         , string "DELETE"  ≫ return DELETE
-         , string "TRACE"   ≫ return TRACE
-         , string "CONNECT" ≫ return CONNECT
-         , ExtensionMethod <$> token
-         ]
-
 uri ∷ Parser URI
 {-# INLINEABLE uri #-}
 uri = do bs ← takeWhile1 (\c → (¬) (isCtl c ∨ c ≡ '\x20'))