Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since I spent a couple of hours wading through the pylons/routes/beaker/etc. source I thought I'd share my solution.</p> <p>First a bit of context. I'm using an elastic load balancer (ELB) on AWS with SSL termination. The application is built to run solely over https; this is a post-firesheep world after all. It's layered like so:</p> <pre><code>ELB -&gt; nginx -&gt; pasteWSGI -&gt; pylons </code></pre> <p>ELB is jolly good in terms of simplicity but any call to pylons.controllers.util.redirect would trigger a 302 Redirect to "http://mysite/". The ELB would not change that on the way back (no reason to) and so my browser would be sent back to port 80 and there is no ELB listening on that port.</p> <p>I've tried updating the Mapper as suggested above.</p> <ol> <li>it did not work,</li> <li>I wanted my redirects to be relative. Switching to https in pylons means that the URL generator goes and fetches the host to create a new URL (https://localhost/....)</li> </ol> <p>Note that Mapper.redirect_to works out of the box and uses relative redirects so there is no need to mess with that. The fundamental problem is that controllers.redirect uses a slightly different code path. In particular, in Routes, the controllers.util.redirect is not a redirect (there's an "if routes and routes.redirect" which evals to False).</p> <p>My solution: replace all calls to redirect by a new controller method (called redirect too) to change redirects from absolute to relative redirects.</p> <p>The code is as follows:</p> <p>lib/helpers.py</p> <pre><code>def relative_redirect(to_url, start_response): """Returns a redirect that is compatible with AWS ELB (no absolute http responses) Using pylons.controllers.util.redirect triggers an exception that'll be turned into a 302 But with an absolute path so the response does not contains https but simple http """ start_response("302 Found", [("Content-Type", "text/plain; charset=utf-8"), ("Location", url(to_url))]) return ["You are being redirected to {0}".format(url(to_url))] </code></pre> <p>With that bit called from the base class of my controllers:</p> <pre><code>class BaseController(WSGIController): ... def redirect(self, to_url): """Force a relative redirection, to work with AWS ELB""" return relative_redirect(to_url, self.start_response) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload