substack/http-browserify — pull request #8 by nlacasse (2012-02-05 23:02:44+00:00)
Title: Work-around for Moz bug #608735

Oh Firefox....

[Mozilla bug #608735][https://bugzil.la/608735] has been open for over a year, and it's not clear if it will get fixed soon.

The bug description is basically this:
If an XHR is a CORS request, then `xhr.getAllResponseHeaders` will always return {}.

`xhr.getResponseHeader` still works as expected.

The jQuery guys have been complaining about this bug and passing around patches here:
http://bugs.jquery.com/ticket/10338

This patch is my attempt to work around the Mozilla bug. It makes `response.getHeader()` work as expected for a CORS request, which it currentlyo does not.

This patch does 3 things:

1. Renames the `res` variable to `xhr` in response.js. This makes sense, because it is an xhr, and is less likely to be confused with `Response`.
2. Stores the response's xhr in `this.xhr`, so the Response methods have access to it and don't need to pass it around.
3. Makes `response.getHeader` call `xhr.getResponseHeader` directly if the header isn't in the header hash.

The first 2 were necessary cleanup to make the 3rd possible. It touches a lot of code, but most of the changes are trivial.