| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
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
- data UseDefaultHeaders
- knownMethods :: [Method]
- type Method = String
- robustSettings :: ManagerSettings
- customMethodWith :: String -> Options -> String -> IO (Response ByteString)
- customPayloadMethodWith :: Postable a => String -> Options -> String -> a -> IO (Response ByteString)
- defaults :: Options
- headers :: Lens' Options [Header]
- responseBody :: forall body0 body1 f. Functor f => (body0 -> f body1) -> Response body0 -> f (Response body1)
- responseHeader :: HeaderName -> Traversal' (Response body) ByteString
- type Header = (HeaderName, ByteString)
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
knownMethods :: [Method] Source #
Lifted from https:/en.wikipedia.orgw/index.php?title=Hypertext_Transfer_Protocol&oldid=954964381#Request_methods
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.~0customMethodWith"PATCH" opts "http://httpbin.org/patch"
>>>let opts = defaults & redirects .~ 0>>>r <- customMethodWith "PATCH" opts "http://httpbin.org/patch">>>r ^. responseStatus . statusCode200
customPayloadMethodWith :: Postable a => String -> Options -> String -> a -> IO (Response ByteString) #
Issue a custom-method request with a payload, using the supplied Options.
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)
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")