1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

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.
This commit is contained in:
Unai Zalakain
2013-10-08 20:30:29 +02:00
committed by Tim Graham
parent 9bfe66164e
commit c7634cd7fe
10 changed files with 34 additions and 18 deletions

View File

@@ -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