streamly-http: A small HTTP/1.1 client written with Streamly

[ bsd3, library, network, streamly, web ] [ Propose Tags ] [ Report a vulnerability ]

An HTTP/1.1 client over plain TCP. The response head is read with flatparse parsers and the body is a stream of byte arrays, whether it is delimited by Content-Length, by the chunked transfer coding or by the end of the connection. Waits and sizes are limited; sessions and clients keep connections from one request to the next. No TLS and no redirects here: requests also go over a transport of the caller, which is how streamly-http-tls adds both.


[Skip to Readme]

Modules

  • Streamly
    • External
      • Network
        • Streamly.External.Network.HTTP
          • Streamly.External.Network.HTTP.URL
          • Streamly.External.Network.HTTP.Wire

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.19 && <4.22), bytestring (>=0.12 && <0.13), containers (>=0.6.7 && <0.8), flatparse (>=0.5 && <0.6), network (>=3.2 && <3.3), streamly-bytestring (>=0.2.3 && <0.3), streamly-core (>=0.3.3 && <0.4), streamly-flatparse (>=0.1 && <0.2), streamly-network-tcp (>=0.1 && <0.2) [details]
Tested with ghc ==9.8.4 || ==9.10.3 || ==9.12.4
License BSD-3-Clause
Author Xavier Dectot
Maintainer Xavier Dectot <xavier@wheredoibegin.fr>
Uploaded by GdeVolpiano at 2026-11-28T10:31:48Z
Category Network, Web, Streamly
Home page https://github.com/GuillaumedeVolpiano/streamly-http
Source repo head: git clone https://github.com/GuillaumedeVolpiano/streamly-http.git
Distributions
Reverse Dependencies 4 direct, 0 indirect [details]
Downloads 0 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2026-11-28 [all 1 reports]

Readme for streamly-http-0.1.0.0

[back to package description]

streamly-http

A small HTTP/1.1 client written with Streamly. The response head is read with flatparse parsers; the body is a stream of byte arrays, whether it is delimited by Content-Length, by the chunked transfer coding or by the end of the connection.

{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}

import Streamly.Data.Fold qualified as F (length)
import Streamly.Data.Stream (fold)
import Streamly.External.Network.HTTP (Response (..), fetch, get, header,
                                       withResponse)

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

  -- The body as a stream, read while the connection is open.
  arrays <- withResponse (get "example.org" 80 "/") $ \streamed ->
    fold F.length streamed.body
  print arrays

Several requests to one server

import Streamly.External.Network.HTTP (Response (..), defaultLimits, fetchIn,
                                       get, withSession)

main :: IO ()
main = withSession defaultLimits "example.org" 80 $ \session -> do
  first <- fetchIn session (get "example.org" 80 "/a")
  second <- fetchIn session (get "example.org" 80 "/b")
  print (first.status, second.status)

The connection is kept when the body was read to its end, its length was announced or it was chunked, and the server did not ask to close. A connection that the server has closed while idle is replaced without a word: the request is sent again once, unless its body is a stream.

For several servers, withClient keeps a session for each, and more than one for a server whose requests overlap:

main :: IO ()
main = withClient defaultLimits $ \client -> do
  first <- fetchFrom client Http (get "example.org" 80 "/a")
  second <- fetchFrom client Http (get "example.net" 80 "/b")
  print (first.status, second.status)

Modules

  • Streamly.External.Network.HTTP: the client over TCP (get, fetch, withResponse).
  • Streamly.External.Network.HTTP.Wire: the message format alone (renderRequest, readResponse), to run it over another transport. It also reads the head of a request, for the servers of protocols that start with an HTTP exchange.
  • Streamly.External.Network.HTTP.URL: http and https URLs, read, written back and resolved against one another.

Limits of this version

  • TLS is not built in. withResponseOver and fetchOver take a connection opened by other means, as a Transport: one of streamly-network-tls gives HTTPS.
  • One connection per request (Connection: close), unless the requests go through a session: withSession keeps the connection to a server for the next request when the response allows it.
  • Redirects are not followed and content codings are not decoded.
  • A request names its host, its port and its target. URLs are read by Streamly.External.Network.HTTP.URL; fetching by URL, with the scheme choosing between TCP and TLS, is what streamly-http-tls adds.
  • Limits bounds each wait (thirty seconds to connect, thirty seconds of silence by default) and the head of a response (64 KiB by default). The whole exchange is not bounded: use System.Timeout.timeout. The body is not either by default: set maxBodySize when the server is not trusted.
  • A status is never an error: look at status.

Building

To build against copies of streamly-network-tcp and streamly-flatparse checked out next to this repository, pass --project-file=cabal.project.siblings.