http2-4.2.2: HTTP/2 library
Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.HTTP2.Internal

Synopsis

File

type FileOffset = Int64 #

Offset for file.

type ByteCount = Int64 #

How many bytes to read

type PositionRead = FileOffset -> ByteCount -> Buffer -> IO ByteCount #

Position read for files.

data Sentinel #

Manipulating a file resource.

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.

type PositionReadMaker = FilePath -> IO (PositionRead, Sentinel) #

Making a position read and its closer.

Types

type Scheme = ByteString #

"http" or "https".

type Authority = ByteString #

Authority.

type Path = ByteString #

Path.

Request and response

data InpObj #

Input object

Constructors

InpObj 

Fields

Instances

Instances details
Show InpObj # 
Instance details

Defined in Network.HTTP2.Arch.Types

Methods

showsPrec :: Int -> InpObj -> ShowS

show :: InpObj -> String

showList :: [InpObj] -> ShowS

type InpBody = IO ByteString #

data OutObj #

Output object

Constructors

OutObj 

Fields

Instances

Instances details
Show OutObj # 
Instance details

Defined in Network.HTTP2.Arch.Types

Methods

showsPrec :: Int -> OutObj -> ShowS

show :: OutObj -> String

showList :: [OutObj] -> ShowS

data OutBody #

Constructors

OutBodyNone 
OutBodyStreaming ((Builder -> IO ()) -> IO () -> IO ())

Streaming body takes a write action and a flush action.

OutBodyStreamingUnmask ((forall x. IO x -> IO x) -> (Builder -> IO ()) -> IO () -> IO ())

Like OutBodyStreaming, but with a callback to unmask expections

This is used in the client: we spawn the new thread for the request body with exceptions masked, and provide the body of OutBodyStreamingUnmask with a callback to unmask them again (typically after installing an exception handler).

We do NOT support this in the server, as here the scope of the thread that is spawned for the server is the entire handler, not just the response streaming body.

TODO: The analogous change for the server-side would be to provide a similar unmask callback as the first argument in the Server type alias.

OutBodyBuilder Builder 
OutBodyFile FileSpec 

data FileSpec #

File specification.

Constructors

FileSpec FilePath FileOffset ByteCount 

Instances

Instances details
Show FileSpec # 
Instance details

Defined in Network.HTTP2.Arch.Types

Methods

showsPrec :: Int -> FileSpec -> ShowS

show :: FileSpec -> String

showList :: [FileSpec] -> ShowS

Eq FileSpec # 
Instance details

Defined in Network.HTTP2.Arch.Types

Methods

(==) :: FileSpec -> FileSpec -> Bool

(/=) :: FileSpec -> FileSpec -> Bool

Sender

data Next #

Constructors

Next BytesFilled Bool (Maybe DynaNext) 

type BytesFilled = Int #

Trailer

type TrailersMaker = Maybe ByteString -> IO NextTrailersMaker #

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 #

TrailersMake to create no trailers.

data NextTrailersMaker #

Either the next trailers maker or final trailers.

runTrailersMaker :: TrailersMaker -> Buffer -> Int -> IO NextTrailersMaker #

Running trailers-maker.

bufferIO buf siz $ \bs -> tlrmkr (Just bs)

Thread Manager

data Manager #

Manager to manage the thread and the timer.

type Action = IO () #

Action to be spawned by the manager.

start :: Manager -> IO Manager #

Starting a thread manager. Its action is initially set to 'return ()' and should be set by setAction. This allows that the action can include the manager itself.

setAction :: Manager -> Action -> IO () #

Setting the action to be spawned.

stopAfter :: Manager -> IO a -> (Either SomeException a -> IO b) -> IO b #

Stopping the manager.

spawnAction :: Manager -> IO () #

Spawning the action.

forkManaged :: Manager -> IO () -> IO () #

Fork managed thread

This guarantees that the thread ID is added to the manager's queue before the thread starts, and is removed again when the thread terminates (normally or abnormally).

forkManagedUnmask :: Manager -> ((forall x. IO x -> IO x) -> IO ()) -> IO () #

Like forkManaged, but run action with exceptions masked

timeoutKillThread :: Manager -> (Handle -> IO a) -> IO a #

Killing the IO action of the second argument on timeout.

timeoutClose :: Manager -> IO () -> IO (IO ()) #

Registering closer for a resource and returning a timer refresher.

incCounter :: Manager -> IO () #

decCounter :: Manager -> IO () #

waitCounter0 :: Manager -> IO () #