From 8fdde7d8291916b50b2f711802bf57b08fef3e66 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 17 Nov 2016 22:14:52 +0100 Subject: [PATCH 1/2] Allow extraHeaders to be set for browser clients in XHR requests --- lib/transports/polling-xhr.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/transports/polling-xhr.js b/lib/transports/polling-xhr.js index 2005e5729..5088dea45 100755 --- a/lib/transports/polling-xhr.js +++ b/lib/transports/polling-xhr.js @@ -31,6 +31,7 @@ function empty () {} function XHR (opts) { Polling.call(this, opts); this.requestTimeout = opts.requestTimeout; + this.extraHeaders = opts.extraHeaders; if (global.location) { var isSSL = 'https:' === location.protocol; @@ -44,8 +45,6 @@ function XHR (opts) { this.xd = opts.hostname !== global.location.hostname || port !== opts.port; this.xs = opts.secure !== isSSL; - } else { - this.extraHeaders = opts.extraHeaders; } } From a561e968de063bf4e922e14f90fb4a099cfddc63 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Fri, 30 Dec 2016 17:02:21 +0100 Subject: [PATCH 2/2] test --- test/transport.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/transport.js b/test/transport.js index 804a707a8..7c44eaef1 100644 --- a/test/transport.js +++ b/test/transport.js @@ -294,4 +294,22 @@ describe('Transport', function () { }); }); } + + describe('options', function () { + it('should accept an `extraHeaders` option for XMLHttpRequest in browser', function () { + var headers = { + 'X-Custom-Header-For-My-Project': 'my-secret-access-token', + 'Cookie': 'user_session=NI2JlCKF90aE0sJZD9ZzujtdsUqNYSBYxzlTsvdSUe35ZzdtVRGqYFr0kdGxbfc5gUOkR9RGp20GVKza; path=/; expires=Tue, 07-Apr-2015 18:18:08 GMT; secure; HttpOnly' + }; + var socket = new eio.Socket({ + transportOptions: { + polling: { + extraHeaders: headers + } + } + }); + expect(socket.transport.name).to.be('polling'); + expect(socket.transport.extraHeaders).to.equal(headers); + }); + }); });