All,
I am writing, a proxy server using HAPIJS, Flow is like this,
My Requirement is merging those arrays.
var cookie = ["dwanonymous_e2c6f8d7717c2d7504ef19ac1c9bec84=beilcabnrjOL6sxvPlTKeVNG2y; Version=1; Max-Age=15552000; Expires=Tue, 22-Sep-2015 14:03:19 GMT; Path=/", "dwsecuretoken_e2c6f8d7717c2d7504ef19ac1c9bec84=4gvDTcZD46MDDPZbiclvkj0aYtWfaWVRDA==; Version=1; Path=/; Secure; HttpOnly", "dwsid=OpzBeljqH7SuLFA88ZH9Fd_fGze-oihgfyA3Duv6FbqKjtZiGia0AW2slUuQgeWzJCwo0VzhXV6kKaeuissKkQ==; path=/; HttpOnly"]
var cookie2 = ["dwanonymous_e2c; Version=1; Max-Age=15552000; Expires=Tue, 22-Sep-2015 14:03:19 GMT; Path=/", "dwsecuretoken_e2c6f8d7717c2d7504ef19ac1c9bec84=ix9wk1fwChTLK114YG-2ZQHlL-P201JMRA==; Version=1; Path=/; Secure; HttpOnly","dwper_e2c;Version=1; Path=/; Secure; HttpOnly"]
var prepCookie1 = [];
for (var i = 0; i < cookie.length; i++) {
console.log(cookie[i], cookie.length)
second(cookie[i], i)
}
function second(db, inde) {
var getComparer1 = getComparer(db);
for (var j = 0; j < cookie2.length; j++) {
var getComparer2 = getComparer(cookie2[j]);
if (getComparer1 === getComparer2) {
prepCookie1.push(cookie2[j]);
cookie.splice(inde, 1)
cookie2.splice(inde, 1)
} else {
prepCookie1.push(db);
cookie.splice(inde, 1)
}
}
}
console.log(prepCookie1)
//[ 'dwanonymous_e2c; Version=1; Max-Age=15552000; Expires=Tue, 22-Sep-2015 14:03:19 GMT; Path=/',
//'dwsid=OpzBeljqH7SuLFA88ZH9Fd_fGze-oihgfyA3Duv6FbqKjtZiGia0AW2slUuQgeWzJCwo0VzhXV6kKaeuissKkQ==; path=/; HttpOnly' ]
function getComparer(c) {
var compare;
if (c) {
var cookieOne = c.split(';')[0];
compare = cookieOne.substring(0, cookieOne.indexOf('_'));
if (compare.indexOf('=') > -1) {
compare = compare.substring(0, compare.indexOf('='))
}
}
return compare
}
Actually my result should be,
[ 'dwanonymous_e2c; Version=1; Max-Age=15552000; Expires=Tue, 22-Sep-2015 14:03:19 GMT; Path=/','dwsid=OpzBeljqH7SuLFA88ZH9Fd_fGze-oihgfyA3Duv6FbqKjtZiGia0AW2slUuQgeWzJCwo0VzhXV6kKaeuissKkQ==; path=/; HttpOnly',"dwsecuretoken_e2c6f8d7717c2d7504ef19ac1c9bec84=ix9wk1fwChTLK114YG-2ZQHlL-P201JMRA==; Version=1; Path=/; Secure; HttpOnly","dwper_e2c;Version=1; Path=/; Secure; HttpOnly"]
But my code gives below output, Someone help me what i am doing wrong here? i am newbie.
[ 'dwanonymous_e2c; Version=1; Max-Age=15552000; Expires=Tue, 22-Sep-2015 14:03:19 GMT; Path=/','dwsid=OpzBeljqH7SuLFA88ZH9Fd_fGze-oihgfyA3Duv6FbqKjtZiGia0AW2slUuQgeWzJCwo0VzhXV6kKaeuissKkQ==; path=/; HttpOnly' ]