Re: [pylons-discuss] Attaching custom header to all responses

2017-11-06 Thread Michael Merickel
A fourth (and probably best way in this case) is to register a NewResponse
subscriber. Another global hook is to add a tween. A good hook that allows
certain views to opt-out or opt-in to something is a view deriver. They all
affect different parts of the pipeline [1] but a NewResponse subscriber is
a pretty good one here for something that affects every request.

[1]
https://docs.pylonsproject.org/projects/pyramid/en/1.9-branch/narr/router.html

On Mon, Nov 6, 2017 at 5:49 PM,  wrote:

> Hi,
>
> This question is more of a curious one as I explore different possible
> solutions for a problem.
>
> What is the recommended way of adding an X-Myapp-Didum header to *every*
> response returned from the server? It looks like there are different ways
> to achieve that:
>
>- Change the Response factory
>
> :
>inherit from the Pyramid Response class and add the header in __init__;
>- Use a Response callback
>
> 
>which adds the header whenever a response is returned from a view function;
>- A Finished callback
>
> ,
>like the Response callback, can add the header to the request.response
>object.
>
> It looks like the Response factory is the favorable way to go, considering
> that both callbacks seem to work only on a per-request basis? Or what other
> ways exist to achieve this?
>
> Thanks!
> Jens
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pylons-discuss+unsubscr...@googlegroups.com.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/pylons-discuss/2f333583-13ff-4587-a11d-b81e47948109%
> 40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAKdhhwG5Ak6APkTha39AHyXHcQjKUT4g-s%3D-oMD1Z3kF-bYfMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[pylons-discuss] Attaching custom header to all responses

2017-11-06 Thread jens . troeger
Hi, 

This question is more of a curious one as I explore different possible 
solutions for a problem.

What is the recommended way of adding an X-Myapp-Didum header to *every* 
response returned from the server? It looks like there are different ways 
to achieve that:

   - Change the Response factory 
   
:
 
   inherit from the Pyramid Response class and add the header in __init__;
   - Use a Response callback 
   

 
   which adds the header whenever a response is returned from a view function;
   - A Finished callback 
   
,
 
   like the Response callback, can add the header to the request.response 
   object.

It looks like the Response factory is the favorable way to go, considering 
that both callbacks seem to work only on a per-request basis? Or what other 
ways exist to achieve this?

Thanks!
Jens

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/2f333583-13ff-4587-a11d-b81e47948109%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.