Skip to content

Files

Latest commit

 

History

History
43 lines (32 loc) · 1.32 KB

elli_middleware.md

File metadata and controls

43 lines (32 loc) · 1.32 KB

Module elli_middleware

HTTP request processing middleware.

Behaviours: elli_handler.

Description

This module offers both pre-processing of requests and post-processing of responses. It can also be used to allow multiple handlers, where the first handler to return a response short-circuits the request. It is implemented as a plain elli handler.

Usage:

   Config = [
             {mods, [
                     {elli_example_middleware, []},
                     {elli_middleware_compress, []},
                     {elli_example_callback, []}
                    ]}
            ],
   elli:start_link([
                    %% ...,
                    {callback, elli_middleware},
                    {callback_args, Config}
                   ]).

The configured modules may implement the elli behaviour, in which case all the callbacks will be used as normal. If handle/2 returns ignore, elli will continue on to the next callback in the list.

Pre-processing and post-processing is implemented in preprocess/2 and postprocess/3. preprocess/2 is called for each middleware in the order specified, while postprocess/3 is called in the reverse order.