On Thu, 2009-10-22 at 12:45 +0100, Tim Sawyer wrote:
> Hi,
> 
> I have a django app that works fine using http.  We have a requirement to
> serve the entire site using https, which is being done at the proxy level
> - so the Apache that my django is running inside (mod_wsgi) doesn't know
> about the https.
> 
> I have a problem with using HttpResponseRedirect - the redirect is
> changing the URL to be http.  Everything else about the URL is right.
> 
> How do I fix this, and have the redirect go to https?
> 
> Thanks,
> 
> Tim.
> 

I use middleware to update the request to think it came in over https.
This is an extremely cut down version of what we use, but if _every_
request is SSL it should work fine (not all our requests are SSL, and
not every view requires SSL, so ours is a lot more complex in deciding
whether to monkey patch).

class SSLMiddleware(object):

  def process_request(self, request):
      # request.is_secure() looks in os.environ to see whether request is SSL
      # Unfortunately, once you look in os.environ, you can't change it...
      # Therefore, we have to monkey patch that function, we know this is SSL
      request.is_secure = lambda: True

Cheers

Tom



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to