Don't render page if an HTTP 3xx (Redirection) code has been set.

Bug #121759 reported by Gavin Panella
8
Affects Status Importance Assigned to Milestone
Launchpad itself
Fix Released
Low
Unassigned

Bug Description

Pages should often not be rendered because a redirect (HTTP 3xx) has been set, but there's some disagreement/mismatch between various parts of Launchpad, for example:

c.l.w.publisher.LaunchpadView considers 301, 302, 303 and 307 as redirects.
c.l.w.generalform.NoRenderingOnRedirect considers 302 and 303 as redirects.

And there are others...

We should consolidate this logic.

Revision history for this message
Gavin Panella (allenap) wrote :

Steve Alexander suggested using a test like (300 <= code < 400), or preferably - because there are only a handful defined in the RFC - just test membership in a list.

Changed in launchpad:
status: New → Confirmed
Revision history for this message
Christian Reis (kiko) wrote :

If you have the time, James, this would rock.

Changed in launchpad:
assignee: nobody → jamesh
Revision history for this message
James Henstridge (jamesh) wrote :

At this point, I consider all of c.l.w.generalform to be legacy code that we want to remove once the remaining users are converted. Do we have any others that are not in legacy code? Do we have cases where code using the legacy infrastructure would be improved by this change?

As for which 3xx status codes should omit the body, the list of such statuses from the RFC is:
          | "300" ; Section 10.3.1: Multiple Choices
          | "301" ; Section 10.3.2: Moved Permanently
          | "302" ; Section 10.3.3: Found
          | "303" ; Section 10.3.4: See Other
          | "304" ; Section 10.3.5: Not Modified
          | "305" ; Section 10.3.6: Use Proxy
          | "307" ; Section 10.3.8: Temporary Redirect

The ones that are not currently covered by LaunchpadView are 300, 304 and 305.

* The RFC states that 300 should have an entity body describing the "multiple choices"

* 304 responses are part of HTTP's caching system. Apart from resources and +icing, we don't provide enough information to the client for them to make a request where this status code is appropriate. I don't know whether we want to give the appearance of supporting 304 responses given the complexity.

* 305 responses probably shouldn't have an entity body so could be added, but there is no situation where we should be generating this response (and I am not sure how many browsers handle it anyway).

Revision history for this message
Christian Reis (kiko) wrote :

Gavin, you say "and there are others". Which others would those be? If it's just generalform, then James is right -- that code needs to be cleaned up, not enhanced!

Revision history for this message
James Henstridge (jamesh) wrote :

Gavin: could you elaborate on this, please?

Revision history for this message
Gavin Panella (allenap) wrote :

James, sorry for taking a while to reply. I found the following duplication of logic:

== webapp/publication.py ==

    def callObject(self, request, ob):

        # Don't render any content on a redirect.
        if request.response.getStatus() in [301, 302, 303, 307]:
            return ''

== webapp/generalform.py ==

class NoRenderingOnRedirect:
    """Mix-in for not rendering the page on redirects."""

    def __call__(self):
        # Call update() here instead of from the template to avoid
        # rendering the page on redirects.
        self.update()
        if self.request.response.getStatus() in [301, 302, 303]:
            # Don't render the page on redirects.
            return u''

== webapp/publisher.py ==

    def _isRedirected(self):
        """Return True if a redirect was requested.

        Check if the response status is one of 301, 302, 303 or 307.
        """
        return self.request.response.getStatus() in [301, 302, 303, 307]

== ftests/_launchpadformharness.py ==

    def wasRedirected(self):
        return self.request.response.getStatus() in [302, 303]

Revision history for this message
Diogo Matsubara (matsubara) wrote :

Moving to 1.1.10 milestone.

Changed in launchpad:
milestone: 1.1.10 → 1.1.11
Revision history for this message
Diogo Matsubara (matsubara) wrote :

re-targeting to .12

Changed in launchpad:
milestone: 1.1.11 → 1.1.12
Revision history for this message
Diogo Matsubara (matsubara) wrote :

Removing 1.1.12 milestone. James, please re-assess and set a new milestone.

Changed in launchpad:
milestone: 1.1.12 → none
Curtis Hovey (sinzui)
Changed in launchpad-foundations:
status: Confirmed → Triaged
importance: Undecided → Low
assignee: James Henstridge (jamesh) → nobody
Curtis Hovey (sinzui)
visibility: private → public
Changed in launchpad-foundations:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.