Skip to content

Commit 2847411

Browse files
DuBistKomischdarrachequesne
authored andcommitted
[feat] Add withCredentials option (#614)
withCredentials was always set to true, despite the browser default being false, and can now be overridden. Closes #495
1 parent 0eeaa7a commit 2847411

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ Exposed as `eio` in the browser standalone build.
196196
will be used instead.
197197
- `forceBase64` (`Boolean`): forces base 64 encoding for polling transport even when XHR2 responseType is available and WebSocket even if the used standard supports binary.
198198
- `enablesXDR` (`Boolean`): enables XDomainRequest for IE8 to avoid loading bar flashing with click sound. default to `false` because XDomainRequest has a flaw of not sending cookie.
199+
- `withCredentials` (`Boolean`): defaults to `true`, whether to include credentials (cookies, authorization headers, TLS client certificates, etc.) with cross-origin XHR polling requests.
199200
- `timestampRequests` (`Boolean`): whether to add the timestamp with each
200201
transport request. Note: polling requests are always stamped unless this
201202
option is explicitly set to `false` (`false`)

lib/socket.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function Socket (uri, opts) {
6666
this.jsonp = false !== opts.jsonp;
6767
this.forceBase64 = !!opts.forceBase64;
6868
this.enablesXDR = !!opts.enablesXDR;
69+
this.withCredentials = false !== opts.withCredentials;
6970
this.timestampParam = opts.timestampParam || 't';
7071
this.timestampRequests = opts.timestampRequests;
7172
this.transports = opts.transports || ['polling', 'websocket'];
@@ -183,6 +184,7 @@ Socket.prototype.createTransport = function (name) {
183184
jsonp: options.jsonp || this.jsonp,
184185
forceBase64: options.forceBase64 || this.forceBase64,
185186
enablesXDR: options.enablesXDR || this.enablesXDR,
187+
withCredentials: options.withCredentials || this.withCredentials,
186188
timestampRequests: options.timestampRequests || this.timestampRequests,
187189
timestampParam: options.timestampParam || this.timestampParam,
188190
policyPort: options.policyPort || this.policyPort,

lib/transport.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function Transport (opts) {
3030
this.agent = opts.agent || false;
3131
this.socket = opts.socket;
3232
this.enablesXDR = opts.enablesXDR;
33+
this.withCredentials = opts.withCredentials;
3334

3435
// SSL options for Node.js client
3536
this.pfx = opts.pfx;

lib/transports/polling-xhr.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ XHR.prototype.request = function (opts) {
7777
opts.agent = this.agent || false;
7878
opts.supportsBinary = this.supportsBinary;
7979
opts.enablesXDR = this.enablesXDR;
80+
opts.withCredentials = this.withCredentials;
8081

8182
// SSL options for Node.js client
8283
opts.pfx = this.pfx;
@@ -150,6 +151,7 @@ function Request (opts) {
150151
this.isBinary = opts.isBinary;
151152
this.supportsBinary = opts.supportsBinary;
152153
this.enablesXDR = opts.enablesXDR;
154+
this.withCredentials = opts.withCredentials;
153155
this.requestTimeout = opts.requestTimeout;
154156

155157
// SSL options for Node.js client
@@ -224,7 +226,7 @@ Request.prototype.create = function () {
224226

225227
// ie6 check
226228
if ('withCredentials' in xhr) {
227-
xhr.withCredentials = true;
229+
xhr.withCredentials = this.withCredentials;
228230
}
229231

230232
if (this.requestTimeout) {

0 commit comments

Comments
 (0)