on master help sign in
Add a bit of haddock documentation
commit7ca5af79164422730cc6388c759b9f799b46aada authorHans-Christian Esperer <hc@hcesperer.org> dateSun 3 Jul 2016, 09:16 (10 years ago) parentbf7a319
1 file changed+22−2
wai-extra/Network/Wai/Parse.hs+22−2
wai-extra/Network/Wai/Parse.hs+22−2
@@ -169,8 +169,16 @@ type BackEnd a = S.ByteString -- ^ parameter name
169169 -> IO S.ByteString
170170 -> IO a
171171
172−data RequestBodyType = UrlEncoded | Multipart S.ByteString
173−
172+-- | The mimetype of the http body.
173+-- Depending on whether just parameters or parameters and files
174+-- are passed, one or the other mimetype should be used.
175+data RequestBodyType
176+ = -- | application/x-www-form-urlencoded (parameters only)
177+ UrlEncoded
178+ | -- | multipart/form-data (parameters and files)
179+ Multipart S.ByteString
180+
181+-- | Get the mimetype of the body of an http request.
174182getRequestBodyType :: Request -> Maybe RequestBodyType
175183getRequestBodyType req = do
176184 ctype' <- lookup hContentType $ requestHeaders req
@@ -204,6 +212,12 @@ parseContentType a = do
204212 in (strip k, strip v)
205213 strip = S.dropWhile (== space) . fst . S.breakEnd (/= space)
206214
215+-- | Parse the body of an HTTP request.
216+-- See parseRequestBodyEx for details.
217+-- Note: This function does not limit the memory it allocates.
218+-- When dealing with untrusted data (as is usually the case when
219+-- receiving input from the internet), it is recommended to
220+-- use the parseRequestBodyEx function instead.
207221parseRequestBody :: BackEnd y
208222 -> Request
209223 -> IO ([Param], [File y])
@@ -212,6 +226,12 @@ parseRequestBody s r =
212226 Nothing -> return ([], [])
213227 Just rbt -> sinkRequestBody s rbt (requestBody r)
214228
229+-- | Parse the body of an HTTP request, limit resource usage.
230+-- The HTTP body can contain both parameters and files.
231+-- This function will return a list of key,value pairs
232+-- for all parameters, and a list of key,a pairs
233+-- for filenames. The a depends on the used backend that
234+-- is responsible for storing the received files.
215235parseRequestBodyEx :: ParseRequestBodyOptions
216236 -> BackEnd y
217237 -> Request