wai-extra-3.0.19.1: Provides some basic WAI handlers and middleware.

Safe Haskell | None
Language | Haskell2010

Network.Wai.Parse

Description

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
  - = UrlEncoded
  - | Multipart ByteString
- 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 {
  - fileName :: ByteString
  - fileContentType :: ByteString
  - fileContent :: c
  }
- parseContentType :: ByteString -> (ByteString, [(ByteString, ByteString)])
- data ParseRequestBodyOptions
- defaultParseRequestBodyOptions :: 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] #

Parse the HTTP accept string to determine supported content types.

parseRequestBody :: BackEnd y -> Request -> IO ([Param], [File y]) #

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 #

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.

Constructors

UrlEncoded | application/x-www-form-urlencoded (parameters only)
Multipart ByteString | multipart/form-data (parameters and files)

getRequestBodyType :: Request -> Maybe RequestBodyType #

Get the mimetype of the body of an http request.

sinkRequestBody :: BackEnd y -> RequestBodyType -> IO ByteString -> IO ([Param], [File y]) #

sinkRequestBodyEx :: ParseRequestBodyOptions -> BackEnd y -> RequestBodyType -> IO ByteString -> IO ([Param], [File y]) #

Since: 3.0.16.0

type BackEnd a #

Arguments

= 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 #

Store uploaded files in memory

tempFileBackEnd :: InternalState -> ignored1 -> ignored2 -> IO ByteString -> IO FilePath #

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.

tempFileBackEndOpts #

Arguments

:: 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) #

Post parameter name and value.

type File y = (ByteString, FileInfo y) #

Post parameter name and associated file information.

data FileInfo c #

Information on an uploaded file.

Constructors

FileInfo |
Fields fileName :: ByteString fileContentType :: ByteString fileContent :: c

Instances

Eq c => Eq (FileInfo c) # |
Methods (==) :: FileInfo c -> FileInfo c -> Bool # (/=) :: FileInfo c -> FileInfo c -> Bool #
Show c => Show (FileInfo c) # |
Methods showsPrec :: Int -> FileInfo c -> ShowS # show :: FileInfo c -> String # showList :: [FileInfo c] -> ShowS #

parseContentType :: ByteString -> (ByteString, [(ByteString, ByteString)]) #

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 #

A data structure that describes the behavior of the parseRequestBodyEx function.

Since: 3.0.16.0

defaultParseRequestBodyOptions :: ParseRequestBodyOptions #

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

parseRequestBodyEx :: ParseRequestBodyOptions -> BackEnd y -> Request -> IO ([Param], [File y]) #

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 #

Set the maximum length of a filename.

Since: 3.0.16.0

clearMaxRequestKeyLength :: ParseRequestBodyOptions -> ParseRequestBodyOptions #

Do not limit the length of filenames.

Since: 3.0.16.0

setMaxRequestNumFiles :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions #

Set the maximum number of files per request.

Since: 3.0.16.0

clearMaxRequestNumFiles :: ParseRequestBodyOptions -> ParseRequestBodyOptions #

Do not limit the maximum number of files per request.

Since: 3.0.16.0

setMaxRequestFileSize :: Int64 -> ParseRequestBodyOptions -> ParseRequestBodyOptions #

Set the maximum filesize per file (in bytes).

Since: 3.0.16.0

clearMaxRequestFileSize :: ParseRequestBodyOptions -> ParseRequestBodyOptions #

Do not limit the maximum filesize per file.

Since: 3.0.16.0

setMaxRequestFilesSize :: Int64 -> ParseRequestBodyOptions -> ParseRequestBodyOptions #

Set the maximum size of all files per request.

Since: 3.0.16.0

clearMaxRequestFilesSize :: ParseRequestBodyOptions -> ParseRequestBodyOptions #

Do not limit the maximum size of all files per request.

Since: 3.0.16.0

setMaxRequestParmsSize :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions #

Set the maximum size of the sum of all parameters.

Since: 3.0.16.0

clearMaxRequestParmsSize :: ParseRequestBodyOptions -> ParseRequestBodyOptions #

Do not limit the maximum size of the sum of all parameters.

Since: 3.0.16.0

setMaxHeaderLines :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions #

Set the maximum header lines per mime/multipart entry.

Since: 3.0.16.0

clearMaxHeaderLines :: ParseRequestBodyOptions -> ParseRequestBodyOptions #

Do not limit the maximum header lines per mime/multipart entry.

Since: 3.0.16.0

setMaxHeaderLineLength :: Int -> ParseRequestBodyOptions -> ParseRequestBodyOptions #

Set the maximum header line length per mime/multipart entry.

Since: 3.0.16.0

clearMaxHeaderLineLength :: ParseRequestBodyOptions -> ParseRequestBodyOptions #

Do not limit the maximum header lines per mime/multipart entry.

Since: 3.0.16.0