[Django] #17092: Internal Redirects with Apache

27 views
Skip to first unread message

Django

unread,
Oct 23, 2011, 2:59:00 PM10/23/11
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+--------------------
Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 1.3
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
The CGI specification allows for a CGI script to return a 'Location'
header
which refers to a location within the local web server. In Apache this is
honoured when the Status returned by the CGI script is also 200. mod_wsgi
also supports this. See
http://code.google.com/p/modwsgi/issues/detail?id=14.

[6164] added the host to all redirects. While this is good for 99.9% of
use cases, this makes these sorts of internal redirects impossible with
django. Would it be reasonable to change fix_location_header to only add
the host if the response code is not 200? Or we could add a variable such
as Response.add_host_to_location that defaults to True that could be used
to control this behavior on a per response basis. I'd be happy to work on
the path for this once I hear back which implementation would be more
likely to be accepted.

--
Ticket URL: <https://code.djangoproject.com/ticket/17092>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 23, 2011, 8:14:42 PM10/23/11
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
-------------------------------------+-------------------------------------
Reporter: anonymous | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.3
Component: HTTP handling | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by leanmeandonothingmachine):

* cc: leanmeandonothingmachine (added)
* needs_docs: => 0
* needs_tests: => 0
* needs_better_patch: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:1>

Django

unread,
Oct 28, 2011, 7:09:44 PM10/28/11
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------
Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: HTTP handling | Version: 1.3
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by ptone):

* status: new => closed
* resolution: => wontfix
* stage: Unreviewed => Accepted


Comment:

One can not assume that all responses Django will serve will be going
through a CGI spec compliant interface. So it does not make sense to make
this change in core.

There are a number of other limitations with the feature, one being that
the request_method is converted to GET and any request content is lost. If
the redirect is just to static content, there is likely something better
that can be done with mod_rewrite, or in a real edge case, one could put
together django middleware that would strip out the host portion before
returning.

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:2>

Django

unread,
Oct 31, 2011, 4:28:58 PM10/31/11
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------
Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: HTTP handling | Version: 1.3
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by anonymous):

This cannot be done with middleware. apply_response_fixes gets called
after middleware has already had it's shot at the response. Mod_rewrite
doesn't help when you want django to do some checks and only conditionally
pass the internal redirect response. Leaving the only possible option an
ugly hack.

{{{
request.get_host = lambda: ''
}}}

While we shouldn't assume that all responses will support the CGI spec, it
also doesn't seem right to me to break a widely used standard such as CGI
in core with no clean way to get the standard behavior.

I'm leaving as closed but in case any core devs reconsider I would still
be happy to contribute a patch that would allow a clean way to get this
behavior.

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:3>

Django

unread,
Oct 31, 2011, 4:43:50 PM10/31/11
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------
Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: reopened
Component: HTTP handling | Version: 1.3
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by carljm):

* status: closed => reopened
* resolution: wontfix =>


Comment:

Given that both CGI and `mod_wsgi` support this, I think that Django
should provide a clean way to return a host-free Location header (not by
default, but by request). Not entirely sure what that ought to look like,
but a flag on `HttpResponse` sounds as reasonable as anything.

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:4>

Django

unread,
Nov 2, 2011, 1:26:55 AM11/2/11
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------
Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: reopened
Component: HTTP handling | Version: 1.3
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by anonymous):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:5>

Django

unread,
Nov 14, 2011, 1:02:25 PM11/14/11
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------
Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: reopened
Component: HTTP handling | Version: 1.3
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by anonymous):

Anyone have any feedback on add_host_to_location.3.diff.

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:6>

Django

unread,
May 16, 2014, 10:08:37 AM5/16/14
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 1.3
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by oinopion):

* needs_better_patch: 0 => 1


Comment:

I could not apply patch. I'm getting this:
{{{
$ curl https://code.djangoproject.com/raw-
attachment/ticket/17092/add_host_to_location.3.diff | git apply
fatal: corrupt patch at line 97
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:8>

Django

unread,
Jul 1, 2014, 12:39:12 PM7/1/14
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by anonymous):

* needs_better_patch: 1 => 0
* version: 1.3 => 1.6


Comment:

After 3 years a patch goes stale, updated it. Lets see if it takes another
three years for someone to look at it.

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:9>

Django

unread,
Jul 1, 2014, 2:54:29 PM7/1/14
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by aaugustin):

I think this asks the broader question of Django's unconditional fixes. We
recently removed some fixes for IE 4-6 and Netscape 4.

Rather than tainting the `HttpResponse` API with a kwarg for each
unconditional "fix" (or "break"), shouldn't we move them to the
`CommonMiddleware`?

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:10>

Django

unread,
Jul 1, 2014, 3:09:51 PM7/1/14
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by anonymous):

I would agree with that, but before putting the time for that sort of re-
factor, i'd like to make sure it's going to get accepted.

Time for django-developers i guess.

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:11>

Django

unread,
Jul 1, 2014, 4:48:37 PM7/1/14
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by aaugustin):

Yes, django-developers it is.

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:12>

Django

unread,
Aug 14, 2014, 8:32:30 AM8/14/14
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


Comment:

Reading the [https://groups.google.com/d/topic/django-
developers/YXv3tszQXzA/discussion django-developers thread] it seems like
a different solution is desired.

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:13>

Django

unread,
Mar 14, 2015, 12:07:44 AM3/14/15
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------

Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by collinanderson):

This should in theory get fixed by #23960

--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:14>

Django

unread,
Mar 18, 2015, 1:29:03 PM3/18/15
to django-...@googlegroups.com
#17092: Internal Redirects with Apache
--------------------------------------+------------------------------------
Reporter: anonymous | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* status: new => closed

* resolution: => fixed


--
Ticket URL: <https://code.djangoproject.com/ticket/17092#comment:15>

Reply all
Reply to author
Forward
0 new messages