packages feed

streamly-http-tls-0.1.0.0: README.md

# streamly-http-tls

Fetch `http` and `https` URLs with
[Streamly](https://streamly.composewell.com/). This is the convenient face
of [streamly-http](https://hackage.haskell.org/package/streamly-http):
give a URL, get the response. The scheme chooses between plain TCP and TLS
(through
[streamly-network-tls](https://hackage.haskell.org/package/streamly-network-tls)),
and redirects are followed.

```haskell
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}

import Streamly.Data.Fold qualified as F (length)
import Streamly.Data.Stream (fold)
import Streamly.External.Network.HTTP (Response (..), header)
import Streamly.External.Network.HTTP.TLS (fetchUrl, withUrl)

main :: IO ()
main = do
  -- The whole response in memory.
  response <- fetchUrl "https://example.org/"
  print (response.status, header "content-type" response)

  -- The body as a stream, read while the connection is open.
  arrays <- withUrl "https://example.org/" $ \streamed ->
    fold F.length streamed.body
  print arrays
```

## What it does

- `fetchUrl` and `withUrl` send a `GET` request and follow the redirects
  (statuses 301, 302, 303, 307 and 308 with a `Location`), ten at most.
- `fetchUrlWith` and `withUrlWith` take `Options`: the certificates
  trusted for `https`, the limits of time and size, the number of
  redirects, and headers for every
  request. When a redirect leads to another host, `Authorization`,
  `Proxy-Authorization` and `Cookie` are left out.
- `withResponseAt` sends one request of any method, with any body, in
  clear or over TLS, without following redirects.
- `withSecureClient` keeps the connections to every server from one URL
  to the next: `fetchUrlIn` and `withUrlIn` fetch through it. Without a
  client, each call opens its connections and closes them; the redirects
  of one call to the same server still share one.
- `withSessionAt` keeps one connection to a server, in clear or over TLS,
  for several requests (`fetchIn` and `withResponseIn` of streamly-http):
  over TLS it spares a handshake for each request after the first.

## Limits of this version

- Those of streamly-http: no content coding decoded, a status is never an
  error.
- Each wait is limited, and so is the head of a response (`limits` in
  `Options`). The whole exchange is not: use `System.Timeout.timeout`. The
  body is not either by default: set `maxBodySize` when the server is not
  trusted.
- No proxy, no cookie jar.

## Building

To build against copies of
[streamly-http](https://hackage.haskell.org/package/streamly-http) and
[streamly-network-tls](https://hackage.haskell.org/package/streamly-network-tls)
checked out next to this repository, pass
`--project-file=cabal.project.siblings`.