Safe Haskell | None |
---|---|
Language | Haskell2010 |
Support for validating server output on-the-fly. Validators can be configured on a per content-type basis.
- setValidator :: (Response -> IO Response) -> Response -> Response
- setValidatorSP :: (Monad m, ToMessage r) => (Response -> IO Response) -> m r -> m Response
- validateConf :: Conf
- runValidator :: (Response -> IO Response) -> Response -> IO Response
- wdgHTMLValidator :: (MonadIO m, ToMessage r) => r -> m Response
- noopValidator :: Response -> IO Response
- lazyProcValidator :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> (Maybe ByteString -> Bool) -> Response -> IO Response
Documentation
setValidator :: (Response -> IO Response) -> Response -> Response Source #
Set the validator which should be used for this particular
Response
when validation is enabled.
Calling this function does not enable validation. That can only be
done by enabling the validation in the Conf
that is passed to
simpleHTTP
.
You do not need to call this function if the validator set in
Conf
does what you want already.
Example: (use noopValidator
instead of the default supplied by
validateConf
)
simpleHTTP validateConf $ ok . setValidator noopValidator =<< htmlPage
See also: validateConf
, wdgHTMLValidator
, noopValidator
,
lazyProcValidator
.
setValidatorSP :: (Monad m, ToMessage r) => (Response -> IO Response) -> m r -> m Response Source #
ServerPart
version of setValidator
.
Example: (Set validator to noopValidator
)
simpleHTTP validateConf $ setValidatorSP noopValidator (dir "ajax" ... )
validateConf :: Conf Source #
Extend nullConf
by enabling validation and setting
wdgHTMLValidator
as the default validator for text/html
.
Example:
simpleHTTP validateConf . anyRequest $ ok htmlPage
runValidator :: (Response -> IO Response) -> Response -> IO Response Source #
Actually perform the validation on a Response
.
Run the validator specified in the Response
. If none is provide
use the supplied default instead.
Note: This function will run validation unconditionally. You
probably want setValidator
or validateConf
.
wdgHTMLValidator :: (MonadIO m, ToMessage r) => r -> m Response Source #
Validate text/html
content with WDG HTML Validator
.
This function expects the executable to be named validate
and it
must be in the default PATH
.
See also: setValidator
, validateConf
, lazyProcValidator
.
noopValidator :: Response -> IO Response Source #
A validator which always succeeds.
Useful for selectively disabling validation. For example, if you are sending down HTML fragments to an AJAX application and the default validator only understands complete documents.
:: FilePath | name of executable |
-> [String] | arguments to pass to the executable |
-> Maybe FilePath | optional path to working directory |
-> Maybe [(String, String)] | optional environment (otherwise inherit) |
-> (Maybe ByteString -> Bool) | content-type filter |
-> Response | Response to validate |
-> IO Response |
Validate the Response
using an external application.
If the external application returns 0, the original response is
returned unmodified. If the external application returns non-zero,
a Response
containing the error messages and original response
body is returned instead.
This function also takes a predicate filter which is applied to the content-type of the response. The filter will only be applied if the predicate returns true.
NOTE: This function requires the use of -threaded to avoid blocking. However, you probably need that for Happstack anyway.
See also: wdgHTMLValidator
.