Skip to content

Commit

Permalink
Always vary cached schema on Cookie and Authorization
Browse files Browse the repository at this point in the history
This is needed to play nice with session auth on the schema view and with CurrentUserDefault.
  • Loading branch information
axnsan12 committed Jan 2, 2018
1 parent caa397b commit f81795d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ caching the schema view in-memory, with some sane defaults:
* caching is enabled by the `cache_page <https://docs.djangoproject.com/en/1.11/topics/cache/#the-per-view-cache>`__
decorator, using the default Django cache backend, can be changed using the ``cache_kwargs`` argument
* HTTP caching of the response is blocked to avoid confusing situations caused by being shown stale schemas
* if `public` is set to ``False`` on the SchemaView, the cached schema varies on the ``Cookie`` and ``Authorization``
HTTP headers to enable filtering of visible endpoints according to the authentication credentials of each user; note
that this means that every user accessing the schema will have a separate schema cached in memory.
* the cached schema varies on the ``Cookie`` and ``Authorization`` HTTP headers to enable filtering of visible endpoints
according to the authentication credentials of each user; note that this means that every user accessing the schema
will have a separate schema cached in memory.

4. Validation
=============
Expand Down
3 changes: 1 addition & 2 deletions src/drf_yasg/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def apply_cache(cls, view, cache_timeout, cache_kwargs):
Arguments described in :meth:`.as_cached_view`.
"""
if not cls.public:
view = vary_on_headers('Cookie', 'Authorization')(view)
view = vary_on_headers('Cookie', 'Authorization')(view)
view = cache_page(cache_timeout, **cache_kwargs)(view)
view = deferred_never_cache(view) # disable in-browser caching
return view
Expand Down

0 comments on commit f81795d

Please sign in to comment.