http-client-0.1.0.0: An HTTP client engine, intended as a base layer for more user-friendly packages.

Safe HaskellNone

Network.HTTP.Client

Synopsis

Documentation

httpRaw :: Request -> Manager -> IO (Response BodyReader)Source

Get a Response without any redirect following.

responseOpen :: Request -> Manager -> IO (Response BodyReader)Source

The most low-level function for initiating an HTTP request.

The first argument to this function gives a full specification on the request: the host to connect to, whether to use SSL, headers, etc. Please see Request for full details. The second argument specifies which Manager should be used.

This function then returns a Response with a Source. The Response contains the status code and headers that were sent back to us, and the Source contains the body of the request. Note that this Source allows you to have fully interleaved IO actions during your HTTP download, making it possible to download very large responses in constant memory. You may also directly connect the returned Source into a Sink, perhaps a file or another socket.

An important note: the response body returned by this function represents a live HTTP connection. As such, if you do not use the response body, an open socket will be retained until the containing ResourceT block exits. If you do not need the response body, it is recommended that you explicitly shut down the connection immediately, using the pattern:

 responseBody res $$+- return ()

As a more thorough example, consider the following program. Without the explicit response body closing, the program will run out of file descriptors around the 1000th request (depending on the operating system limits).

 import Control.Monad          (replicateM_)
 import Control.Monad.IO.Class (liftIO)
 import Data.Conduit           (($$+-))
 import Network                (withSocketsDo)
 import Network.HTTP.Conduit

 main = withSocketsDo $ withManager $ \manager -> do
     req <- parseUrl "http://localhost/"
     mapM_ (worker manager req) [1..5000]

 worker manager req i = do
     res <- http req manager
     responseBody res $$+- return () -- The important line
     liftIO $ print (i, responseStatus res)

Note: Unlike previous versions, this function will perform redirects, as specified by the redirectCount setting.

applyCheckStatus :: (Status -> ResponseHeaders -> CookieJar -> Maybe SomeException) -> Response BodyReader -> IO (Maybe SomeException)Source

Apply 'Request'\'s checkStatus and return resulting exception if any.

httpRedirectSource

Arguments

:: Int

redirectCount

-> (Request -> IO (Response BodyReader, Maybe Request))

function which performs a request and returns a response, and possibly another request if there's a redirect.

-> Request 
-> IO (Response BodyReader) 

Redirect loop