Safe Haskell | None |
---|---|
Language | Haskell2010 |
- type Attendant = PushAction -> PullAction -> CloseAction -> IO ()
- type PullAction = IO ByteString
- type PushAction = ByteString -> IO ()
- type CloseAction = IO ()
- data IOProblem
- data GenericIOProblem
- tlsServeWithALPN :: FilePath -> FilePath -> String -> [(String, Attendant)] -> Int -> IO ()
- tlsServeWithALPNAndFinishOnRequest :: FilePath -> FilePath -> String -> [(String, Attendant)] -> Int -> MVar FinishRequest -> IO ()
- enableConsoleLogging :: IO ()
- data TLSLayerGenericProblem = TLSLayerGenericProblem String
- data FinishRequest = FinishRequest
Callbacks
These callback make possible to separate the parts in layers.
The Attendant
is a function that can push and pull bytes to/from
a transport (for example, a socket), but it is not concerned on how
those bytes are pushed or pulled.
type Attendant = PushAction -> PullAction -> CloseAction -> IO () Source
A function which takes three arguments: the first one says how to send data (on a socket or similar transport), and the second one how to receive data on said socket. The third argument encapsulates the sequence of steps needed for a clean shutdown.
You can implement one of these to let somebody else supply the push, pull and close callbacks. In this library we supply callbacks for TLS sockets, so that you don't need to go through the drudgery of managing those yourself.
Attendants encapsulate all the session book-keeping functionality,
which for HTTP/2 is quite complicated. You use the function http2Attendant
to create one of these from a CoherentWorker
.
type PullAction = IO ByteString Source
Callback type to pull data from a channel. The same as to PushAction applies to exceptions thrown from there.
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 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.
Throw exceptions derived from this (e.g, GenericIOProblem
below)
to have the HTTP/2 session to terminate gracefully.
data GenericIOProblem Source
A concrete case of the above exception. Throw one of this
if you don't want to implement your own type. Use
IOProblem
in catch signatures.
High level OpenSSL functions.
Use these functions to create your TLS-compliant HTTP/2 server in a snap.
:: FilePath | Path to a certificate the server is going to use to identify itself. Bear in mind that multiple domains can be served from the same HTTP/2 TLS socket, so please create the HTTP/2 certificate accordingly. |
-> FilePath | Path to the key of your certificate. |
-> String | Name of the network interface where you want to start your server |
-> [(String, Attendant)] | List of protocol names and the corresponding |
-> Int | Port to open to listen for connections. |
-> IO () |
Simple function to open
tlsServeWithALPNAndFinishOnRequest Source
:: FilePath | |
-> FilePath | Same as for |
-> String | Same as for |
-> [(String, Attendant)] | Same as for |
-> Int | Same as for |
-> MVar FinishRequest | Finish request, write a value here to finish serving |
-> IO () |
Interruptible version of tlsServeWithALPN
. Use the extra argument to ask
the server to finish: you pass an empty MVar and when you want to finish you
just populate it.
enableConsoleLogging :: IO () Source
Activates logging to terminal
data TLSLayerGenericProblem Source
Exception inheriting from IOProblem
. This is thrown by the
OpenSSL subsystem to signal that the connection was broken or that
otherwise there was a problem at the SSL layer.
data FinishRequest Source
Singleton type. Used in conjunction with an MVar
. If the MVar is full,
the fuction tlsServeWithALPNAndFinishOnRequest
knows that it should finish
at its earliest convenience and call the CloseAction
for any open sessions.