This repository has been archived by the owner on Dec 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
22: Enable SSL redirect and other security settings #203
Merged
stevejalim
merged 2 commits into
master
from
22--enable-ssl-redirect-and-other-security-settings
Sep 25, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import logging | ||
|
||
from django.conf import settings | ||
from django.test.client import RequestFactory | ||
|
||
from wagtailbakery.views import AllPublishedPagesView | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class AllPublishedPagesViewAllowingSecureRedirect(AllPublishedPagesView): | ||
"""Extension of `AllPublishedPagesView` that detects application-level SSL | ||
redirection in order to avoid an issue where rendered pages end up being 0 bytes | ||
|
||
See https://github.com/wagtail/wagtail-bakery/issues/24 for confirmation of the | ||
issue and the discussion on https://github.com/wagtail/wagtail-bakery/pull/25 | ||
that points to a custom view being the (current) workaround. Ideally we'll be | ||
able to replace this when that issue is resolved. | ||
|
||
The following code is taken from that closed PR, which adds the `secure_request` | ||
variable. | ||
""" | ||
|
||
def build_object(self, obj): | ||
""" | ||
Build wagtail page and set SERVER_NAME to retrieve corresponding site | ||
object. | ||
""" | ||
site = obj.get_site() | ||
logger.debug("Building %s" % obj) | ||
secure_request = site.port == 443 or getattr( | ||
settings, "SECURE_SSL_REDIRECT", False | ||
) | ||
self.request = RequestFactory(SERVER_NAME=site.hostname).get( | ||
self.get_url(obj), secure=secure_request | ||
) | ||
self.set_kwargs(obj) | ||
path = self.get_build_path(obj) | ||
self.build_file(path, self.get_content(obj)) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
secure=secure_request
and the creation of thesecure_request
variable itself were the two things added in wagtail-nest/wagtail-bakery#25 -- the rest of the method is unchanged