From a108f16effcd6a3921da3a3bd9c89ee110fdd138 Mon Sep 17 00:00:00 2001
From: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Wed, 5 Oct 2016 12:07:13 +0200
Subject: [PATCH] Fix preview when SECURE_SSL_REDIRECT = True.

Fix #3048.
---
 CHANGELOG.txt                 | 1 +
 docs/releases/1.7.rst         | 1 +
 wagtail/wagtailcore/models.py | 2 ++
 3 files changed, 4 insertions(+)

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 86982a20d2..2b963f941a 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -34,6 +34,7 @@ Changelog
  * Fix: Images / documents pagination now preserves GET parameters (Bojan Mihelac)
  * Fix: Wagtail's UserProfile model now sets a related_name of ``wagtail_userprofile`` to avoid naming collisions with other user profile models (Matt Westcott)
  * Fix: Non-text content is now preserved when adding or editing a link within rich text (Matt Westcott)
+ * Fix: Fixed preview when `SECURE_SSL_REDIRECT = True` (Aymeric Augustin)
 
 
 1.6.3 (30.09.2016)
diff --git a/docs/releases/1.7.rst b/docs/releases/1.7.rst
index 0e3a97cc21..749590c3ae 100644
--- a/docs/releases/1.7.rst
+++ b/docs/releases/1.7.rst
@@ -69,6 +69,7 @@ Bug fixes
  * Images / documents pagination now preserves GET parameters (Bojan Mihelac)
  * Wagtail's UserProfile model now sets a related_name of ``wagtail_userprofile`` to avoid naming collisions with other user profile models (Matt Westcott)
  * Non-text content is now preserved when adding or editing a link within rich text (Matt Westcott)
+ * Fixed preview when ``SECURE_SSL_REDIRECT = True`` (Aymeric Augustin)
 
 
 Upgrade considerations
diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py
index 332f13ed31..e186bdb611 100644
--- a/wagtail/wagtailcore/models.py
+++ b/wagtail/wagtailcore/models.py
@@ -1229,6 +1229,8 @@ class Page(six.with_metaclass(PageBase, AbstractPage, index.Indexed, Clusterable
             'REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR', 'HTTP_COOKIE', 'HTTP_USER_AGENT',
             'wsgi.version', 'wsgi.multithread', 'wsgi.multiprocess', 'wsgi.run_once',
         ]
+        if settings.SECURE_PROXY_SSL_HEADER:
+            HEADERS_FROM_ORIGINAL_REQUEST.append(settings.SECURE_PROXY_SSL_HEADER[0])
         if original_request:
             for header in HEADERS_FROM_ORIGINAL_REQUEST:
                 if header in original_request.META: