withHttpServer :: Status -> ResponseHeaders -> ByteString -> (IO Req -> IO a) -> IO a
withHttpServer status headers body action = do
  ref <- newIORef (error "No request received!")
  withApplication (app ref) $ do
    action (readIORef ref)
  where
    app :: IORef Req -> Application
    app ref request = do
      liftIO $ toReq request >>= writeIORef ref
      return (responseLBS status headers body)
withHttpServer :: Status -> ResponseHeaders -> ByteString -> (IO Req -> IO a) -> IO a
withHttpServer status headers body action = do
  ref <- newIORef (error "No request received!")
  withApplication (app ref) $ do
    action (readIORef ref)
  where
    app :: IORef Req -> Application
    app ref request = do
      liftIO $ toReq request >>= writeIORef ref
      return (responseLBS status headers body)
withHttpServer status headers body action = do
  ref <- newIORef (error "No request received!")
  withApplication (app ref) $ do
    action (readIORef ref)
  where
    app :: IORef Req -> Application
    app ref request = do
      liftIO $ toReq request >>= writeIORef ref
      return (responseLBS status headers body)