From c25ab5dd47198143eccfa58f8d322f1a58ee34b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Nicouleaud?= Date: Thu, 9 Jan 2020 21:55:40 +0100 Subject: [PATCH 1/2] User-Agent header is not restricted anymore Fixes #29 --- src/001-xml_http_request.coffee | 5 ++--- test/src/headers_test.coffee | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) 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' From bcc4852db57ad554539fa7294e6a435d63c73e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Nicouleaud?= Date: Fri, 10 Jan 2020 23:27:33 +0100 Subject: [PATCH 2/2] Force Mocha to quit after tests complete --- Cakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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', ->