From 739ebde0d1fdf766bc74dbf08879b41b4e00729b Mon Sep 17 00:00:00 2001 From: Ofir Attia Date: Sat, 7 Oct 2017 18:58:35 +0300 Subject: [PATCH] Add withCredentials flag for global fetch Supporting CORS, fixing issue when using session id not on the same domain, on the global fetch there is withCredentials flag, if its true it will set the credentials to "include" otherwise to same-origin. --- lib/request.js | 11 +++++++++-- lib/requestify.js | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/request.js b/lib/request.js index 8a387b8..8fe31ee 100644 --- a/lib/request.js +++ b/lib/request.js @@ -30,7 +30,8 @@ function Request(url, options) { this.cache = options.cache || { cache: false, expires: 3600 }; this.timeout = options.timeout || 30000; this.cookies(options.cookies); - this.redirect = options.redirect || false + this.redirect = options.redirect || false; + this.withCredentials = options.withCredentials || false; } /** @@ -281,5 +282,11 @@ Request.prototype.getAuthorization = function() { return auth.username + ':' + auth.password; }; - +/** + * Returns the current withCredentials flag + * @returns {boolean} + */ +Request.prototype.getWithCredentials = function() { + return this.withCredentials; +}; module.exports = Request; diff --git a/lib/requestify.js b/lib/requestify.js index da18d85..ea1dc6f 100644 --- a/lib/requestify.js +++ b/lib/requestify.js @@ -90,7 +90,8 @@ var Requestify = (function() { method: request.method, auth: request.getAuthorization(), headers: request.getHeaders(), - redirect : request.getRedirect() + redirect : request.getRedirect(), + withCredentials: request.getWithCredentials() }; /**