Safe Haskell | None |
---|---|
Language | Haskell2010 |
Network.HTTP2.Internal
Synopsis
- type FileOffset = Int64
- type ByteCount = Int64
- type PositionReadMaker = FilePath -> IO (PositionRead, Sentinel)
- type PositionRead = FileOffset -> ByteCount -> Buffer -> IO ByteCount
- data 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 ())
- | OutBodyStreamingUnmask ((forall x. IO x -> IO x) -> (Builder -> IO ()) -> IO () -> IO ())
- | OutBodyBuilder Builder
- | OutBodyFile FileSpec
- data FileSpec = FileSpec FilePath FileOffset ByteCount
- data Next = Next BytesFilled Bool (Maybe DynaNext)
- type BytesFilled = Int
- type DynaNext = Buffer -> BufferSize -> WindowSize -> IO Next
- data StreamingChunk
- = StreamingFinished (IO ())
- | StreamingFlush
- | StreamingBuilder Builder
- 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
- data Manager
- type Action = IO ()
- start :: Manager -> IO Manager
- setAction :: Manager -> Action -> IO ()
- stopAfter :: Manager -> IO a -> (Either SomeException a -> IO b) -> IO b
- spawnAction :: Manager -> IO ()
- forkManaged :: Manager -> IO () -> IO ()
- forkManagedUnmask :: Manager -> ((forall x. IO x -> IO x) -> IO ()) -> IO ()
- timeoutKillThread :: Manager -> (Handle -> IO a) -> IO a
- timeoutClose :: Manager -> IO () -> IO (IO ())
- data KilledByHttp2ThreadManager = KilledByHttp2ThreadManager (Maybe SomeException)
- incCounter :: Manager -> IO ()
- decCounter :: Manager -> IO ()
- waitCounter0 :: Manager -> IO ()
File
type FileOffset = Int64 Source #
Offset for file.
type PositionReadMaker = FilePath -> IO (PositionRead, Sentinel) Source #
Making a position read and its closer.
type PositionRead = FileOffset -> ByteCount -> Buffer -> IO ByteCount Source #
Position read for files.
Manipulating a file resource.
defaultPositionReadMaker :: PositionReadMaker Source #
Position read based on Handle
.
Types
Request and response
Input object
Constructors
InpObj | |
Fields
|
Output object
Constructors
OutObj | |
Fields
|
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 This is used in the client: we spawn the new thread for the request body
with exceptions masked, and provide the body of 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
|
OutBodyBuilder Builder | |
OutBodyFile FileSpec |
Sender
type BytesFilled = Int Source #
type DynaNext = Buffer -> BufferSize -> WindowSize -> IO Next Source #
data StreamingChunk Source #
Constructors
StreamingFinished (IO ()) | |
StreamingFlush | |
StreamingBuilder Builder |
fillBuilderBodyGetNext :: Builder -> DynaNext 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.
Constructors
NextTrailersMaker TrailersMaker | |
Trailers [Header] |
runTrailersMaker :: TrailersMaker -> Buffer -> Int -> IO NextTrailersMaker Source #
Running trailers-maker.
bufferIO buf siz $ \bs -> tlrmkr (Just bs)
Thread Manager
start :: Manager -> IO Manager Source #
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.
stopAfter :: Manager -> IO a -> (Either SomeException a -> IO b) -> IO b Source #
Stopping the manager.
spawnAction :: Manager -> IO () Source #
Spawning the action.
forkManaged :: Manager -> IO () -> IO () Source #
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 () Source #
Like forkManaged
, but run action with exceptions masked
timeoutKillThread :: Manager -> (Handle -> IO a) -> IO a Source #
Killing the IO action of the second argument on timeout.
timeoutClose :: Manager -> IO () -> IO (IO ()) Source #
Registering closer for a resource and returning a timer refresher.
data KilledByHttp2ThreadManager Source #
Constructors
KilledByHttp2ThreadManager (Maybe SomeException) |
Instances
Exception KilledByHttp2ThreadManager Source # | |
Defined in Network.HTTP2.H2.Manager Methods toException :: KilledByHttp2ThreadManager -> SomeException fromException :: SomeException -> Maybe KilledByHttp2ThreadManager displayException :: KilledByHttp2ThreadManager -> String | |
Show KilledByHttp2ThreadManager Source # | |
Defined in Network.HTTP2.H2.Manager Methods showsPrec :: Int -> KilledByHttp2ThreadManager -> ShowS show :: KilledByHttp2ThreadManager -> String showList :: [KilledByHttp2ThreadManager] -> ShowS |
incCounter :: Manager -> IO () Source #
decCounter :: Manager -> IO () Source #
waitCounter0 :: Manager -> IO () Source #