http2-manager-0.0.1: Managed connection pool for HTTP2
Safe HaskellSafe-Inferred
LanguageHaskell2010

HTTP2.Client.Manager.Internal

Synopsis

Documentation

type Port = Int Source #

data Request Source #

Constructors

Request 

Fields

  • request :: Request

    The request to be sent.

  • responseConsumer :: Response -> IO ()

    Consumer for the response, must not exit until the response body is completely consumed.

    The response consumer has to return 'IO ()' because we want to processes different requests on one connection and run ties the return type of response consumer to the return type of itself. Even if the response consumer returned something else we would need another empty MVar to write the result, this is being dealt with in sendRequestWithConnection.

  • exceptionMVar :: MVar SomeException

    There are exceptions which cannot be communicated in a continuation becasue they can be raised even before the continuation starts. We also need a way to communicate any exceptions raised by the continuation itself. This MVar will be written to in any of those cases.

data Http2Manager Source #

FUTUREWORK: Support HTTPS, perhaps ALPN negotiation can also be used to HTTP1. I think HTTP1 vs HTTP2 can not be negotated without TLS, so perhaps this manager will default to HTTP2.

Constructors

Http2Manager 

setCacheLimit :: Int -> Http2Manager -> Http2Manager Source #

Warning: This won't affect already established connections

setSSLContext :: SSLContext -> Http2Manager -> Http2Manager Source #

Warning: This won't affect already established connections

setSSLRemoveTrailingDot :: Bool -> Http2Manager -> Http2Manager Source #

Remove traling dots in hostname while verifying hostname in the certificate presented by the server. For instance, when connecting with 'foo.example.com.' (Note the trailing dot) by default most SSL libraries fail hostname verification if the server has a certificate for 'foo.example.com' (Note the lack of a trailing dot). Setting this flag makes the hostname verification succeed for these hosts. However, this will make the hostname verification fail if the host presents a certificate which does have a trailing dot.

Discussion about why this is not implemented as a flag on SSLContext: https://github.com/openssl/openssl/issues/11560

Warning: This won't affect already established connections

sendRequestWithConnection :: HTTP2Conn -> Request -> (Response -> IO r) -> IO r Source #

Does not check whether connection is actually running. Users should use withHTTP2Request. This function is good for testing.

withHTTP2Request :: Http2Manager -> Target -> Request -> (Response -> IO a) -> IO a Source #

Make an HTTP2 request, if it is the first time the Http2Manager sees this target, it creates the connection and keeps it around for any subsequent requests. Subsequest requests try to use this connection, in case the connection is already dead (e.g. the background thread has finished), a new connection is created.

It is important that the continuation provided by the caller of this function consumes the response body completely before it returns.

NOTE: If many concurrent requests are made to the same server using a single instance of Http2Manager, it could cause the manager to make multiple connections to the server. Eventually only one connection will be kept open. This, in theory, would cause some contention over STM based Map that the Http2Manager keeps and so could decrease throughput. In cases where many concurrent requests are to be made, it might be best to ensure that a connection exists using connectIfNotAlreadyConnected before making all the requests.

connectIfNotAlreadyConnected :: Http2Manager -> Target -> IO () Source #

Connects to a server if it is not already connected, useful when making many concurrent requests. This way the first few requests don't have to fight for making a connection This way the first few requests don't have to fight for making a connection.

getOrMakeConnection :: Http2Manager -> Target -> IO HTTP2Conn Source #

Gets a connection if it exists and is alive, otherwise connects to the given Target.

getConnection :: Http2Manager -> Target -> STM (Maybe HTTP2Conn) Source #

Removes connection from map if it is not alive anymore

disconnectTarget :: Http2Manager -> Target -> IO () Source #

Disconnects HTTP2 connection if there exists one. Will hang around until all the ongoing requests complete. This would throw an error if the background thread maintaining the connection throws an error, e.g. there was a TLS error or the connection was already disconnected with error.

disconnectTargetWithTimeout :: Http2Manager -> Target -> Int -> IO () Source #

Disconnects HTTP2 connection if there exists one. If the background thread running the connection does not finish within 1 second, it is canceled. Errors from the background thread running the connection are not propagated.

NOTE: Any requests in progress might not finish correctly.

startPersistentHTTP2Connection Source #

Arguments

:: SSLContext 
-> Target 
-> Int 
-> Bool 
-> Int

TCP connect timeout in microseconds

-> MVar ConnectionAction 
-> IO () 

type SendReqFn = Request -> (Response -> IO ()) -> IO () Source #

data TLSParams Source #

Constructors

TLSParams