Skip to content

Commit e40d6e8

Browse files
committed
doc: split after_request in flask integration
1 parent 99c9913 commit e40d6e8

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

doc/guides/_examples/flask_example.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,9 @@
3838

3939

4040
@bp.after_request
41-
def scim_after_request(response):
42-
"""Set the SCIM media type, extract ETag, and handle conditional responses."""
41+
def set_scim_content_type(response):
42+
"""Expose every endpoint with the SCIM media type."""
4343
response.headers["Content-Type"] = "application/scim+json"
44-
data = response.get_json(silent=True)
45-
if meta := (data or {}).get("meta"):
46-
if version := meta.get("version"):
47-
response.headers["ETag"] = version
48-
response.make_conditional(request)
4944
return response
5045

5146

@@ -56,6 +51,17 @@ def resource_location(app_record):
5651

5752

5853
# -- etag-start --
54+
@bp.after_request
55+
def set_etag_header(response):
56+
"""Extract ``ETag`` from ``meta.version`` and handle conditional responses."""
57+
data = response.get_json(silent=True)
58+
if meta := (data or {}).get("meta"):
59+
if version := meta.get("version"):
60+
response.headers["ETag"] = version
61+
response.make_conditional(request)
62+
return response
63+
64+
5965
@bp.before_request
6066
def check_etag():
6167
"""Verify ``If-Match`` on write operations.

doc/guides/flask.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ The complete runnable file is available in the `Complete example`_ section.
2323
Blueprint setup
2424
===============
2525

26-
Start with a Flask blueprint.
27-
The SCIM specifications indicates that the responses content type must be ``application/scim+json``,
28-
so lets enforce this on all the blueprint views with :meth:`~flask.Blueprint.after_request`.
26+
Start with a Flask blueprint and an :meth:`~flask.Blueprint.after_request` hook that
27+
sets the ``application/scim+json`` content type on every response.
2928

3029
.. literalinclude:: _examples/flask_example.py
3130
:language: python

0 commit comments

Comments
 (0)