browserify / http-browserify

node's http module, but for the browser
MIT License
244 stars 110 forks source link

Work-around for Moz bug #608735 #8

Open nlacasse opened 12 years ago

nlacasse commented 12 years ago

Oh Firefox....

Mozilla bug #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.

Review on Reviewable