From cf5a684d51e4c8b76b8bbc554d68e2ddb1e7a741 Mon Sep 17 00:00:00 2001 From: Jochen Becker Date: Tue, 23 May 2017 10:26:51 +0200 Subject: [PATCH] - added a function to remove all cookies for a URL - updated change log - incremented version for release --- CHANGELOG.md | 4 ++++ package.json | 2 +- plugin.xml | 2 +- www/advanced-http.js | 3 +++ www/angular-integration.js | 3 +++ www/cookie-handler.js | 15 ++++++++++++++- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30a5ca8..e534780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v1.5.5 + +- added a function to remove all cookies for a URL + ## v1.5.4 - fixed an error if the response has no "headers" field diff --git a/package.json b/package.json index a6e817c..251eeb2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-advanced-http", - "version": "1.5.4", + "version": "1.5.5", "description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning", "scripts": { "build": "cp node_modules/umd-tough-cookie/lib/umd-tough-cookie.js www/umd-tough-cookie.js", diff --git a/plugin.xml b/plugin.xml index a47270a..c36db0d 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.5.5"> Advanced HTTP plugin diff --git a/www/advanced-http.js b/www/advanced-http.js index c019cf6..30ccddb 100644 --- a/www/advanced-http.js +++ b/www/advanced-http.js @@ -143,6 +143,9 @@ var http = { clearCookies: function () { return cookieHandler.clearCookies(); }, + removeCookies: function (url, callback) { + cookieHandler.removeCookies(url, callback); + }, enableSSLPinning: function (enable, success, failure) { return exec(success, failure, 'CordovaHttpPlugin', 'enableSSLPinning', [enable]); }, diff --git a/www/angular-integration.js b/www/angular-integration.js index c903b91..ec525c9 100644 --- a/www/angular-integration.js +++ b/www/angular-integration.js @@ -47,6 +47,9 @@ function registerService(http) { clearCookies: function () { return http.clearCookies(); }, + removeCookies: function (url) { + return http.removeCookies(url); + }, enableSSLPinning: function (enable) { return makePromise(http.enableSSLPinning, [enable]); }, diff --git a/www/cookie-handler.js b/www/cookie-handler.js index c350d0e..a88ea6f 100644 --- a/www/cookie-handler.js +++ b/www/cookie-handler.js @@ -11,7 +11,8 @@ var cookieJar = new ToughCookie.CookieJar(store); module.exports = { setCookieFromString: setCookieFromString, getCookieString: getCookieString, - clearCookies: clearCookies + clearCookies: clearCookies, + removeCookies: removeCookies } function splitCookieString(cookieStr) { @@ -51,3 +52,15 @@ function getCookieString(url) { function clearCookies() { window.localStorage.removeItem(storeKey); } + +function removeCookies(url, cb) { + cookieJar.getCookies(url, function(error, cookies) { + if (!cookies || cookies.length === 0) { + return cb(null, []); + } + + var domain = cookies[0].domain; + + cookieJar.store.removeCookies(domain, null, cb); + }); +}