Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Some helpers for parsing data out of a raw WAI Request
.
Synopsis
- parseHttpAccept :: ByteString -> [ByteString]
- parseRequestBody :: BackEnd y -> Request -> IO ([Param], [File y])
- data RequestBodyType
- getRequestBodyType :: Request -> Maybe RequestBodyType
- sinkRequestBody :: BackEnd y -> RequestBodyType -> IO ByteString -> IO ([Param], [File y])
- sinkRequestBodyEx :: ParseRequestBodyOptions -> BackEnd y -> RequestBodyType -> IO ByteString -> IO ([Param], [File y])
- type BackEnd a = ByteString -> FileInfo () -> IO ByteString -> IO a
- lbsBackEnd :: Monad m => ignored1 -> ignored2 -> m ByteString -> m ByteString
- tempFileBackEnd :: InternalState -> ignored1 -> ignored2 -> IO ByteString -> IO FilePath
- tempFileBackEndOpts :: IO FilePath -> String -> InternalState -> ignored1 -> ignored2 -> IO ByteString -> IO FilePath
- type Param = (ByteString, ByteString)
- type File y = (ByteString, FileInfo y)
- data FileInfo c = FileInfo {}
- parseContentType :: ByteString -> (ByteString, [(ByteString, ByteString)])
- data ParseRequestBodyOptions
- defaultParseRequestBodyOptions :: ParseRequestBodyOptions
- noLimitParseRequestBodyOptions :: ParseRequestBodyOptions
- parseRequestBodyEx :: ParseRequestBodyOptions -> BackEnd y -> Request -> IO ([Param], [File y])
- setMaxRequestKeyLength :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions
- clearMaxRequestKeyLength :: ParseRequestBodyOptions -> ParseRequestBodyOptions
- setMaxRequestNumFiles :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions
- clearMaxRequestNumFiles :: ParseRequestBodyOptions -> ParseRequestBodyOptions
- setMaxRequestFileSize :: Int64 -> ParseRequestBodyOptions -> ParseRequestBodyOptions
- clearMaxRequestFileSize :: ParseRequestBodyOptions -> ParseRequestBodyOptions
- setMaxRequestFilesSize :: Int64 -> ParseRequestBodyOptions -> ParseRequestBodyOptions
- clearMaxRequestFilesSize :: ParseRequestBodyOptions -> ParseRequestBodyOptions
- setMaxRequestParmsSize :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions
- clearMaxRequestParmsSize :: ParseRequestBodyOptions -> ParseRequestBodyOptions
- setMaxHeaderLines :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions
- clearMaxHeaderLines :: ParseRequestBodyOptions -> ParseRequestBodyOptions
- setMaxHeaderLineLength :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions
- clearMaxHeaderLineLength :: ParseRequestBodyOptions -> ParseRequestBodyOptions
Documentation
parseHttpAccept :: ByteString -> [ByteString] Source #
Parse the HTTP accept string to determine supported content types.
parseRequestBody :: BackEnd y -> Request -> IO ([Param], [File y]) Source #
Parse the body of an HTTP request.
See parseRequestBodyEx for details.
Note: This function does not limit the memory it allocates.
When dealing with untrusted data (as is usually the case when
receiving input from the internet), it is recommended to
use the parseRequestBodyEx
function instead.
data RequestBodyType Source #
The mimetype of the http body. Depending on whether just parameters or parameters and files are passed, one or the other mimetype should be used.
UrlEncoded | application/x-www-form-urlencoded (parameters only) |
Multipart ByteString | multipart/form-data (parameters and files) |
getRequestBodyType :: Request -> Maybe RequestBodyType Source #
Get the mimetype of the body of an http request.
sinkRequestBody :: BackEnd y -> RequestBodyType -> IO ByteString -> IO ([Param], [File y]) Source #
sinkRequestBodyEx :: ParseRequestBodyOptions -> BackEnd y -> RequestBodyType -> IO ByteString -> IO ([Param], [File y]) Source #
Since: 3.0.16.0
= ByteString | parameter name |
-> FileInfo () | |
-> IO ByteString | |
-> IO a |
A file uploading backend. Takes the parameter name, file name, and a stream of data.
lbsBackEnd :: Monad m => ignored1 -> ignored2 -> m ByteString -> m ByteString Source #
Store uploaded files in memory
tempFileBackEnd :: InternalState -> ignored1 -> ignored2 -> IO ByteString -> IO FilePath Source #
Save uploaded files on disk as temporary files
Note: starting with version 2.0, removal of temp files is registered with
the provided InternalState
. It is the responsibility of the caller to
ensure that this InternalState
gets cleaned up.
:: IO FilePath | get temporary directory |
-> String | filename pattern |
-> InternalState | |
-> ignored1 | |
-> ignored2 | |
-> IO ByteString | |
-> IO FilePath |
Same as tempFileBackEnd
, but use configurable temp folders and patterns.
type Param = (ByteString, ByteString) Source #
Post parameter name and value.
type File y = (ByteString, FileInfo y) Source #
Post parameter name and associated file information.
Information on an uploaded file.
FileInfo | |
|
parseContentType :: ByteString -> (ByteString, [(ByteString, ByteString)]) Source #
Parse a content type value, turning a single ByteString
into the actual
content type and a list of pairs of attributes.
Since: 1.3.2
data ParseRequestBodyOptions Source #
A data structure that describes the behavior of the parseRequestBodyEx function.
Since: 3.0.16.0
defaultParseRequestBodyOptions :: ParseRequestBodyOptions Source #
A reasonable default set of parsing options. Maximum key/filename length: 32 bytes; maximum files: 10; filesize unlimited; maximum size for parameters: 64kbytes; maximum number of header lines: 32 bytes (applies only to headers of a mime/multipart message); maximum header line length: Apache's default for that is 8190 bytes (http:/httpd.apache.orgdocs2.2mod/core.html#limitrequestline) so we're using that here as well.
Since: 3.0.16.0
noLimitParseRequestBodyOptions :: ParseRequestBodyOptions Source #
Do not impose any memory limits.
Since: 3.0.21.0
parseRequestBodyEx :: ParseRequestBodyOptions -> BackEnd y -> Request -> IO ([Param], [File y]) Source #
Parse the body of an HTTP request, limit resource usage. The HTTP body can contain both parameters and files. This function will return a list of key,value pairs for all parameters, and a list of key,a pairs for filenames. The a depends on the used backend that is responsible for storing the received files.
setMaxRequestKeyLength :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Set the maximum length of a filename.
Since: 3.0.16.0
clearMaxRequestKeyLength :: ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Do not limit the length of filenames.
Since: 3.0.16.0
setMaxRequestNumFiles :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Set the maximum number of files per request.
Since: 3.0.16.0
clearMaxRequestNumFiles :: ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Do not limit the maximum number of files per request.
Since: 3.0.16.0
setMaxRequestFileSize :: Int64 -> ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Set the maximum filesize per file (in bytes).
Since: 3.0.16.0
clearMaxRequestFileSize :: ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Do not limit the maximum filesize per file.
Since: 3.0.16.0
setMaxRequestFilesSize :: Int64 -> ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Set the maximum size of all files per request.
Since: 3.0.16.0
clearMaxRequestFilesSize :: ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Do not limit the maximum size of all files per request.
Since: 3.0.16.0
setMaxRequestParmsSize :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Set the maximum size of the sum of all parameters.
Since: 3.0.16.0
clearMaxRequestParmsSize :: ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Do not limit the maximum size of the sum of all parameters.
Since: 3.0.16.0
setMaxHeaderLines :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Set the maximum header lines per mime/multipart entry.
Since: 3.0.16.0
clearMaxHeaderLines :: ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Do not limit the maximum header lines per mime/multipart entry.
Since: 3.0.16.0
setMaxHeaderLineLength :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Set the maximum header line length per mime/multipart entry.
Since: 3.0.16.0
clearMaxHeaderLineLength :: ParseRequestBodyOptions -> ParseRequestBodyOptions Source #
Do not limit the maximum header lines per mime/multipart entry.
Since: 3.0.16.0