wso2-apimgr
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -18,3 +18,3 @@ | ||
Proxy.prototype.ajax = function(request, callback) { | ||
var debug = this.config.debug, req, data; | ||
var debug = this.config.debug, req, data, cookies; | ||
if (debug) console.log('Proxy.ajax', JSON.stringify(request)); | ||
@@ -36,8 +36,14 @@ if (typeof request.method === 'undefined') { | ||
req.open(request.method, request.url, true); | ||
if (this.cookie) { | ||
req.withCredentials = true; | ||
req.withCredentials = true; | ||
if (this.cookie && this.cookie.length>0) { | ||
req.setDisableHeaderCheck(true); | ||
req.setRequestHeader('Cookie', this.cookie); | ||
for (i=0,m=this.cookie.length;i<m;i++){ | ||
console.log("adding", this.cookie[i]); | ||
if (i>0) cookies += "; "; | ||
cookies += this.cookie[i]; | ||
} | ||
req.setRequestHeader('Cookie', cookies); | ||
} | ||
if (debug) console.log('Proxy.ajax send', request.method, request.url, data, this.cookie); | ||
if (debug) console.log('Proxy.ajax send', request.method, request.url, data, cookies); | ||
if (request.method === 'GET') { | ||
@@ -44,0 +50,0 @@ req.send(); |
@@ -6,3 +6,3 @@ | ||
var cookieRegex = /(JSESSIONID=\w*)/; | ||
var cookieRegex = /^(\w*=\w*)/; | ||
@@ -29,11 +29,12 @@ function Store(proxy){ | ||
this.proxy.ajax(request, function(err, resp, raw) { | ||
var cookie = raw.getResponseHeader('Set-Cookie'); | ||
if (err === null && cookie !== null){ | ||
cookie = cookieRegex.exec(cookie); | ||
if (cookie.length >0){ | ||
cookie = cookie[0]; | ||
_this.proxy.cookie = cookie; | ||
if (_this.proxy.config.debug) console.log('Cookie ', cookie); | ||
} | ||
} | ||
var cookies = raw.getResponseHeader('Set-Cookie'); | ||
var headers=[]; | ||
for (i=0, m=cookies.length; i<m; i++) { | ||
var cookie = cookieRegex.exec(cookies[i]); | ||
if (cookie && cookie.length >0){ | ||
headers.push(cookie[0]); | ||
} | ||
} | ||
if (_this.proxy.config.debug) console.log('Cookie Headers', headers); | ||
_this.proxy.cookie=headers; | ||
callback (err,resp); | ||
@@ -58,3 +59,3 @@ }); | ||
if (err === null) { | ||
_this.proxy.cookie = null; | ||
_this.proxy.cookie = []; | ||
} | ||
@@ -61,0 +62,0 @@ callback(err, resp); |
{ | ||
"name": "wso2-apimgr", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A lightweight JS SDK to work with the WSO2 API Manager", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
18905
547