33-- Module : Network.HTTP
44-- Copyright : See LICENSE file
55-- License : BSD
6- --
6+ --
77-- Maintainer : Ganesh Sittampalam <[email protected] > 88-- Stability : experimental
99-- Portability : non-portable (not tested)
2727-- namespace, letting you either use the default implementation here
2828-- by importing @Network.HTTP@ or, for more specific uses, selectively
2929-- import the modules in @Network.HTTP.*@. To wit, more than one kind of
30- -- representation of the bulk data that flows across a HTTP connection is
30+ -- representation of the bulk data that flows across a HTTP connection is
3131-- supported. (see "Network.HTTP.HandleStream".)
32- --
32+ --
3333-- /NOTE:/ The 'Request' send actions will normalize the @Request@ prior to transmission.
3434-- Normalization such as having the request path be in the expected form and, possibly,
3535-- introduce a default @Host:@ header if one isn't already present.
3636-- Normalization also takes the @"user:pass\@"@ portion out of the the URI,
3737-- if it was supplied, and converts it into @Authorization: Basic$ header.
38- -- If you do not
38+ -- If you do not
3939-- want the requests tampered with, but sent as-is, please import and use the
4040-- the "Network.HTTP.HandleStream" or "Network.HTTP.Stream" modules instead. They
41- -- export the same functions, but leaves construction and any normalization of
41+ -- export the same functions, but leaves construction and any normalization of
4242-- @Request@s to the user.
4343--
4444-- /NOTE:/ This package only supports HTTP; it does not support HTTPS.
4545-- Attempts to use HTTPS result in an error.
4646-----------------------------------------------------------------------------
47- module Network.HTTP
47+ module Network.HTTP
4848 ( module Network.HTTP.Base
4949 , module Network.HTTP.Headers
5050
51- {- the functionality that the implementation modules,
52- Network.HTTP.HandleStream and Network.HTTP.Stream,
53- exposes:
54- -}
51+ {- the functionality that the implementation modules,
52+ Network.HTTP.HandleStream and Network.HTTP.Stream,
53+ exposes:
54+ -}
5555 , simpleHTTP -- :: Request -> IO (Result Response)
5656 , simpleHTTP_ -- :: Stream s => s -> Request -> IO (Result Response)
5757 , sendHTTP -- :: Stream s => s -> Request -> IO (Result Response)
@@ -60,12 +60,12 @@ module Network.HTTP
6060 , respondHTTP -- :: Stream s => s -> Response -> IO ()
6161
6262 , module Network.TCP
63-
63+
6464 , getRequest -- :: String -> Request_String
6565 , headRequest -- :: String -> Request_String
6666 , postRequest -- :: String -> Request_String
6767 , postRequestWithBody -- :: String -> String -> String -> Request_String
68-
68+
6969 , getResponseBody -- :: Result (Request ty) -> IO ty
7070 , getResponseCode -- :: Result (Request ty) -> IO ResponseCode
7171 ) where
@@ -109,10 +109,10 @@ simpleHTTP r = do
109109 c <- openStream (host auth) (fromMaybe 80 (port auth))
110110 let norm_r = normalizeRequest defaultNormalizeRequestOptions{normDoClose= True } r
111111 simpleHTTP_ c norm_r
112-
112+
113113-- | Identical to 'simpleHTTP', but acting on an already opened stream.
114114simpleHTTP_ :: HStream ty => HandleStream ty -> Request ty -> IO (Result (Response ty ))
115- simpleHTTP_ s r = do
115+ simpleHTTP_ s r = do
116116 let norm_r = normalizeRequest defaultNormalizeRequestOptions{normDoClose= True } r
117117 S. sendHTTP s norm_r
118118
@@ -121,7 +121,7 @@ simpleHTTP_ s r = do
121121-- closed upon receiving the response.
122122sendHTTP :: HStream ty => HandleStream ty -> Request ty -> IO (Result (Response ty ))
123123sendHTTP conn rq = do
124- let norm_r = normalizeRequest defaultNormalizeRequestOptions rq
124+ let norm_r = normalizeRequest defaultNormalizeRequestOptions rq
125125 S. sendHTTP conn norm_r
126126
127127-- | @sendHTTP_notify hStream httpRequest action@ behaves like 'sendHTTP', but
@@ -134,7 +134,7 @@ sendHTTP_notify :: HStream ty
134134 -> IO ()
135135 -> IO (Result (Response ty ))
136136sendHTTP_notify conn rq onSendComplete = do
137- let norm_r = normalizeRequest defaultNormalizeRequestOptions rq
137+ let norm_r = normalizeRequest defaultNormalizeRequestOptions rq
138138 S. sendHTTP_notify conn norm_r onSendComplete
139139
140140-- | @receiveHTTP hStream@ reads a 'Request' from the 'HandleStream' @hStream@
@@ -154,7 +154,7 @@ respondHTTP conn rsp = S.respondHTTP conn rsp
154154getRequest
155155 :: String -- ^ URL to fetch
156156 -> Request_String -- ^ The constructed request
157- getRequest urlString =
157+ getRequest urlString =
158158 case parseURI urlString of
159159 Nothing -> error (" getRequest: Not a valid URL - " ++ urlString)
160160 Just u -> mkRequest GET u
@@ -165,7 +165,7 @@ getRequest urlString =
165165headRequest
166166 :: String -- ^ URL to fetch
167167 -> Request_String -- ^ The constructed request
168- headRequest urlString =
168+ headRequest urlString =
169169 case parseURI urlString of
170170 Nothing -> error (" headRequest: Not a valid URL - " ++ urlString)
171171 Just u -> mkRequest HEAD u
@@ -176,7 +176,7 @@ headRequest urlString =
176176postRequest
177177 :: String -- ^ URL to POST to
178178 -> Request_String -- ^ The constructed request
179- postRequest urlString =
179+ postRequest urlString =
180180 case parseURI urlString of
181181 Nothing -> error (" postRequest: Not a valid URL - " ++ urlString)
182182 Just u -> mkRequest POST u
@@ -193,7 +193,7 @@ postRequestWithBody
193193 -> String -- ^ Content-Type of body
194194 -> String -- ^ The body of the request
195195 -> Request_String -- ^ The constructed request
196- postRequestWithBody urlString typ body =
196+ postRequestWithBody urlString typ body =
197197 case parseURI urlString of
198198 Nothing -> error (" postRequestWithBody: Not a valid URL - " ++ urlString)
199199 Just u -> setRequestBody (mkRequest POST u) (typ, body)
@@ -222,29 +222,29 @@ getResponseCode (Right r) = return (rspCode r)
222222-- - comm timeouts
223223-- - MIME & entity stuff (happening in separate module)
224224-- - support \"*\" uri-request-string for OPTIONS request method
225- --
226- --
225+ --
226+ --
227227-- * Header notes:
228228--
229229-- [@Host@]
230230-- Required by HTTP\/1.1, if not supplied as part
231231-- of a request a default Host value is extracted
232232-- from the request-uri.
233- --
234- -- [@Connection@]
233+ --
234+ -- [@Connection@]
235235-- If this header is present in any request or
236236-- response, and it's value is "close", then
237- -- the current request\/response is the last
237+ -- the current request\/response is the last
238238-- to be allowed on that connection.
239- --
239+ --
240240-- [@Expect@]
241241-- Should a request contain a body, an Expect
242242-- header will be added to the request. The added
243243-- header has the value \"100-continue\". After
244244-- a 417 \"Expectation Failed\" response the request
245245-- is attempted again without this added Expect
246246-- header.
247- --
247+ --
248248-- [@TransferEncoding,ContentLength,...@]
249249-- if request is inconsistent with any of these
250250-- header values then you may not receive any response
@@ -257,7 +257,7 @@ getResponseCode (Right r) = return (rspCode r)
257257-- [@1xx@] \"100 Continue\" will cause any unsent request body to be sent.
258258-- \"101 Upgrade\" will be returned.
259259-- Other 1xx responses are ignored.
260- --
260+ --
261261-- [@417@] The reason for this code is \"Expectation failed\", indicating
262262-- that the server did not like the Expect \"100-continue\" header
263263-- added to a request. Receipt of 417 will induce another
0 commit comments