feature #46: support adding custom cookies

This commit is contained in:
Sefa Ilkimen
2017-11-24 18:47:00 +01:00
parent 1957cf4ef7
commit d34196ff4e
4 changed files with 27 additions and 2 deletions
+1
View File
@@ -4,6 +4,7 @@
- Feature #44: "getCookieString" method is exposed
- Feature #43: added support for content type "application/javascript" on iOS (thanks wh33ler)
- Feature #46: "setCookie" allows adding custom cookies
## v1.8.1
+15 -1
View File
@@ -114,6 +114,20 @@ Set how long to wait for a request to respond, in seconds.
cordova.plugin.http.setRequestTimeout(5.0);
```
### getCookieString
Returns saved cookies (as string) matching given URL.
```js
cordova.plugin.http.getCookieString(url);
```
### setCookie
Add a custom cookie. Takes a URL, a cookie string and an options object. See [ToughCookie documentation](https://github.com/salesforce/tough-cookie#setcookiecookieorstring-currenturl-options-cberrcookie) for allowed options.
```js
cordova.plugin.http.setCookie(url, cookie, options);
```
### clearCookies
Clear the cookie store.
@@ -157,7 +171,7 @@ This function was removed in v1.6.2. Domain name validation is disabled automati
Remove all cookies associated with a given URL.
```js
cordova.plugin.http.removeCookies(url);
cordova.plugin.http.removeCookies(url, callback);
```
### post<a name="post"></a>
+4 -1
View File
@@ -171,8 +171,11 @@ var http = {
setDataSerializer: function (serializer) {
this.dataSerializer = checkSerializer(serializer);
},
setCookie: function (url, cookie, options) {
cookieHandler.setCookie(url, cookie, options);
},
clearCookies: function () {
return cookieHandler.clearCookies();
cookieHandler.clearCookies();
},
removeCookies: function (url, callback) {
cookieHandler.removeCookies(url, callback);
+7
View File
@@ -10,6 +10,7 @@ var cookieJar = new ToughCookie.CookieJar(store);
module.exports = {
setCookieFromString: setCookieFromString,
setCookie: setCookie,
getCookieString: getCookieString,
clearCookies: clearCookies,
removeCookies: removeCookies
@@ -45,6 +46,12 @@ function setCookieFromString(url, cookieStr) {
}
}
function setCookie(url, cookie, options) {
options = options || {};
options.ignoreError = false;
cookieJar.setCookieSync(cookie, url, options);
}
function getCookieString(url) {
return cookieJar.getCookieStringSync(url);
}