Safe Haskell | None |
---|---|
Language | Haskell2010 |
- type PushAction = ByteString -> IO ()
- type PullAction = Int -> IO ByteString
- type BestEffortPullAction = Bool -> IO ByteString
- type Attendant = IOCallbacks -> IO ()
- type CloseAction = IO ()
- data IOCallbacks = IOCallbacks {}
- pushAction_IOC :: Lens' IOCallbacks PushAction
- pullAction_IOC :: Lens' IOCallbacks PullAction
- closeAction_IOC :: Lens' IOCallbacks CloseAction
- bestEffortPullAction_IOC :: Lens' IOCallbacks BestEffortPullAction
- getHeaderFromFlatList :: Headers -> ByteString -> Maybe ByteString
- nullFooter :: Source IO ByteString -> DataAndConclusion
- type HeaderName = ByteString
- type HeaderValue = ByteString
- type Header = (HeaderName, HeaderValue)
- type Headers = [Header]
- type FinalizationHeaders = Headers
- data Request = Request {}
- type Footers = FinalizationHeaders
- data Perception = Perception {}
- data Effect = Effect {}
- type AwareWorker = Request -> IO PrincipalStream
- data PrincipalStream = PrincipalStream {}
- type PushedStreams = [IO PushedStream]
- data PushedStream = PushedStream {}
- type DataAndConclusion = ConduitM () ByteString IO Footers
- type CoherentWorker = TupledRequest -> IO TupledPrincipalStream
- type InputDataStream = Source IO ByteString
- type TupledPrincipalStream = (Headers, PushedStreams, DataAndConclusion)
- type TupledRequest = (Headers, Maybe InputDataStream)
- type FragmentDeliveryCallback = Int -> TimeSpec -> IO ()
- data InterruptEffect
- headers_RQ :: Lens' Request Headers
- inputData_RQ :: Lens' Request (Maybe InputDataStream)
- perception_RQ :: Lens' Request Perception
- headers_PS :: Lens' PrincipalStream Headers
- pushedStreams_PS :: Lens' PrincipalStream PushedStreams
- dataAndConclusion_PS :: Lens' PrincipalStream DataAndConclusion
- dataAndConclusion_Psh :: Lens' PushedStream DataAndConclusion
- requestHeaders_Psh :: Lens' PushedStream Headers
- responseHeaders_Psh :: Lens' PushedStream Headers
- effect_PS :: Lens' PrincipalStream Effect
- startedTime_Pr :: Lens' Perception TimeSpec
- streamId_Pr :: Lens' Perception Int
- sessionId_Pr :: Lens' Perception Int
- anouncedProtocols_Pr :: Lens' Perception (Maybe [ByteString])
- protocol_Pr :: Lens' Perception HttpProtocolVersion
- fragmentDeliveryCallback_Ef :: Lens' Effect (Maybe FragmentDeliveryCallback)
- priorityEffect_Ef :: Lens' Effect (Maybe Int)
- interrupt_Ef :: Lens' Effect (Maybe InterruptEffect)
- defaultEffects :: Effect
- coherentToAwareWorker :: CoherentWorker -> AwareWorker
- tupledPrincipalStreamToPrincipalStream :: TupledPrincipalStream -> PrincipalStream
- requestToTupledRequest :: Request -> TupledRequest
- data HttpProtocolVersion
Documentation
type PushAction = ByteString -> IO () Source
Callback type to push data to a channel. Part of this interface is the abstract exception type IOProblem. Throw an instance of it from here to notify the session that the connection has been broken. There is no way to signal "normal termination", since HTTP/2's normal termination can be observed at a higher level when a GO_AWAY frame is seen.
type PullAction = Int -> IO ByteString Source
Callback type to pull data from a channel. The same as to PushAction applies to exceptions thrown from there. The first argument is the number of bytes to pull from the medium. Barring exceptions, we always know how many bytes we are expecting with HTTP/2.
type BestEffortPullAction = Bool -> IO ByteString Source
Callback type to pull data from a channel in a best-effort basis. When the first argument is True, the data-providing backend can block if the input buffers are empty and await for new data. Otherwise, it will return immediately with an empty ByteString
type Attendant = IOCallbacks -> IO () Source
This is an intermediate type. It represents what you obtain by combining something that speaks the protocol and an AwareWorker. In turn, you need to feed a bundle of callbacks implementing I/O to finally start a server.
You can implement one of these to let somebody else supply the
push, pull and close callbacks. For example, tlsServeWithALPN
will
supply these arguments to an Attendant
.
Attendants encapsulate all the session book-keeping functionality,
which for HTTP/2 is quite complicated. You use the functions
http**Attendant
to create one of these from a CoherentWorker
.
This library supplies two of such Attendant factories,
http11Attendant
for
HTTP 1.1 sessions, and http2Attendant
for HTTP/2 sessions.
type CloseAction = IO () Source
Callback that the session calls to realease resources associated with the channels. Take into account that your callback should be able to deal with non-clean shutdowns also, for example, if the connection to the remote peer is severed suddenly.
data IOCallbacks Source
A set of functions describing how to do I/O in a session. As usual, we provide lenses accessors.
IOCallbacks | |
|
getHeaderFromFlatList :: Headers -> ByteString -> Maybe ByteString Source
Gets a single header from the list
nullFooter :: Source IO ByteString -> DataAndConclusion Source
If you want to skip the footers, i.e., they are empty, use this function to convert an ordinary Source to a DataAndConclusion.
type HeaderName = ByteString Source
The name part of a header
type HeaderValue = ByteString Source
The value part of a header
type Header = (HeaderName, HeaderValue) Source
The complete header
type Headers = [Header] Source
List of headers. The first part of each tuple is the header name (be sure to conform to the HTTP/2 convention of using lowercase) and the second part is the headers contents. This list needs to include the special :method, :scheme, :authority and :path pseudo-headers for requests; and :status (with a plain numeric value represented in ascii digits) for responses.
type FinalizationHeaders = Headers Source
Finalization headers. If you don't know what they are, chances are that you don't need to worry about them for now. The support in this library for those are at best sketchy.
A request is a set of headers and a request body.... which will normally be empty, except for POST and PUT requests. But this library enforces none of that.
type Footers = FinalizationHeaders Source
Finalization headers
data Perception Source
Data related to the request
Perception | |
|
Sometimes a response needs to be handled a bit specially, for example by reporting delivery details back to the worker
Effect | |
|
type AwareWorker = Request -> IO PrincipalStream Source
Main type of this library. You implement one of these for your server. This is a callback that the library calls as soon as it has all the headers of a request. For GET requests that's the entire request basically, but for POST and PUT requests this is just before the data starts arriving to the server.
It is important that you consume the data in the cases where there is an input stream, otherwise the memory is lost for the duration of the request, and a malicious client can use that.
Also, notice that when handling requests your worker can be interrupted with
an asynchronous exception of type StreamCancelledException
, if the peer
cancels the stream
data PrincipalStream Source
You use this type to answer a request. The Headers
are thus response
headers and they should contain the :status pseudo-header. The PushedStreams
is a list of pushed streams... they will be pushed to the client.
type PushedStreams = [IO PushedStream] Source
A list of pushed streams. Notice that a list of IO computations is required here. These computations only happen when and if the streams are pushed to the client. The lazy nature of Haskell helps to avoid unneeded computations if the streams are not going to be sent to the client.
data PushedStream Source
A pushed stream, represented by a list of request headers, a list of response headers, and the usual response body (which may include final footers (not implemented yet)).
type DataAndConclusion = ConduitM () ByteString IO Footers Source
A source-like conduit with the data returned in the response. The return value of the conduit is a list of footers. For now that list can be anything (even bottom), I'm not handling it just yet.
type CoherentWorker = TupledRequest -> IO TupledPrincipalStream Source
A CoherentWorker is a simplified callback that you can implement to handle requests.
Then you can convert it to an AwareWorker with tupledPrincipalStreamToPrincipalStream
.
type InputDataStream = Source IO ByteString Source
This is a Source conduit (see Haskell Data.Conduit library from Michael Snoyman) that you can use to retrieve the data sent by the peer piece-wise.
type TupledPrincipalStream = (Headers, PushedStreams, DataAndConclusion) Source
A tuple representing the data alone that you usually need to give as a response, that is, the headers in the response (including the HTTP/2 :status), any pushed streams, a stream with the response data and the footers.
type TupledRequest = (Headers, Maybe InputDataStream) Source
A tuple representing the data alone usually needed to create a response. That is, the headers (including HTTP/2 :path, :authority, etc) and maybe an input data stream for requests that include it, that is, POST and PUT.
type FragmentDeliveryCallback = Int -> TimeSpec -> IO () Source
First argument is the ordinal of this data frame, second an approximation of when the frame was delivered, according to the monotonic clock. Do not linger in this call, it may delay some important thread
data InterruptEffect Source
Types of interrupt effects that can be signaled by aware workers. These include whole connection shutdowns and stream resets. In all the cases, the reason given will be NO_ERROR.
InterruptConnectionAfter_IEf | Close and send GoAway after this stream finishes delivery |
InterruptConnectionNow_IEf | Close and send GoAway without delivering this stream. This implies that other fields of the PrincipalStream record will be ignored. |InterruptThisStream_IEf -- ^ Just reset this stream, disabled for now. |
tupledPrincipalStreamToPrincipalStream :: TupledPrincipalStream -> PrincipalStream Source
Convert between the two types of callback.
data HttpProtocolVersion Source
The protocol version used. Here we distinguish only between HTTP1.1 and HTTP2