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.
putRequest :: MonadSnap m => Request -> m ()snap-core Snap.Internal.Core Puts a new Request object into the Snap monad. Example:
ghci> :set -XOverloadedStrings ghci> import qualified Data.Map as M ghci> import qualified Snap.Test as T ghci> :{ ghci| let hndlr = do rq <- T.buildRequest (T.get "/bar/foo" M.empty) ghci| putRequest rq ghci| uri' <- getsRequest rqURI ghci| writeBS uri' ghci| :} ghci> T.runHandler (T.get "/foo/bar" M.empty) hndlr HTTP/1.1 200 OK server: Snap/test date: Wed, 06 Aug 2014 15:13:46 GMT /bar/foo
readRequestBody :: MonadSnap m => Word64 -> m ByteStringsnap-core Snap.Internal.Core Returns the request body as a lazy bytestring. /Note that the request is not actually provided lazily!/ Example:
ghci> :set -XOverloadedStrings ghci> import qualified Data.Map as M ghci> import qualified Snap.Test as T ghci> let r = T.put "/foo" "text/plain" "some text" ghci> T.runHandler r (readRequestBody 2048 >>= writeLBS) HTTP/1.1 200 OK server: Snap/test date: Thu, 07 Aug 2014 20:08:44 GMT some text
Since: 0.6runRequestBody :: MonadSnap m => (InputStream ByteString -> IO a) -> m asnap-core Snap.Internal.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.Internal.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.Internal.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.Http.Types Contains all of the information about an incoming HTTP request.
-
snap-core Snap.Internal.Http.Types No documentation available.
checkRangeReq :: MonadSnap m => Request -> FilePath -> Word64 -> m Boolsnap-core Snap.Internal.Util.FileServe No documentation available.
-
snap-core Snap.Test No documentation available.
-
snap-core Snap.Test No documentation available.