On Wed, Nov 06, 2019 at 12:20:52PM +0100, Enrico Zini wrote:

> I'll now try to explore workarounds, as this is making it impossible to
> deploy a tornado server with gunicorn behind a proxy :/

First (failed) attempt was using a python configuration with this hook:

        def post_worker_init(worker):
            worker.server.xheaders = True

however, at the time the hook is called, worker.server is not filled,
and it is only filled in the TornadoWorker.run() method, which does not
terminate and so cannot be extended. There seem to be no obvious way to
hook into tornado.httpserver.HTTPServer creation inside TornadoWorker.

I found a non-obvious way, monkey patching tornado.httpserver.HTTPServer
to default to xheaders=True:

        def post_worker_init(worker):
            import tornado.httpserver

            class XheadersServer(tornado.httpserver.HTTPServer):
                def __init__(self, *args, **kw):
                    super().__init__(*args, **kw)
                    self.xheaders = True

            tornado.httpserver.HTTPServer = XheadersServer

This way it seems to work.


Enrico

-- 
GPG key: 4096R/634F4BD1E7AD5568 2009-05-08 Enrico Zini <[email protected]>

Reply via email to