Skip to content

Commit

Permalink
[feat] Add withCredentials option (#614)
Browse files Browse the repository at this point in the history
withCredentials was always set to true, despite the browser default being false, and can now be overridden.

Closes #495
  • Loading branch information
DuBistKomisch authored and darrachequesne committed Sep 13, 2019
1 parent 0eeaa7a commit 2847411
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -196,6 +196,7 @@ Exposed as `eio` in the browser standalone build.
will be used instead.
- `forceBase64` (`Boolean`): forces base 64 encoding for polling transport even when XHR2 responseType is available and WebSocket even if the used standard supports binary.
- `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.
- `withCredentials` (`Boolean`): defaults to `true`, whether to include credentials (cookies, authorization headers, TLS client certificates, etc.) with cross-origin XHR polling requests.
- `timestampRequests` (`Boolean`): whether to add the timestamp with each
transport request. Note: polling requests are always stamped unless this
option is explicitly set to `false` (`false`)
Expand Down
2 changes: 2 additions & 0 deletions lib/socket.js
Expand Up @@ -66,6 +66,7 @@ function Socket (uri, opts) {
this.jsonp = false !== opts.jsonp;
this.forceBase64 = !!opts.forceBase64;
this.enablesXDR = !!opts.enablesXDR;
this.withCredentials = false !== opts.withCredentials;
this.timestampParam = opts.timestampParam || 't';
this.timestampRequests = opts.timestampRequests;
this.transports = opts.transports || ['polling', 'websocket'];
Expand Down Expand Up @@ -183,6 +184,7 @@ Socket.prototype.createTransport = function (name) {
jsonp: options.jsonp || this.jsonp,
forceBase64: options.forceBase64 || this.forceBase64,
enablesXDR: options.enablesXDR || this.enablesXDR,
withCredentials: options.withCredentials || this.withCredentials,
timestampRequests: options.timestampRequests || this.timestampRequests,
timestampParam: options.timestampParam || this.timestampParam,
policyPort: options.policyPort || this.policyPort,
Expand Down
1 change: 1 addition & 0 deletions lib/transport.js
Expand Up @@ -30,6 +30,7 @@ function Transport (opts) {
this.agent = opts.agent || false;
this.socket = opts.socket;
this.enablesXDR = opts.enablesXDR;
this.withCredentials = opts.withCredentials;

// SSL options for Node.js client
this.pfx = opts.pfx;
Expand Down
4 changes: 3 additions & 1 deletion lib/transports/polling-xhr.js
Expand Up @@ -77,6 +77,7 @@ XHR.prototype.request = function (opts) {
opts.agent = this.agent || false;
opts.supportsBinary = this.supportsBinary;
opts.enablesXDR = this.enablesXDR;
opts.withCredentials = this.withCredentials;

// SSL options for Node.js client
opts.pfx = this.pfx;
Expand Down Expand Up @@ -150,6 +151,7 @@ function Request (opts) {
this.isBinary = opts.isBinary;
this.supportsBinary = opts.supportsBinary;
this.enablesXDR = opts.enablesXDR;
this.withCredentials = opts.withCredentials;
this.requestTimeout = opts.requestTimeout;

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

// ie6 check
if ('withCredentials' in xhr) {
xhr.withCredentials = true;
xhr.withCredentials = this.withCredentials;
}

if (this.requestTimeout) {
Expand Down

0 comments on commit 2847411

Please sign in to comment.