Hoogle Search
Within LTS Haskell 24.52 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
runRequestBody :: MonadSnap m => (InputStream ByteString -> IO a) -> m asnap-core Snap.Core Pass the request body stream to a consuming procedure, returning the result. If the consuming procedure you pass in here throws an exception, Snap will attempt to clear the rest of the unread request body (using skipToEof) before rethrowing the exception. If you used terminateConnection, however, Snap will give up and immediately close the socket. To prevent slowloris attacks, the connection will be also terminated if the input socket produces data too slowly (500 bytes per second is the default limit). Example:
ghci> :set -XOverloadedStrings ghci> import qualified Data.ByteString.Char8 as B8 ghci> import qualified Data.ByteString.Lazy as L ghci> import Data.Char (toUpper) ghci> import qualified Data.Map as M ghci> import qualified Snap.Test as T ghci> import qualified System.IO.Streams as Streams ghci> let r = T.put "/foo" "text/plain" "some text" ghci> :{ ghci| let f s = do u <- Streams.map (B8.map toUpper) s ghci| l <- Streams.toList u ghci| return $ L.fromChunks l ghci| :} ghci> T.runHandler r (runRequestBody f >>= writeLBS) HTTP/1.1 200 OK server: Snap/test date: Thu, 07 Aug 2014 20:48:40 GMT SOME TEXT
transformRequestBody :: (InputStream ByteString -> IO (InputStream ByteString)) -> Snap ()snap-core Snap.Core Normally Snap is careful to ensure that the request body is fully consumed after your web handler runs, but before the Response body is streamed out the socket. If you want to transform the request body into some output in O(1) space, you should use this function. Take care: in order for this to work, the HTTP client must be written with input-to-output streaming in mind. Note that upon calling this function, response processing finishes early as if you called finishWith. Make sure you set any content types, headers, cookies, etc. before you call this function. Example:
ghci> :set -XOverloadedStrings ghci> import qualified Data.ByteString.Char8 as B8 ghci> import Data.Char (toUpper) ghci> import qualified Data.Map as M ghci> import qualified Snap.Test as T ghci> import qualified System.IO.Streams as Streams ghci> let r = T.put "/foo" "text/plain" "some text" ghci> let f = Streams.map (B8.map toUpper) ghci> T.runHandler r (transformRequestBody f >> readRequestBody 2048 >>= writeLBS) HTTP/1.1 200 OK server: Snap/test date: Thu, 07 Aug 2014 20:30:15 GMT SOME TEXT
withRequest :: MonadSnap m => (Request -> m a) -> m asnap-core Snap.Core Fetches the Request from state and hands it to the given action. Example:
ghci> :set -XOverloadedStrings ghci> import qualified Data.Map as M ghci> import qualified Snap.Test as T ghci> import Control.Monad.IO.Class ghci> let r = T.get "/foo/bar" M.empty ghci> let h = withRequest (\rq -> liftIO (T.requestToString rq) >>= writeBS) ghci> T.runHandler r h HTTP/1.1 200 OK server: Snap/test date: Wed, 06 Aug 2014 15:44:24 GMT GET /foo/bar HTTP/1.1 host: localhost
-
snap-core Snap.Internal.Core Contains all of the information about an incoming HTTP request.
-
snap-core Snap.Internal.Core No documentation available.
_snapRequest :: SnapState -> Requestsnap-core Snap.Internal.Core No documentation available.
getRequest :: MonadSnap m => m Requestsnap-core Snap.Internal.Core Grabs the Request object out of the Snap monad. Example:
ghci> :set -XOverloadedStrings ghci> import qualified Data.Map as M ghci> import qualified Snap.Test as T ghci> let r = T.get "/foo/bar" M.empty ghci> T.runHandler r (writeBS . rqURI =<< getRequest) HTTP/1.1 200 OK server: Snap/test date: Sat, 02 Aug 2014 07:51:54 GMT /foo/bar
getsRequest :: MonadSnap m => (Request -> a) -> m asnap-core Snap.Internal.Core Grabs something out of the Request object, using the given projection function. See gets. Example:
ghci> :set -XOverloadedStrings ghci> import qualified Data.Map as M ghci> import qualified Snap.Test as T ghci> let r = T.get "/foo/bar" M.empty ghci> T.runHandler r (writeBS =<< getsRequest rqURI) HTTP/1.1 200 OK server: Snap/test date: Sat, 02 Aug 2014 07:51:54 GMT /foo/bar
localRequest :: MonadSnap m => (Request -> Request) -> m a -> m asnap-core Snap.Internal.Core Runs a Snap action with a locally-modified Request state object. The Request object in the Snap monad state after the call to localRequest will be unchanged. Example:
ghci> :set -XOverloadedStrings ghci> import qualified Data.Map as M ghci> import qualified Snap.Test as T ghci> let r = T.get "/foo/bar" M.empty ghci> r' <- T.buildRequest $ T.get "/bar/foo" M.empty ghci> let printRqURI = getsRequest rqURI >>= writeBS >> writeBS "\n" ghci> T.runHandler r (printRqURI >> localRequest (const r') printRqURI) HTTP/1.1 200 OK server: Snap/test date: Wed, 06 Aug 2014 15:34:12 GMT /foo/bar /bar/foo
modifyRequest :: MonadSnap m => (Request -> Request) -> m ()snap-core Snap.Internal.Core Modifies the Request object stored in a Snap monad. Example:
ghci> :set -XOverloadedStrings ghci> import qualified Data.Map as M ghci> import qualified Snap.Test as T ghci> let r = T.get "/foo/bar" M.empty ghci> r' <- T.buildRequest $ T.get "/bar/foo" M.empty ghci> T.runHandler r (modifyRequest (const r') >> getsRequest rqURI >>= writeBS) HTTP/1.1 200 OK server: Snap/test date: Wed, 06 Aug 2014 15:24:25 GMT /bar/foo