Commit c7634cd7 authored by Unai Zalakain's avatar Unai Zalakain Committed by Tim Graham
Browse files

Fixed #7603 -- Added a 'scheme' property to the HttpRequest object

`HttpRequest.scheme` is `https` if `settings.SECURE_PROXY_SSL_HEADER` is
appropriately set and falls back to `HttpRequest._get_scheme()` (a hook
for subclasses to implement) otherwise.

`WSGIRequest._get_scheme()` makes use of the `wsgi.url_scheme` WSGI
environ variable to determine the request scheme.

`HttpRequest.is_secure()` simply checks if `HttpRequest.scheme` is
`https`.

This provides a way to check the current scheme in templates, for example.
It also allows us to deal with other schemes.

Thanks nslater for the suggestion.
parent 9bfe6616
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ def bookmarklets(request):
    admin_root = urlresolvers.reverse('admin:index')
    return render_to_response('admin_doc/bookmarklets.html', {
        'root_path': admin_root,
        'admin_url': "%s://%s%s" % ('https' if request.is_secure() else 'http', request.get_host(), admin_root),
        'admin_url': "%s://%s%s" % (request.scheme, request.get_host(), admin_root),
    }, context_instance=RequestContext(request))

@staff_member_required
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ def shortcut(request, content_type_id, object_id):
    # If all that malarkey found an object domain, use it. Otherwise, fall back
    # to whatever get_absolute_url() returned.
    if object_domain is not None:
        protocol = 'https' if request.is_secure() else 'http'
        protocol = request.scheme
        return http.HttpResponseRedirect('%s://%s%s'
                                         % (protocol, object_domain, absurl))
    else:
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ def index(request, sitemaps):
    """
    current_site = get_current_site(request)
    sites = []
    protocol = 'https' if request.is_secure() else 'http'
    protocol = request.scheme
    for section, site in sitemaps.items():
        if callable(site):
            pages = site().paginator.num_pages
+2 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ def index(request, sitemaps,
          template_name='sitemap_index.xml', content_type='application/xml',
          sitemap_url_name='django.contrib.sitemaps.views.sitemap'):

    req_protocol = 'https' if request.is_secure() else 'http'
    req_protocol = request.scheme
    req_site = get_current_site(request)

    sites = []
@@ -44,7 +44,7 @@ def index(request, sitemaps,
def sitemap(request, sitemaps, section=None,
            template_name='sitemap.xml', content_type='application/xml'):

    req_protocol = 'https' if request.is_secure() else 'http'
    req_protocol = request.scheme
    req_site = get_current_site(request)

    if section is not None:
+2 −2
Original line number Diff line number Diff line
@@ -110,8 +110,8 @@ class WSGIRequest(http.HttpRequest):
        self._read_started = False
        self.resolver_match = None

    def _is_secure(self):
        return self.environ.get('wsgi.url_scheme') == 'https'
    def _get_scheme(self):
        return self.environ.get('wsgi.url_scheme')

    def _parse_content_type(self, ctype):
        """
Loading