Re: Virtual hosting and CommonMiddleware redirects

2006-03-28 Thread Luke Plant

On Wednesday 29 March 2006 00:33, Luke Plant wrote:
> Hi,
>
> I'm using python-hosting which is working great so far.  I've found
> one problem with the way that CommonMiddleware does redirects.
> Python-hosting give you your own apache instance, forwarding on
> requests from the main one on the same machine (I think).  This
> means that HTTP_HOST is not set as you might expect.  

I've found that 'HTTP_X_FORWARDED_HOST' *is* set to what I expect.  Does 
anyone know if this a standard mechanism, and one that Django could use 
if it found it instead of HTTP_HOST?  A quick google suggests Rails 
does this.

Luke

-- 
"A man in love is incomplete until he is married. Then he is finished." 
-- Zsa Zsa Gabor, "Newsweek"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Virtual hosting and CommonMiddleware redirects

2006-03-28 Thread Luke Plant

Hi,

I'm using python-hosting which is working great so far.  I've found 
one problem with the way that CommonMiddleware does redirects.  
Python-hosting give you your own apache instance, forwarding on 
requests from the main one on the same machine (I think).  This 
means that HTTP_HOST is not set as you might expect.  I've had to 
monkey patch django (magic-removal) as below to get it to work, 
but it is fragile with respect to other potential vhost 
configurations I think.  Any other ideas how to fix this -- either 
fix django or resolve the problem some other way?

Cheers,

Luke



Index: django/middleware/common.py
===
--- django/middleware/common.py (revision 2584)
+++ django/middleware/common.py (working copy)
@@ -31,6 +31,8 @@

 # Check for a redirect based on settings.APPEND_SLASH and 
settings.PREPEND_WWW
 old_url = [request.META.get('HTTP_HOST', ''), request.path]
+if old_url[0].startswith('127.0.0.1'):
+old_url[0] = ''
 new_url = old_url[:]
 if settings.PREPEND_WWW and old_url[0] and not 
old_url[0].startswith('www.'):
 new_url[0] = 'www.' + old_url[0]

-- 
"A man in love is incomplete until he is married. Then he is finished." 
-- Zsa Zsa Gabor, "Newsweek"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---