On May 22, 10:48 am, Wyatt Baldwin <[email protected]>
wrote:
> On May 22, 2:33 am, Shannon -jj Behrens <[email protected]> wrote:
>
> [snip]
>
> > * Once I got response.status_code working, it started shoving my HTML
> > response into the middle of a big error template instead of just serving
> > what I had. This totally messed with my Web service which counts on
> > the sparse HTML error messages I provide. I hacked around the problem.
> > In my action, I wrote:
>
> > request.environ['error_response_is_intentional'] = True
>
> > In error.py's document method, I wrote:
>
> > resp = request.environ['pylons.original_response']
> > if request.environ.get('error_response_is_intentional', False):
> > page = resp.body
> > else:
> > content = literal(resp.body) or
> > cgi.escape(request.GET.get('message', ''))
> > page = error_document_template % \
> > dict(prefix=request.environ.get('SCRIPT_NAME', ''),
> > code=cgi.escape(request.GET.get('code',
> > str(resp.status_int))),
> > message=content)
> > return pag
>
> > This is definitely a hack. I'm not even sure why this behavior changed.
> > If I set request.status_code, and I set the HTML containing the error
> > message, it should just leave it alone.
>
> One of the default middlewares is doing this--StatusCodeRedirect. I
> completely removed this from the Pylons project I'm using for web
> services.
>
> In another project, I have this in certain controllers:
>
> request.environ['pylons.status_code_redirect'] = True
>
> I found that by reading the source. If I understand it correctly, it
> disables StatusCodeRedirect for a given request. (It seems to work,
> but the semantics are confusing.)
For reference, this is documented on line 176 of pylons.middleware.
Not sure if it's in the official docs anywhere.
"""
Should an application wish to bypass the error response (ie, to
purposely return a 401), set
``environ['pylons.status_code_redirect'] = True`` in the
application.
"""
This comment is pretty clear, but when you go back and read the code
where you used this, it's easy to misinterpret. Perhaps the key should
be 'pylons.status_code_redirect.circumvent'. Or maybe the value should
be False (although the check for this key doesn't even look at the
value).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---