tornadoweb/tornado — pull request #1098 by lullis (2014-07-07 15:33:59+00:00)
Title: Small change on WSGIContainer.__call__ to allow environ method overriding in subclasses.

Scenario: you have a django application sitting behind uwsgi. This application now needs to offer some websocket capability. This application needs to be mounted on a subfolder and your cheap host really does not open many ports, and nginx/apache needs to be in front of it all times.

Problem: After replacing uwsgi with tornado, you see it running and everything looks good in your machine, until your app goes to staging and you learn that Tornado's find out that WSGIContainer does not honor environment variables such as `SCRIPT_NAME` set by nginx. With this, your poor django application is now getting all wrong reversed urls. What do?

(Mind you, I believe I see a bug report in there, but let's assume that this is by design - after all tornado is designed to be the front web server.)

Solution: Subclass WSGIContainer and override `environ`, so we can get `SCRIPT_NAME`. This should work, except that the call to environ calls explicitly for `WSGIContainer.environ`. The game is not over, you say: there are two options left:

1. Override the whole `__call__` method, and change the call on environ to the class you have.
2. Change it at the source, Luke.

This pull request - should the tornado overlords choose to accept it - argues that option number 2 makes more sense.