Skip to content

Commit

Permalink
Clarified response middleware execution order in the documentation (#…
Browse files Browse the repository at this point in the history
…1846)

Co-authored-by: Adam Hopkins <[email protected]>
  • Loading branch information
kirilyer and ahopkins authored Jun 28, 2020
1 parent 6c8e20a commit d81096f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/sanic/middleware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ There are two types of middleware: request and response. Both are declared
using the `@app.middleware` decorator, with the decorator's parameter being a
string representing its type: `'request'` or `'response'`.

* Request middleware receives only the `request` as argument.
* Response middleware receives both the `request` and `response`.
* Request middleware receives only the `request` as an argument and are executed in the order they were added.
* Response middleware receives both the `request` and `response` and are executed in *reverse* order.

The simplest middleware doesn't modify the request or response at all:

Expand Down Expand Up @@ -64,12 +64,12 @@ this.
app.run(host="0.0.0.0", port=8000)
The three middlewares are executed in order:
The three middlewares are executed in the following order:

1. The first request middleware **add_key** adds a new key `foo` into request context.
2. Request is routed to handler **index**, which gets the key from context and returns a text response.
3. The first response middleware **custom_banner** changes the HTTP response header *Server* to say *Fake-Server*
4. The second response middleware **prevent_xss** adds the HTTP header for preventing Cross-Site-Scripting (XSS) attacks.
3. The second response middleware **prevent_xss** adds the HTTP header for preventing Cross-Site-Scripting (XSS) attacks.
4. The first response middleware **custom_banner** changes the HTTP response header *Server* to say *Fake-Server*

Responding early
----------------
Expand Down

0 comments on commit d81096f

Please sign in to comment.