restman-0.7.7.0: Web request TUI program.
Safe HaskellNone
LanguageGHC2024

HTTP.Client

Description

Thin wrapper around wreq and http-client to provide a robust HTTP(S) connection manager and re-export the subset of wreq and http-types symbols used throughout RESTman.

The key entry point is robustSettings, which configures an ManagerSettings with a 30-second response timeout to prevent hangs on slow proxies or captive portals.

Note: The underlying http-client library has a hardcoded 8 KB limit per header line that cannot be configured in this version. Some sites (e.g. slashdot.org with its extensive Content-Security-Policy header listing hundreds of domains) may exceed this limit and will fail with an OverlongHeaders exception. This is a known limitation of the http-client library version in use.

Synopsis

HTTP.Client helpers

data UseDefaultHeaders Source #

Bool-ish (for now) with more descriptive names.

Constructors

ReplaceDefaultHeaders

Discard wreq's default headers; use only custom headers.

AppendCustomToDefaultHeaders

Keep wreq's default headers and append custom headers.

Instances

Instances details
Bounded UseDefaultHeaders Source # 
Instance details

Defined in HTTP.Client

Enum UseDefaultHeaders Source # 
Instance details

Defined in HTTP.Client

Read UseDefaultHeaders Source # 
Instance details

Defined in HTTP.Client

Show UseDefaultHeaders Source # 
Instance details

Defined in HTTP.Client

Eq UseDefaultHeaders Source # 
Instance details

Defined in HTTP.Client

Ord UseDefaultHeaders Source # 
Instance details

Defined in HTTP.Client

knownMethods :: [Method] Source #

Lifted from https:/en.wikipedia.orgw/index.php?title=Hypertext_Transfer_Protocol&oldid=954964381#Request_methods

type Method = String Source #

Helper type for clarity of intention.

robustSettings :: ManagerSettings Source #

TLS-enabled ManagerSettings with a 30-second response timeout.

Use this when creating an Manager for RESTman so that requests do not hang indefinitely on unresponsive proxies or captive portals.

manager <- HC.newManager robustSettings

wreq re-exports

customMethodWith :: String -> Options -> String -> IO (Response ByteString) #

Issue a custom request method request, using the supplied Options.

Example:

let opts = defaults & redirects .~ 0
customMethodWith "PATCH" opts "http://httpbin.org/patch"
 
>>> let opts = defaults & redirects .~ 0
>>> r <- customMethodWith "PATCH" opts "http://httpbin.org/patch"
>>> r ^. responseStatus . statusCode
200

customPayloadMethodWith :: Postable a => String -> Options -> String -> a -> IO (Response ByteString) #

Issue a custom-method request with a payload, using the supplied Options.

headers :: Lens' Options [Header] #

A lens onto all headers (there can legitimately be zero or more).

In this example, we print all the headers sent by default with every request.

print (defaults ^. headers)
 

responseBody :: forall body0 body1 f. Functor f => (body0 -> f body1) -> Response body0 -> f (Response body1) #

A lens onto the body of a response.

r <- get "http://httpbin.org/get"
print (r ^. responseBody)
 

responseHeader #

Arguments

:: HeaderName

Header name to match.

-> Traversal' (Response body) ByteString 

A lens onto all matching named headers in an HTTP response.

To access exactly one header (the result will be the empty string if there is no match), use the (^.) operator.

r <- get "http://httpbin.org/get"
print (r ^. responseHeader "Content-Type")
 

To access at most one header (the result will be Nothing if there is no match), use the (^?) operator.

r <- get "http://httpbin.org/get"
print (r ^? responseHeader "Content-Transfer-Encoding")
 

To access all (zero or more) matching headers, use the (^..) operator.

r <- get "http://httpbin.org/get"
print (r ^.. responseHeader "Set-Cookie")
 

http-types re-exports

type Header = (HeaderName, ByteString) #

A full HTTP header field with the name and value separated.

E.g. "Content-Length: 28" parsed into a Header would turn into ("Content-Length", "28")