#944226 No way to use xheaders in tornado worker

Package:
gunicorn3
Source:
gunicorn
Submitter:
Enrico Zini
Date:
2019-11-08 18:18:05 UTC
Severity:
important
Tags:
#944226#5
Date:
2019-11-06 11:20:52 UTC
From:
To:
Hello,

thanks for packaging gunicorn.

I am using gunicorn to deploy a tornado server using the tornado worker.
Deployment is behind a proxy, so I need to activate xheaders in the
tornado httpserver[1], and use --forwarded-allow-ips in gunicorn.

In workers/gtornado.py, however, I see no way to set xheaders=True in
the created tornado httpserver. This seems odd because in the traceback
in this link there seems to be or have been code for it:
https://github.com/benoitc/gunicorn/issues/783

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

Enrico

[1] https://www.tornadoweb.org/en/stable/httpserver.html#http-server

#944226#10
Date:
2019-11-06 11:54:18 UTC
From:
To:
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

#944226#15
Date:
2019-11-06 18:59:34 UTC
From:
To:
Hi Enrico,

Ooh, how delightful. ;)

Would you like me to forward this issue upstream or would you be able
to do that? (I don't think this is something that Debian should change
independent of upstream, at least unless there was some kind of
disagreement over the fix…)


Best wishes,

#944226#20
Date:
2019-11-08 17:19:55 UTC
From:
To:

Enrico