@@ -11,6 +11,14 @@ module Network.Wai
11 , HttpVersion (..)
11 , HttpVersion (..)
12 , httpVersionFromBS
12 , httpVersionFromBS
13 , httpVersionToBS
13 , httpVersionToBS
14+ -- ** Request header names
16+ , requestHeaderFromBS
18+ -- ** Response header names
19+ , ResponseHeader (..)
20+ , responseHeaderFromBS
14 -- ** Response status code
22 -- ** Response status code
15 , Status (..)
23 , Status (..)
16 , statusCode
24 , statusCode
@@ -73,6 +81,7 @@ data HttpVersion =
75 | HttpVersion B.ByteString
83 | HttpVersion B.ByteString
77httpVersionFromBS :: B.ByteString -> HttpVersion
86httpVersionFromBS :: B.ByteString -> HttpVersion
78httpVersionFromBS bs
87httpVersionFromBS bs
@@ -89,6 +98,92 @@ httpVersionToBS Http10 = B8.pack "1.0"
89httpVersionToBS Http11 = B8.pack "1.1"
98httpVersionToBS Http11 = B8.pack "1.1"
90httpVersionToBS (HttpVersion bs) = bs
99httpVersionToBS (HttpVersion bs) = bs
112+ | RequestHeader B.ByteString
115+instance Eq RequestHeader where
116+ x == y = requestHeaderToBS x == requestHeaderToBS y
118+requestHeaderFromBS :: B.ByteString -> RequestHeader
119+requestHeaderFromBS bs = case B8.unpack bs of
121+ "Accept-Charset" -> AcceptCharset
122+ "Accept-Encoding" -> AcceptEncoding
123+ "Accept-Language" -> AcceptLanguage
124+ "Authorization" -> Authorization
126+ "Content-Length" -> ReqContentLength
127+ "Content-Type" -> ReqContentType
129+ "Referer" -> Referer
130+ _ -> RequestHeader bs
132+requestHeaderToBS :: RequestHeader -> B.ByteString
133+requestHeaderToBS Accept = B8.pack "Accept"
134+requestHeaderToBS AcceptCharset = B8.pack "Accept-Charset"
135+requestHeaderToBS AcceptEncoding = B8.pack "Accept-Encoding"
136+requestHeaderToBS AcceptLanguage = B8.pack "Accept-Language"
137+requestHeaderToBS Authorization = B8.pack "Authorization"
138+requestHeaderToBS Cookie = B8.pack "Cookie"
139+requestHeaderToBS ReqContentLength = B8.pack "Content-Length"
140+requestHeaderToBS ReqContentType = B8.pack "Content-Type"
141+requestHeaderToBS Host = B8.pack "Host"
142+requestHeaderToBS Referer = B8.pack "Referer"
143+requestHeaderToBS (RequestHeader bs) = bs
145+data ResponseHeader =
149+ | ContentDisposition
155+ | ResponseHeader B.ByteString
158+instance Eq ResponseHeader where
159+ x == y = responseHeaderToBS x == responseHeaderToBS y
162+responseHeaderFromBS :: B.ByteString -> ResponseHeader
163+responseHeaderFromBS bs = case B8.unpack bs of
164+ "Content-Encoding" -> ContentEncoding
165+ "Content-Language" -> ContentLanguage
166+ "Content-Length" -> ContentLength
167+ "Content-Disposition" -> ContentDisposition
168+ "Content-Type" -> ContentType
169+ "Expires" -> Expires
170+ "Location" -> Location
172+ "Set-Cookie" -> SetCookie
173+ _ -> ResponseHeader bs
175+responseHeaderToBS :: ResponseHeader -> B.ByteString
176+responseHeaderToBS ContentEncoding = B8.pack "Content-Encoding"
177+responseHeaderToBS ContentLanguage = B8.pack "Content-Language"
178+responseHeaderToBS ContentLength = B8.pack "Content-Length"
179+responseHeaderToBS ContentDisposition = B8.pack "Content-Disposition"
180+responseHeaderToBS ContentType = B8.pack "Content-Type"
181+responseHeaderToBS Expires = B8.pack "Expires"
182+responseHeaderToBS Location = B8.pack "Location"
183+responseHeaderToBS Server = B8.pack "Server"
184+responseHeaderToBS SetCookie = B8.pack "Set-Cookie"
185+responseHeaderToBS (ResponseHeader bs) = bs
92-- | This attempts to provide the most common HTTP status codes, not all of
187-- | This attempts to provide the most common HTTP status codes, not all of
93-- them. Use the 'Status' constructor when you want to create a status code not
188-- them. Use the 'Status' constructor when you want to create a status code not
94-- provided.
189-- provided.
@@ -145,7 +240,7 @@ data Request = Request
145 , queryString :: B.ByteString
240 , queryString :: B.ByteString
146 , serverName :: B.ByteString
241 , serverName :: B.ByteString
147 , serverPort :: Int
242 , serverPort :: Int
148− , httpHeaders :: [(B.ByteString, B.ByteString)]
243+ , httpHeaders :: [(RequestHeader, B.ByteString)]
149 , urlScheme :: UrlScheme
244 , urlScheme :: UrlScheme
150 , requestBody :: IO (Maybe B.ByteString)
245 , requestBody :: IO (Maybe B.ByteString)
151 , errorHandler :: String -> IO ()
246 , errorHandler :: String -> IO ()
@@ -154,7 +249,7 @@ data Request = Request
155data Response = Response
250data Response = Response
156 { status :: Status
251 { status :: Status
157− , headers :: [(B.ByteString, B.ByteString)]
252+ , headers :: [(ResponseHeader, B.ByteString)]
158 , body :: Either FilePath ((B.ByteString -> IO ()) -> IO ())
253 , body :: Either FilePath ((B.ByteString -> IO ()) -> IO ())