stack-1.9.3.1: The Haskell Tool Stack

Safe HaskellNone
LanguageHaskell2010

Network.HTTP.StackClient

Description

Wrapper functions of Simple and Client to add the 'User-Agent' HTTP request header to each request.

Synopsis

Documentation

withResponse :: (MonadUnliftIO m, MonadIO n) => Request -> (Response (ConduitM i ByteString n ()) -> m a) -> m a Source #

setRequestMethod :: ByteString -> Request -> Request #

Set the request method

Since: http-conduit-2.1.10

setRequestHeader :: HeaderName -> [ByteString] -> Request -> Request #

Set the given request header to the given list of values. Removes any previously set header values with the same name.

Since: http-conduit-2.1.10

addRequestHeader :: HeaderName -> ByteString -> Request -> Request #

Add a request header name/value combination

Since: http-conduit-2.1.10

setRequestBody :: RequestBody -> Request -> Request #

Set the request body to the given RequestBody. You may want to consider using one of the convenience functions in the modules, e.g. requestBodyJSON.

Note: This will not modify the request method. For that, please use requestMethod. You likely don't want the default of GET.

Since: http-conduit-2.1.10

setRequestManager :: Manager -> Request -> Request #

Instead of using the default global Manager, use the supplied Manager.

Since: http-conduit-2.1.10

getResponseHeaders :: Response a -> [(HeaderName, ByteString)] #

Get all response headers

Since: http-conduit-2.1.10

getResponseBody :: Response a -> a #

Get the response body

Since: http-conduit-2.1.10

getResponseStatusCode :: Response a -> Int #

Get the integral status code of the response

Since: http-conduit-2.1.10

responseHeaders :: Response body -> ResponseHeaders #

Response headers sent by the server.

Since 0.1.0

responseStatus :: Response body -> Status #

Status code of the response.

Since 0.1.0

responseBody :: Response body -> body #

Response body sent by the server.

Since 0.1.0

parseRequest :: MonadThrow m => String -> m Request #

Convert a URL into a Request.

This function defaults some of the values in Request, such as setting method to GET and requestHeaders to [].

Since this function uses MonadThrow, the return monad can be anything that is an instance of MonadThrow, such as IO or Maybe.

You can place the request method at the beginning of the URL separated by a space, e.g.:

@@ parseRequest "POST http://httpbin.org/post" @@

Note that the request method must be provided as all capital letters.

A Request created by this function won't cause exceptions on non-2XX response status codes.

To create a request which throws on non-2XX status codes, see parseUrlThrow

Since: http-client-0.4.30

parseRequest_ :: String -> Request #

Same as parseRequest, but parse errors cause an impure exception. Mostly useful for static strings which are known to be correctly formatted.

defaultRequest :: Request #

A default request value, a GET request of localhost/:80, with an empty request body.

Note that the default checkResponse does nothing.

Since: http-client-0.4.30

setUri :: MonadThrow m => Request -> URI -> m Request #

Validate a URI, then add it to the request.

getUri :: Request -> URI #

Extract a URI from the request.

Since 0.1.0

path :: Request -> ByteString #

Everything from the host to the query string.

Since 0.1.0

checkResponse :: Request -> Request -> Response BodyReader -> IO () #

Check the response immediately after receiving the status and headers. This can be useful for throwing exceptions on non-success status codes.

In previous versions of http-client, this went under the name checkStatus, but was renamed to avoid confusion about the new default behavior (doing nothing).

Since: http-client-0.5.0

parseUrlThrow :: MonadThrow m => String -> m Request #

Same as parseRequest, except will throw an HttpException in the event of a non-2XX response. This uses throwErrorStatusCodes to implement checkResponse.

Since: http-client-0.4.30

requestHeaders :: Request -> RequestHeaders #

Custom HTTP request headers

The Content-Length and Transfer-Encoding headers are set automatically by this module, and shall not be added to requestHeaders.

If not provided by the user, Host will automatically be set based on the host and port fields.

Moreover, the Accept-Encoding header is set implicitly to gzip for convenience by default. This behaviour can be overridden if needed, by setting the header explicitly to a different value. In order to omit the Accept-Header altogether, set it to the empty string "". If you need an empty Accept-Header (i.e. requesting the identity encoding), set it to a non-empty white-space string, e.g. " ". See RFC 2616 section 14.3 for details about the semantics of the Accept-Header field. If you request a content-encoding not supported by this module, you will have to decode it yourself (see also the decompress field).

Note: Multiple header fields with the same field-name will result in multiple header fields being sent and therefore it's the responsibility of the client code to ensure that the rules from RFC 2616 section 4.2 are honoured.

Since 0.1.0

getGlobalManager :: IO Manager #

Get the current global Manager

Since: http-client-tls-0.2.4

applyDigestAuth #

Arguments

:: (MonadIO m, MonadThrow n) 
=> ByteString

username

-> ByteString

password

-> Request 
-> Manager 
-> m (n Request) 

Apply digest authentication to this request.

Note that this function will need to make an HTTP request to the server in order to get the nonce, thus the need for a Manager and to live in IO. This also means that the request body will be sent to the server. If the request body in the supplied Request can only be read once, you should replace it with a dummy value.

In the event of successfully generating a digest, this will return a Just value. If there is any problem with generating the digest, it will return Nothing.

Since: http-client-tls-0.3.1

displayDigestAuthException :: DigestAuthException -> String #

User friendly display of a DigestAuthException

Since: http-client-tls-0.3.3

data Request #

All information on how to connect to a host and what should be sent in the HTTP request.

If you simply wish to download from a URL, see parseRequest.

The constructor for this data type is not exposed. Instead, you should use either the defaultRequest value, or parseRequest to construct from a URL, and then use the records below to make modifications. This approach allows http-client to add configuration options without breaking backwards compatibility.

For example, to construct a POST request, you could do something like:

initReq <- parseRequest "http://www.example.com/path"
let req = initReq
            { method = "POST"
            }

For more information, please see http://www.yesodweb.com/book/settings-types.

Since 0.1.0

Instances
Show Request 
Instance details

Defined in Network.HTTP.Client.Types

data RequestBody #

When using one of the RequestBodyStream / RequestBodyStreamChunked constructors, you must ensure that the GivesPopper can be called multiple times. Usually this is not a problem.

The RequestBodyStreamChunked will send a chunked request body. Note that not all servers support this. Only use RequestBodyStreamChunked if you know the server you're sending to supports chunked request bodies.

Since 0.1.0

data Response body #

A simple representation of the HTTP response.

Since 0.1.0

Instances
Functor Response 
Instance details

Defined in Network.HTTP.Client.Types

Methods

fmap :: (a -> b) -> Response a -> Response b #

(<$) :: a -> Response b -> Response a #

Foldable Response 
Instance details

Defined in Network.HTTP.Client.Types

Methods

fold :: Monoid m => Response m -> m #

foldMap :: Monoid m => (a -> m) -> Response a -> m #

foldr :: (a -> b -> b) -> b -> Response a -> b #

foldr' :: (a -> b -> b) -> b -> Response a -> b #

foldl :: (b -> a -> b) -> b -> Response a -> b #

foldl' :: (b -> a -> b) -> b -> Response a -> b #

foldr1 :: (a -> a -> a) -> Response a -> a #

foldl1 :: (a -> a -> a) -> Response a -> a #

toList :: Response a -> [a] #

null :: Response a -> Bool #

length :: Response a -> Int #

elem :: Eq a => a -> Response a -> Bool #

maximum :: Ord a => Response a -> a #

minimum :: Ord a => Response a -> a #

sum :: Num a => Response a -> a #

product :: Num a => Response a -> a #

Traversable Response 
Instance details

Defined in Network.HTTP.Client.Types

Methods

traverse :: Applicative f => (a -> f b) -> Response a -> f (Response b) #

sequenceA :: Applicative f => Response (f a) -> f (Response a) #

mapM :: Monad m => (a -> m b) -> Response a -> m (Response b) #

sequence :: Monad m => Response (m a) -> m (Response a) #

Eq body => Eq (Response body) 
Instance details

Defined in Network.HTTP.Client.Types

Methods

(==) :: Response body -> Response body -> Bool #

(/=) :: Response body -> Response body -> Bool #

Show body => Show (Response body) 
Instance details

Defined in Network.HTTP.Client.Types

Methods

showsPrec :: Int -> Response body -> ShowS #

show :: Response body -> String #

showList :: [Response body] -> ShowS #

data Manager #

Keeps track of open connections for keep-alive.

If possible, you should share a single Manager between multiple threads and requests.

Since 0.1.0

Instances
HasHttpManager Manager 
Instance details

Defined in Network.HTTP.Client.Types

type Header = (HeaderName, ByteString) #

Header

type HeaderName = CI ByteString #

Header name

data HttpException #

An exception which may be generated by this library

Since: http-client-0.5.0

Constructors

HttpExceptionRequest Request HttpExceptionContent

Most exceptions are specific to a Request. Inspect the HttpExceptionContent value for details on what occurred.

Since: http-client-0.5.0

data HttpExceptionContent #

Constructors

StatusCodeException (Response ()) ByteString

Generated by the parseUrlThrow function when the server returns a non-2XX response status code.

May include the beginning of the response body.

Since: http-client-0.5.0

methodPut :: Method #

HTTP Method constants.

ok200 :: Status #

OK 200

partialContent206 :: Status #

Partial Content 206

data Proxy #

Define a HTTP proxy, consisting of a hostname and port number.

Instances
Eq Proxy 
Instance details

Defined in Network.HTTP.Client.Types

Methods

(==) :: Proxy -> Proxy -> Bool #

(/=) :: Proxy -> Proxy -> Bool #

Ord Proxy 
Instance details

Defined in Network.HTTP.Client.Types

Methods

compare :: Proxy -> Proxy -> Ordering #

(<) :: Proxy -> Proxy -> Bool #

(<=) :: Proxy -> Proxy -> Bool #

(>) :: Proxy -> Proxy -> Bool #

(>=) :: Proxy -> Proxy -> Bool #

max :: Proxy -> Proxy -> Proxy #

min :: Proxy -> Proxy -> Proxy #

Read Proxy 
Instance details

Defined in Network.HTTP.Client.Types

Show Proxy 
Instance details

Defined in Network.HTTP.Client.Types

Methods

showsPrec :: Int -> Proxy -> ShowS #

show :: Proxy -> String #

showList :: [Proxy] -> ShowS #

useProxy :: Proxy -> ProxyOverride #

Use the given proxy settings, regardless of the proxy value in the Request.

Since 0.4.7

noProxy :: ProxyOverride #

Never connect using a proxy, regardless of the proxy value in the Request.

Since 0.4.7

proxyEnvironment #

Arguments

:: Maybe Proxy

fallback if no environment set

-> ProxyOverride 

Get the proxy settings from the default environment variable (http_proxy for insecure, https_proxy for secure). If no variable is set, then fall back to the given value. Nothing is equivalent to noProxy, Just is equivalent to useProxy.

Since 0.4.7

managerSetProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings #

Set the proxy override value, for both HTTP (insecure) and HTTPS (insecure) connections.

Since 0.4.7

formDataBody :: MonadIO m => [Part] -> Request -> m Request #

Add form data to the Request.

This sets a new requestBody, adds a content-type request header and changes the method to POST.

partFileRequestBody #

Arguments

:: Applicative m 
=> Text

Name of the corresponding <input>.

-> FilePath

File name to supply to the server.

-> RequestBody

Data to upload.

-> PartM m 

Construct a Part from form name, filepath and a RequestBody

partFileRequestBody "who_calls" "caller.json" $ RequestBodyBS "{\"caller\":\"Jason J Jason\"}"
-- empty upload form
partFileRequestBody "file" mempty mempty

The Part does not have a content type associated with it.

partBS #

Arguments

:: Applicative m 
=> Text

Name of the corresponding <input>.

-> ByteString

The body for this Part.

-> PartM m 

Make a Part whose content is a strict ByteString.

The Part does not have a file name or content type associated with it.

partLBS #

Arguments

:: Applicative m 
=> Text

Name of the corresponding <input>.

-> ByteString

The body for this Part.

-> PartM m 

Make a Part whose content is a lazy ByteString.

The Part does not have a file name or content type associated with it.