Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type FileOffset = Int64
- type ByteCount = Int64
- type PositionRead = FileOffset -> ByteCount -> Buffer -> IO ByteCount
- data Sentinel
- type PositionReadMaker = FilePath -> IO ( PositionRead , Sentinel )
- defaultPositionReadMaker :: PositionReadMaker
- type Scheme = ByteString
- type Authority = ByteString
- type Path = ByteString
-
data
InpObj
=
InpObj
{
- inpObjHeaders :: HeaderTable
- inpObjBodySize :: Maybe Int
- inpObjBody :: InpBody
- inpObjTrailers :: IORef ( Maybe HeaderTable )
- type InpBody = IO ByteString
-
data
OutObj
=
OutObj
{
- outObjHeaders :: [ Header ]
- outObjBody :: OutBody
- outObjTrailers :: TrailersMaker
-
data
OutBody
- = OutBodyNone
- | OutBodyStreaming (( Builder -> IO ()) -> IO () -> IO ())
- | OutBodyBuilder Builder
- | OutBodyFile FileSpec
- data FileSpec = FileSpec FilePath FileOffset ByteCount
- data Next = Next BytesFilled ( Maybe DynaNext )
- type BytesFilled = Int
- type DynaNext = Buffer -> BufferSize -> WindowSize -> IO Next
- data StreamingChunk
- fillBuilderBodyGetNext :: Builder -> DynaNext
- fillFileBodyGetNext :: PositionRead -> FileOffset -> ByteCount -> IO () -> DynaNext
- fillStreamBodyGetNext :: IO ( Maybe StreamingChunk ) -> DynaNext
- type TrailersMaker = Maybe ByteString -> IO NextTrailersMaker
- defaultTrailersMaker :: TrailersMaker
-
data
NextTrailersMaker
- = NextTrailersMaker TrailersMaker
- | Trailers [ Header ]
- runTrailersMaker :: TrailersMaker -> Buffer -> Int -> IO NextTrailersMaker
File
type FileOffset = Int64 Source #
Offset for file.
type PositionRead = FileOffset -> ByteCount -> Buffer -> IO ByteCount Source #
Position read for files.
Manipulating a file resource.
type PositionReadMaker = FilePath -> IO ( PositionRead , Sentinel ) Source #
Making a position read and its closer.
defaultPositionReadMaker :: PositionReadMaker Source #
Position read based on
Handle
.
Types
type Scheme = ByteString Source #
"http" or "https".
type Authority = ByteString Source #
For so-called "Host:" header.
type Path = ByteString Source #
Path.
Request and response
Input object
InpObj | |
|
type InpBody = IO ByteString Source #
Output object
OutObj | |
|
OutBodyNone | |
OutBodyStreaming (( Builder -> IO ()) -> IO () -> IO ()) |
Streaming body takes a write action and a flush action. |
OutBodyBuilder Builder | |
OutBodyFile FileSpec |
Sender
type BytesFilled = Int Source #
type DynaNext = Buffer -> BufferSize -> WindowSize -> IO Next Source #
fillFileBodyGetNext :: PositionRead -> FileOffset -> ByteCount -> IO () -> DynaNext Source #
fillStreamBodyGetNext :: IO ( Maybe StreamingChunk ) -> DynaNext Source #
Trailer
type TrailersMaker = Maybe ByteString -> IO NextTrailersMaker Source #
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
defaultTrailersMaker :: TrailersMaker Source #
TrailersMake to create no trailers.
data NextTrailersMaker Source #
Either the next trailers maker or final trailers.
runTrailersMaker :: TrailersMaker -> Buffer -> Int -> IO NextTrailersMaker Source #
Running trailers-maker.
bufferIO buf siz $ \bs -> tlrmkr (Just bs)