-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from SADiLaR/bug/browser-restore
Ensure HTML pages vary on HX-Request
- Loading branch information
Showing
2 changed files
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.utils.cache import patch_vary_headers | ||
|
||
|
||
class ExtraVaryMiddleware: | ||
"""Ensure HTML pages vary on HX-Request | ||
This is needed so that incomplete responses based on base_htmx.html are not | ||
reused as full-page responses, for example on browser restore of a page.""" | ||
|
||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
response = self.get_response(request) | ||
if "text/html" in response.headers["Content-Type"]: | ||
patch_vary_headers(response, ["HX-Request"]) | ||
return response |