UNPKG

@tririga/tri-proxy

Version:

A development HTTP proxy for IBM TRIRIGA UX views.

54 lines (45 loc) 1.34 kB
/* * Forked from https://github.com/BrowserSync/browser-sync/blob/master/packages/browser-sync/lib/server/proxy-utils.js * When removing domain from cookies, it will not remove Secure attribute. * Copyright (c) 2016 Shane Osbourne * Licensed under the Apache 2.0 license. */ function checkCookies(res) { if (typeof res.headers["set-cookie"] !== "undefined") { res.headers["set-cookie"] = res.headers["set-cookie"].map(function (item) { return rewriteCookies(item); }); } } function rewriteCookies(rawCookie) { var objCookie = (function () { // simple parse function (does not remove quotes) var obj = {}; var pairs = rawCookie.split(/; */); pairs.forEach(function (pair) { var eqIndex = pair.indexOf("="); // skip things that don't look like key=value if (eqIndex < 0) { return; } var key = pair.substr(0, eqIndex).trim(); obj[key] = pair.substr(eqIndex + 1, pair.length).trim(); }); return obj; })(); var pairs = Object.keys(objCookie) .filter(function (item) { return item.toLowerCase() !== "domain"; }) .map(function (key) { return key + "=" + objCookie[key]; }); if (rawCookie.match(/httponly/i)) { pairs.push("HttpOnly"); } if (rawCookie.match(/secure/i)) { pairs.push("Secure"); } return pairs.join("; "); } module.exports.checkCookies = checkCookies;