HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehttp-semantics-0.3.0Haskell2010

Network.HTTP.Semantics.IO

  • 12 types
  • 7 values

Naive implementation for readN.

NOTE: This function is intended to be used by a single thread only. (It is probably quite rare anyway to want concurrent reads from the same network socket.)

datadata Sentinel
#

Constructors

  • Closer (IO ())

    Closing a file resource. Its refresher is automatiaclly generated by the internal timer.

  • Refresher (IO ())

    Refreshing a file resource while reading. Closing the file must be done by its own timer or something.

typetype DynaNext = Buffer -> Int -> IO Next
#

Write part of a streaming response to the write buffer

In http2 this will be used to construct a single HTTP2 DATA frame (see discussion of the maximum number of bytes, below).

typetype CleanupStream = IO ()
#

Action to run prior to terminating the stream

Trailers maker. A chunks of the response body is passed with Just. The maker should update internal state with the ByteString and return the next trailers maker. When response body reaches its end, Nothing is passed and the maker should generate trailers. An example:

{-# LANGUAGE BangPatterns #-}
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as C8
import Crypto.Hash (Context, SHA1) -- cryptonite
import qualified Crypto.Hash as CH

-- Strictness is important for Context.
trailersMaker :: Context SHA1 -> Maybe ByteString -> IO NextTrailersMaker
trailersMaker ctx Nothing = return $ Trailers [("X-SHA1", sha1)]
  where
    !sha1 = C8.pack $ show $ CH.hashFinalize ctx
trailersMaker ctx (Just bs) = return $ NextTrailersMaker $ trailersMaker ctx'
  where
    !ctx' = CH.hashUpdate ctx bs

Usage example:

let h2rsp = responseFile ...
    maker = trailersMaker (CH.hashInit :: Context SHA1)
    h2rsp' = setResponseTrailersMaker h2rsp maker