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, <[email protected]> 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 > > <https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/hooks.html#changing-the-response-factory>: > inherit from the Pyramid Response class and add the header in __init__; > - Use a Response callback > > <https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/hooks.html#using-response-callbacks> > which adds the header whenever a response is returned from a view function; > - A Finished callback > > <https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/hooks.html#using-finished-callbacks>, > 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 [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/pylons-discuss/2f333583-13ff-4587-a11d-b81e47948109% > 40googlegroups.com > <https://groups.google.com/d/msgid/pylons-discuss/2f333583-13ff-4587-a11d-b81e47948109%40googlegroups.com?utm_medium=email&utm_source=footer> > . > 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 [email protected]. To post to this group, send email to [email protected]. 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.
