@@ -1,7 +1,17 @@
1{-# LANGUAGE ExistentialQuantification #-}
1{-# LANGUAGE ExistentialQuantification #-}
2module Network.Wai
2module Network.Wai
3− ( RequestMethod (..)
5+ RequestMethod (..)
8+ -- ** URL scheme (http versus https)
4 , UrlScheme (..)
9 , UrlScheme (..)
10+ -- ** HTTP protocol versions
5 , Request (..)
15 , Request (..)
6 , Response (..)
16 , Response (..)
7 , Application
17 , Application
@@ -12,22 +22,75 @@ module Network.Wai
13import qualified Data.ByteString.Lazy as L
23import qualified Data.ByteString.Lazy as L
14import qualified Data.ByteString as B
24import qualified Data.ByteString as B
25+import qualified Data.ByteString.Char8 as B8
27+-- | Please do not use the Show and Read instances for anything other than
28+-- debugging purposes. Instead, the 'methodFromBS' and 'methodToBS' provide a
29+-- more appropriate interface.
16data RequestMethod =
30data RequestMethod =
24− | CONNECT
38+ | CONNECT
39+ | OtherMethod B.ByteString
25 deriving (Show, Read, Eq)
40 deriving (Show, Read, Eq)
42+methodFromBS :: B.ByteString -> RequestMethod
44+ | B.length bs <= 7 = case B8.unpack bs of
54+ | otherwise = OtherMethod bs
56+methodToBS :: RequestMethod -> B.ByteString
57+methodToBS OPTIONS = B8.pack "OPTIONS"
58+methodToBS GET = B8.pack "GET"
59+methodToBS HEAD = B8.pack "HEAD"
60+methodToBS POST = B8.pack "POST"
61+methodToBS PUT = B8.pack "PUT"
62+methodToBS DELETE = B8.pack "DELETE"
63+methodToBS TRACE = B8.pack "TRACE"
64+methodToBS CONNECT = B8.pack "CONNECT"
65+methodToBS (OtherMethod bs) = bs
27data UrlScheme = HTTP | HTTPS deriving (Show, Eq)
67data UrlScheme = HTTP | HTTPS deriving (Show, Eq)
69+-- | The value of HttpVersion should be the information trailing HTTP/.
74+ | HttpVersion B.ByteString
76+httpVersionFromBS :: B.ByteString -> HttpVersion
78+ | B.length bs == 3 = case B8.unpack bs of
83+ | otherwise = HttpVersion bs
85+httpVersionToBS :: HttpVersion -> B.ByteString
86+httpVersionToBS Http09 = B8.pack "0.9"
87+httpVersionToBS Http10 = B8.pack "1.0"
88+httpVersionToBS Http11 = B8.pack "1.1"
89+httpVersionToBS (HttpVersion bs) = bs
29data Request = Request
91data Request = Request
30 { requestMethod :: RequestMethod
92 { requestMethod :: RequestMethod
93+ , httpVersion :: HttpVersion
31 , pathInfo :: B.ByteString
94 , pathInfo :: B.ByteString
32 , queryString :: B.ByteString
95 , queryString :: B.ByteString
33 , serverName :: B.ByteString
96 , serverName :: B.ByteString