-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow storing secure cookies (HTTPS)
- Loading branch information
Showing
7 changed files
with
65 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/*! [email protected].2. Jherax 2017. Visit https://github.com/jherax/proxy-storage */ | ||
/*! [email protected].3. Jherax 2017. Visit https://github.com/jherax/proxy-storage */ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(); | ||
|
@@ -562,15 +562,31 @@ function buildExpirationString(date) { | |
/** | ||
* @private | ||
* | ||
* Builds the string for the cookie's metadata. | ||
* Builds the string for the cookie metadata. | ||
* | ||
* @param {string} key: name of the metadata | ||
* @param {object} data: metadata of the cookie | ||
* @return {string} | ||
*/ | ||
function buildMetadataFor(key, data) { | ||
if (!data[key]) return ''; | ||
return '; ' + key + '=' + data[key]; | ||
return ';' + key + '=' + data[key]; | ||
} | ||
|
||
/** | ||
* @private | ||
* | ||
* Builds the whole string for the cookie metadata. | ||
* | ||
* @param {object} data: metadata of the cookie | ||
* @return {string} | ||
*/ | ||
function formatMetadata(data) { | ||
var expires = buildMetadataFor('expires', data); | ||
var domain = buildMetadataFor('domain', data); | ||
var path = buildMetadataFor('path', data); | ||
var secure = data.secure ? ';secure' : ''; | ||
return '' + expires + domain + path + secure; | ||
} | ||
|
||
/** | ||
|
@@ -608,10 +624,9 @@ function cookieStorage() { | |
if (options.domain && typeof options.domain === 'string') { | ||
metadata.domain = options.domain.trim(); | ||
} | ||
var expires = buildMetadataFor('expires', metadata); | ||
var domain = buildMetadataFor('domain', metadata); | ||
var path = buildMetadataFor('path', metadata); | ||
var cookie = key + '=' + encodeURIComponent(value) + expires + domain + path; | ||
if (options.secure === true) metadata.secure = true; | ||
var cookie = key + '=' + encodeURIComponent(value) + formatMetadata(metadata); | ||
// TODO: should encodeURIComponent(key) ? | ||
$cookie.set(cookie); | ||
}, | ||
getItem: function getItem(key) { | ||
|
Oops, something went wrong.