Clarify handler ordering

Matt Holt 2019-07-11 16:59:30 -06:00
parent 0245151384
commit de96b8bacc

@ -719,7 +719,11 @@ Handlers are modules which handle HTTP requests. They are chained together in a
Not all handlers call the next handler in the chain. For example, the `file_server` handler always serves a file from disk or returns an error. Thus, configuring handlers after `file_server` in your route is illogical, since they would never be executed. You will want to put handlers which originate the response at the very end of your route(s). The documentation for a module should state whether it invokes the next handler, but sometimes it is common sense.
Some handlers manipulate the response. Remember that **requests flow down, and responses flow up**. For example, if you wanted to use both `templates` and `encode` handlers, you would need to put `templates` _after_ `encode` in your route, because responses flow up. Thus, `templates` will be able to parse and execute the plain-text response as a template, and then return it up to the `encode` handler which will then compress it into a binary format:
Some handlers manipulate the response. Remember that **requests flow down, and responses flow up**. For example, if you wanted to use both `templates` and `encode` handlers, you would need to put `templates` _after_ `encode` in your route, because responses flow up. Thus, `templates` will be able to parse and execute the plain-text response as a template, and then return it up to the `encode` handler which will then compress it into a binary format.
If `templates` came before `encode`, then `encode` would write a compressed, binary-encoded response to `templates` which would not be able to parse the response properly.
The correct order, then, is this:
```
[