Skip to content

Commit fc078f1

Browse files
authored
User-Agent header is not restricted anymore (#37)
* User-Agent header is not restricted anymore Fixes #29 * Force Mocha to quit after tests complete
1 parent da629e9 commit fc078f1

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

Cakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ task 'test', ->
2020
ssl_cert ->
2121
test_cases = glob.sync 'test/js/**/*_test.js'
2222
test_cases.sort() # Consistent test case order.
23-
run 'node_modules/.bin/mocha --colors --slow 200 --timeout 1000 ' +
23+
run 'node_modules/.bin/mocha --colors --slow 200 --timeout 1000 --exit ' +
2424
"--require test/js/helpers/setup.js #{test_cases.join(' ')}"
2525

2626
task 'webtest', ->

src/001-xml_http_request.coffee

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget
379379
trailer: true
380380
'transfer-encoding': true
381381
upgrade: true
382-
'user-agent': true
383382
via: true
384383

385384
# HTTP response headers that should not be exposed according to the XHR spec.
@@ -391,7 +390,7 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget
391390
'set-cookie': true
392391
'set-cookie2': true
393392

394-
# The value of the User-Agent header.
393+
# The default value of the User-Agent header.
395394
_userAgent: "Mozilla/5.0 (#{os.type()} #{os.arch()}) " +
396395
"node.js/#{process.versions.node} v8/#{process.versions.v8}"
397396

@@ -483,7 +482,7 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget
483482
@_headers['Host'] = @_url.host
484483
if @_anonymous
485484
@_headers['Referer'] = 'about:blank'
486-
@_headers['User-Agent'] = @_userAgent
485+
@_headers['User-Agent'] ||= @_userAgent
487486
@upload._finalizeHeaders @_headers, @_loweredHeaders
488487
undefined
489488

test/src/headers_test.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe 'XMLHttpRequest', ->
1010
describe 'with allowed headers', ->
1111
beforeEach ->
1212
@xhr.setRequestHeader 'Authorization', 'lol'
13+
@xhr.setRequestHeader 'User-Agent', 'toaster'
1314
@xhr.setRequestHeader 'X-Answer', '42'
1415
@xhr.setRequestHeader 'X-Header-Name', 'value'
1516

@@ -19,6 +20,8 @@ describe 'XMLHttpRequest', ->
1920
headers = JSON.parse @xhr.responseText
2021
expect(headers).to.have.property 'authorization'
2122
expect(headers['authorization']).to.equal 'lol'
23+
expect(headers).to.have.property 'user-agent'
24+
expect(headers['user-agent']).to.equal 'toaster'
2225
expect(headers).to.have.property 'x-answer'
2326
expect(headers['x-answer']).to.equal '42'
2427
expect(headers).to.have.property 'x-header-name'

0 commit comments

Comments
 (0)