Skip to content

Commit b1baf8d

Browse files
[feature] Allow extraHeaders to be set for browser clients in XHR requests (#519)
1 parent c01b9a8 commit b1baf8d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/transports/polling-xhr.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function empty () {}
3131
function XHR (opts) {
3232
Polling.call(this, opts);
3333
this.requestTimeout = opts.requestTimeout;
34+
this.extraHeaders = opts.extraHeaders;
3435

3536
if (global.location) {
3637
var isSSL = 'https:' === location.protocol;
@@ -44,8 +45,6 @@ function XHR (opts) {
4445
this.xd = opts.hostname !== global.location.hostname ||
4546
port !== opts.port;
4647
this.xs = opts.secure !== isSSL;
47-
} else {
48-
this.extraHeaders = opts.extraHeaders;
4948
}
5049
}
5150

test/transport.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,22 @@ describe('Transport', function () {
294294
});
295295
});
296296
}
297+
298+
describe('options', function () {
299+
it('should accept an `extraHeaders` option for XMLHttpRequest in browser', function () {
300+
var headers = {
301+
'X-Custom-Header-For-My-Project': 'my-secret-access-token',
302+
'Cookie': 'user_session=NI2JlCKF90aE0sJZD9ZzujtdsUqNYSBYxzlTsvdSUe35ZzdtVRGqYFr0kdGxbfc5gUOkR9RGp20GVKza; path=/; expires=Tue, 07-Apr-2015 18:18:08 GMT; secure; HttpOnly'
303+
};
304+
var socket = new eio.Socket({
305+
transportOptions: {
306+
polling: {
307+
extraHeaders: headers
308+
}
309+
}
310+
});
311+
expect(socket.transport.name).to.be('polling');
312+
expect(socket.transport.extraHeaders).to.equal(headers);
313+
});
314+
});
297315
});

0 commit comments

Comments
 (0)