karma-runner/karma — pull request #1130 by kahnjw (2014-07-11 20:39:00+00:00)
Title: Add X-Forwarded-Host support to proxy

This adds support for X-Forwarded-Host support to karma's proxy. This is necessary for backends that perform CSRF token checks and use X-Forwarded-Host header fields to perform referrer checks.

Example use case: an integration test against a CSRF Protected Django API endpoint. If X-Forwarded-Host header is not present and the API is configured to use this (many are) the referrer check will fail. This commit fixes that.

Also, I wasn't sure whether to include a configuration parameter to add this header field conditionally, or just always add it. Would like some input on this.

This code is tough to test because the function being changed is wrapped in createProxyHandler(). It seems like it could use a good refactor to make it more testable. I am willing to do that, but would do it in a subsequent commit. Any thoughts on that?