Search code examples
apacheuwsgimod-headers

Can mod_headers change headers generated by uWSGI?


I have a uWSGI service running behing an apache front-end. The part of my apache conf handling that lools like:

     <Location /myapp>
         SetHandler uwsgi-handler
         uWSGISocket /var/run/uwsgi/myapp.sock
         Allow from all
    </Location>

and I'd like to add a custom header to the responses of my app. I know I can do that by adding some code in the app, but I would prefer doing it with mod_headers, by adding the following line in the Location directive

         Header set Custom-Header "hello world"

It does not seem to work, although mod_headers documentation states

This directive can replace, merge or remove HTTP response headers. The header is modified just after the content handler and output filters are run, allowing outgoing headers to be modified.

What do I do wrong, or understand wrong?


Solution

  • As stated in the docs mod_uwsgi is very raw and uses the 'assbackwards' mode, unless you enable the CGI mode. This mode (assbackwards) gives superior performance but breaks basically all of the filters. You should use mod_proxy_uwsgi (fully apache-friendly) or let uWSGI do the hard work for you using the internal routing:

    http://uwsgi-docs.readthedocs.org/en/latest/InternalRouting.html

    (or the --add-header more invasive option)