substack/http-browserify — pull request #7 by nlacasse (2012-02-01 22:48:29+00:00)
Title: check for unsafe headers before setting header

Using http-browserify, my console was flooded with messages like this:

Refused to set unsafe header "Content-Length"
Refused to set unsafe header "User-Agent"

There are some "unsafe" headers that we cannot set on an XHR.

This is poorly documented, but I found Mozilla's list of unsafe headers here:
http://dxr.mozilla.org/mozilla/mozilla-central/content/base/src/nsXMLHttpRequest.cpp.html

And I found Webkit's list of unsafe headers here:
http://opensource.apple.com/source/WebCore/WebCore-5525.28.4/xml/XMLHttpRequest.cpp

This commit makes sure we don't call `xhr.setRequestHeader` on an unsafe header. I used the Mozilla list because it is a superset of the Webkit list.