get package:snap-core
Builds an HTTP "GET" request with the given query parameters.
Example:
ghci> :set -XOverloadedStrings
ghci> import qualified Data.Map as M
ghci> buildRequest $ get "/foo/bar" (M.fromList [("param0", ["baz", "quux"])])
GET /foo/bar?param0=baz¶m0=quux HTTP/1.1
host: localhost
sn="localhost" c=127.0.0.1:60000 s=127.0.0.1:8080 ctx=/ clen=n/a
params: param0: ["baz","quux"]
Gets the HTTP
Cookie with the specified name.
Example:
ghci> :set -XOverloadedStrings
ghci> import qualified Data.Map as M
ghci> import qualified Snap.Test as T
ghci> import qualified Data.ByteString.Char8 as B8
ghci> let cookie = Cookie "name" "value" Nothing Nothing Nothing False False
ghci> let r = T.get "/foo/bar" M.empty >> T.addCookies [cookie]
ghci> T.runHandler r (getCookie "name" >>= writeBS . B8.pack . show)
HTTP/1.1 200 OK
server: Snap/test
date: Thu, 07 Aug 2014 12:16:58 GMT
Just (Cookie {cookieName = "name", cookieValue = "value", ...})
See
rqParam. Looks up a value for the given named parameter in
the
Request. If more than one value was entered for the given
parameter name,
getParam gloms the values together with
intercalate " ".
Example:
ghci> :set -XOverloadedStrings
ghci> import qualified Data.Map as M
ghci> import qualified Snap.Test as T
ghci> import qualified Data.ByteString.Char8 as B8
ghci> let r = T.get "/foo/bar" $ M.fromList [("foo", ["bar"])]
ghci> T.runHandler r (getParam "foo" >>= writeBS . B8.pack . show)
HTTP/1.1 200 OK
server: Snap/test
date: Mon, 11 Aug 2014 12:57:20 GMT
Just "bar"
See
rqParams. Convenience function to return
Params from
the
Request inside of a
MonadSnap instance.
Example:
ghci> :set -XOverloadedStrings
ghci> import qualified Data.Map as M
ghci> import qualified Snap.Test as T
ghci> import qualified Data.ByteString.Char8 as B8
ghci> let r = T.get "/foo/bar" $ M.fromList [("foo", ["bar"])]
ghci> T.runHandler r (getParams >>= writeBS . B8.pack . show)
HTTP/1.1 200 OK
server: Snap/test
date: Mon, 11 Aug 2014 13:02:54 GMT
fromList [("foo",["bar"])]
See
rqPostParam. Looks up a value for the given named parameter
in the POST form parameters mapping in
Request. If more than
one value was entered for the given parameter name,
getPostParam gloms the values together with:
intercalate " ".
Example:
ghci> :set -XOverloadedStrings
ghci> import qualified Data.Map as M
ghci> import qualified Snap.Test as T
ghci> import qualified Data.ByteString.Char8 as B8
ghci> let r = T.postUrlEncoded "/foo/bar" $ M.fromList [("foo", ["bar"])]
ghci> T.runHandler r (getPostParam "foo" >>= writeBS . B8.pack . show)
HTTP/1.1 200 OK
server: Snap/test
date: Mon, 11 Aug 2014 13:01:04 GMT
Just "bar"
See
rqParams. Convenience function to return
Params from
the
Request inside of a
MonadSnap instance.
Example:
ghci> :set -XOverloadedStrings
ghci> import qualified Data.Map as M
ghci> import qualified Snap.Test as T
ghci> import qualified Data.ByteString.Char8 as B8
ghci> let r = T.postUrlEncoded "/foo/bar" $ M.fromList [("foo", ["bar"])]
ghci> T.runHandler r (getPostParams >>= writeBS . B8.pack . show)
HTTP/1.1 200 OK
server: Snap/test
date: Mon, 11 Aug 2014 13:04:34 GMT
fromList [("foo",["bar"])]
See
rqQueryParam. Looks up a value for the given named
parameter in the query string parameters mapping in
Request. If
more than one value was entered for the given parameter name,
getQueryParam gloms the values together with
intercalate " ".
Example:
ghci> :set -XOverloadedStrings
ghci> import qualified Data.Map as M
ghci> import qualified Snap.Test as T
ghci> import qualified Data.ByteString.Char8 as B8
ghci> let r = T.postUrlEncoded "/foo/bar" M.empty >> T.setQueryStringRaw "foo=bar&foo=baz"
ghci> T.runHandler r (getQueryParam "foo" >>= writeBS . B8.pack . show)
HTTP/1.1 200 OK
server: Snap/test
date: Mon, 11 Aug 2014 13:06:50 GMT
Just "bar baz"
See
rqParams. Convenience function to return
Params from
the
Request inside of a
MonadSnap instance.
Example:
ghci> :set -XOverloadedStrings
ghci> import qualified Data.Map as M
ghci> import qualified Snap.Test as T
ghci> import qualified Data.ByteString.Char8 as B8
ghci> let r = T.postUrlEncoded "/foo/bar" M.empty >> T.setQueryStringRaw "foo=bar&foo=baz"
ghci> T.runHandler r (getQueryParams >>= writeBS . B8.pack . show)
HTTP/1.1 200 OK
server: Snap/test
date: Mon, 11 Aug 2014 13:10:17 GMT
fromList [("foo",["bar","baz"])]
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
Grabs the
Response 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 . rspStatusReason =<< getResponse)
HTTP/1.1 200 OK
server: Snap/test
date: Sat, 02 Aug 2014 15:06:00 GMT
OK
Returns an
IO action which you can use to modify the timeout
value.
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
Grabs something out of the
Response 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 =<< getsResponse rspStatusReason)
HTTP/1.1 200 OK
server: Snap/test
date: Wed, 06 Aug 2014 13:35:45 GMT
OK
Gets a path from the
Request using
rqPathInfo and makes
sure it is safe to use for opening files. A path is safe if it is a
relative path and has no ".." elements to escape the intended
directory structure.
Example:
ghci> :set -XOverloadedStrings
ghci> import qualified Data.Map as M
ghci> import qualified Snap.Test as T
ghci> import qualified Data.ByteString.Char8 as B8
ghci> T.runHandler (T.get "/foo/bar" M.empty) (getSafePath >>= writeBS . B8.pack)
HTTP/1.1 200 OK
server: Snap/test
date: Fri, 08 Aug 2014 16:13:20 GMT
foo/bar
ghci> T.runHandler (T.get "/foo/../bar" M.empty) (getSafePath >>= writeBS . B8.pack)
HTTP/1.1 404 Not Found
...
Get the maximum size of a form input which will be read into our
rqParams map.
Get the maximum size of a form input which will be read into our
rqParams map.
Get the minimum rate (in bytes/second) a client must maintain
before we kill the connection.
Get the amount of time which must elapse before we begin enforcing the
upload rate minimum
Get the "upload timeout". Whenever input is received from the client,
the connection timeout is set this many seconds in the future.