Hoogle Search

Within LTS Haskell 24.63 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. managerIdleConnectionCount :: ManagerSettings -> Int

    http-client Network.HTTP.Client.Internal

    Total number of idle connection to keep open at a given time. This limit helps deal with the case where you are making a large number of connections to different hosts. Without this limit, you could run out of file descriptors. Additionally, it can be set to zero to prevent reuse of any connections. Doing this is useful when the server your application is talking to sits behind a load balancer. Default: 512 Since 0.3.7

  2. managerIdleConnectionCount :: ManagerSettings -> Int

    http-client Network.HTTP.Client.Internal

    Total number of idle connection to keep open at a given time. This limit helps deal with the case where you are making a large number of connections to different hosts. Without this limit, you could run out of file descriptors. Additionally, it can be set to zero to prevent reuse of any connections. Doing this is useful when the server your application is talking to sits behind a load balancer. Default: 512 Since 0.3.7

  3. requestManagerOverride :: Request -> Maybe Manager

    http-client Network.HTTP.Client.Internal

    A Manager value that should override whatever Manager value was passed in to the HTTP request function manually. This is useful when dealing with implicit global managers, such as in Network.HTTP.Simple

  4. runProxyOverride :: ProxyOverride -> Bool -> IO (Request -> Request)

    http-client Network.HTTP.Client.Internal

    No documentation available.

  5. validateHeaders :: RequestHeaders -> HeadersValidationResult

    http-client Network.HTTP.Client.Internal

    No documentation available.

  6. type Middleware = Application -> Application

    wai Network.Wai

    A Middleware is a component that sits between the server and application. It can modify both the Request and Response, to provide simple transformations that are required for all (or most of) your web server’s routes.

    Users of middleware

    If you are trying to apply one or more Middlewares to your Application, just call them as functions. For example, if you have corsMiddleware and authorizationMiddleware, and you want to authorize first, you can do:
    let allMiddleware app = authorizationMiddleware (corsMiddleware app)
    
    to get a new Middleware, which first authorizes, then sets, CORS headers. The “outer” middleware is called first. You can also chain them via (.):
    let allMiddleware =
    authorizationMiddleware
    . corsMiddleware
    . … more middleware here …
    
    Then, once you have an app :: Application, you can wrap it in your middleware:
    let myApp = allMiddleware app :: Application
    
    and run it as usual:
    Warp.run port myApp
    

    Authors of middleware

    When fully expanded, Middleware has the type signature:
    (Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived) -> Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
    
    or if we shorten to type Respond = Response -> IO ResponseReceived:
    (Request -> Respond -> IO ResponseReceived) -> Request -> Respond -> IO ResponseReceived
    
    so a middleware definition takes 3 arguments, an inner application, a request and a response callback. Compare with the type of a simple Application:
    Request -> Respond -> IO ResponseReceived
    
    It takes the Request and Respond, but not the extra application. Said differently, a middleware has the power of a normal Application — it can inspect the Request and return a Response — but it can (and in many cases it should) also call the Application which was passed to it.

    Modifying the Request

    A lot of middleware just looks at the request and does something based on its values. For example, the authorizationMiddleware from above could look at the Authorization HTTP header and run JWT verification logic against the database.
    authorizationMiddleware app req respond = do
    case verifyJWT (requestHeaders req) of
    InvalidJWT err -> respond (invalidJWTResponse err)
    ValidJWT -> app req respond
    
    Notice how the inner app is called when the validation was successful. If it was not, we can respond e.g. with HTTP 401 Unauthorized, by constructing a Response with responseLBS and passing it to respond.

    Passing arguments to and from your Middleware

    Middleware must often be configurable. Let’s say you have a type JWTSettings that you want to be passed to the middleware. Simply pass an extra argument to your middleware. Then your middleware type turns into:
    authorizationMiddleware :: JWTSettings -> Application -> Request -> Respond -> IO ResponseReceived
    authorizationMiddleware jwtSettings req respond =
    case verifyJWT jwtSettings (requestHeaders req) of
    InvalidJWT err -> respond (invalidJWTResponse err)
    ValidJWT -> app req respond
    
    or alternatively:
    authorizationMiddleware :: JWTSettings -> Middleware
    
    Perhaps less intuitively, you can also pass on data from middleware to the wrapped Application:
    authorizationMiddleware :: JWTSettings -> (JWT -> Application) -> Request -> Respond -> IO ResponseReceived
    authorizationMiddleware jwtSettings req respond =
    case verifyJWT jwtSettings (requestHeaders req) of
    InvalidJWT err -> respond (invalidJWTResponse err)
    ValidJWT jwt -> app jwt req respond
    
    although then, chaining different middleware has to take this extra argument into account:
    let finalApp =
    authorizationMiddleware
    (\jwt -> corsMiddleware
    (… more middleware here …
    (app jwt)))
    

    Modifying the Response

    Middleware can also modify the Response that is returned by the inner application. This is done by taking the respond callback, using it to define a new respond', and passing this new respond' to the app:
    gzipMiddleware app req respond = do
    let respond' resp = do
    resp' <- gzipResponseBody resp
    respond resp'
    app req respond'
    
    However, modifying the response (especially the response body) is not trivial, so in order to get a sense of how to do it (dealing with the type of responseToStream), it’s best to look at an example, for example the GZIP middleware of wai-extra.

  7. module Test.QuickCheck.Instances.UUID

    No documentation available.

  8. module Test.QuickCheck.Instances.Void

    No documentation available.

  9. data InvalidAccess

    resourcet Control.Monad.Trans.Resource

    Indicates either an error in the library, or misuse of it (e.g., a ResourceT's state is accessed after being released). Since 0.3.0

  10. InvalidAccess :: String -> InvalidAccess

    resourcet Control.Monad.Trans.Resource

    No documentation available.

Page 404 of many | Previous | Next