diff --git a/Cakefile b/Cakefile index d23d8ff..f0d15a6 100644 --- a/Cakefile +++ b/Cakefile @@ -20,7 +20,7 @@ task 'test', -> ssl_cert -> test_cases = glob.sync 'test/js/**/*_test.js' test_cases.sort() # Consistent test case order. - run 'node_modules/.bin/mocha --colors --slow 200 --timeout 1000 ' + + run 'node_modules/.bin/mocha --colors --slow 200 --timeout 1000 --exit ' + "--require test/js/helpers/setup.js #{test_cases.join(' ')}" task 'webtest', -> diff --git a/src/001-xml_http_request.coffee b/src/001-xml_http_request.coffee index 3e448b4..a37a073 100644 --- a/src/001-xml_http_request.coffee +++ b/src/001-xml_http_request.coffee @@ -379,7 +379,6 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget trailer: true 'transfer-encoding': true upgrade: true - 'user-agent': true via: true # HTTP response headers that should not be exposed according to the XHR spec. @@ -391,7 +390,7 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget 'set-cookie': true 'set-cookie2': true - # The value of the User-Agent header. + # The default value of the User-Agent header. _userAgent: "Mozilla/5.0 (#{os.type()} #{os.arch()}) " + "node.js/#{process.versions.node} v8/#{process.versions.v8}" @@ -483,7 +482,7 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget @_headers['Host'] = @_url.host if @_anonymous @_headers['Referer'] = 'about:blank' - @_headers['User-Agent'] = @_userAgent + @_headers['User-Agent'] ||= @_userAgent @upload._finalizeHeaders @_headers, @_loweredHeaders undefined diff --git a/test/src/headers_test.coffee b/test/src/headers_test.coffee index 4ba33a8..09e038b 100644 --- a/test/src/headers_test.coffee +++ b/test/src/headers_test.coffee @@ -10,6 +10,7 @@ describe 'XMLHttpRequest', -> describe 'with allowed headers', -> beforeEach -> @xhr.setRequestHeader 'Authorization', 'lol' + @xhr.setRequestHeader 'User-Agent', 'toaster' @xhr.setRequestHeader 'X-Answer', '42' @xhr.setRequestHeader 'X-Header-Name', 'value' @@ -19,6 +20,8 @@ describe 'XMLHttpRequest', -> headers = JSON.parse @xhr.responseText expect(headers).to.have.property 'authorization' expect(headers['authorization']).to.equal 'lol' + expect(headers).to.have.property 'user-agent' + expect(headers['user-agent']).to.equal 'toaster' expect(headers).to.have.property 'x-answer' expect(headers['x-answer']).to.equal '42' expect(headers).to.have.property 'x-header-name'