Repository URL to install this package:
|
Version:
1.2.0 ▾
|
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* If the response contains 'set-cookie' headers, this method duplicates them so that they are also set on the
* local proxying domain. The local domain is localhost by default.
* @param {string} localDomain The domain in which to set the cookies
* @param {Response} response The response coming from the proxied endpoint
*/
var extendSetCookieHeadersForLocalDomain = exports.extendSetCookieHeadersForLocalDomain = function extendSetCookieHeadersForLocalDomain() {
var localDomain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'localhost';
var response = arguments[1];
var cookieSetterHeaders = response.headers['set-cookie'];
if (Array.isArray(cookieSetterHeaders)) {
// If not on localhost, prepend the domain with the `.` so it works on subdomains too
var overriddenDomain = localDomain === 'localhost' ? localDomain : '.' + localDomain;
cookieSetterHeaders.forEach(function (header) {
var cookieForLocalhost = header.replace(/Domain=.+?;/, 'Domain=' + overriddenDomain + ';');
cookieSetterHeaders.push(cookieForLocalhost);
});
}
};