session
session copied to clipboard
Not possible to set cookie encode option
One of the options which can be set on cookie.serialize is encode see here
In express-session it is not possible to set this option:
- https://github.com/expressjs/session/blob/5df613c481bc7c5979aeaeac691b64ef0a5c4948/index.js#L161
- https://github.com/expressjs/session/blob/5df613c481bc7c5979aeaeac691b64ef0a5c4948/index.js#L243
- https://github.com/expressjs/session/blob/5df613c481bc7c5979aeaeac691b64ef0a5c4948/index.js#L657
- https://github.com/expressjs/session/blob/5df613c481bc7c5979aeaeac691b64ef0a5c4948/session/cookie.js#L117-L127
I believe express-session should expose this, as the default encodeUriComponent is not always the desired behaviour. I would be willing to try and put a PR together for this if it was likely to be merged promptly.
I agree, in my context, cookies are urlEncoded once more by a mechanism I have no control on and I had to patch the module to allow encode to be modified same as other ones.
diff --git a/node_modules/express-session/session/cookie.js b/node_modules/express-session/session/cookie.js
index a8b4e57..5fa4553 100644
--- a/node_modules/express-session/session/cookie.js
+++ b/node_modules/express-session/session/cookie.js
@@ -73,6 +73,28 @@ Cookie.prototype = {
return this._expires;
},
+ /**
+ * Set encode `callback`.
+ *
+ * @param {CallableFunction} callback
+ * @api public
+ */
+
+ set encode(callback) {
+ this.callback = callback;
+ },
+
+ /**
+ * Get encode `callback`.
+ *
+ * @return {CallableFunction} callback
+ * @api public
+ */
+
+ get encode() {
+ return this.callback;
+ },
+
/**
* Set expires via max-age in `ms`.
*
@@ -123,6 +145,7 @@ Cookie.prototype = {
, domain: this.domain
, path: this.path
, sameSite: this.sameSite
+ , encode: this.callback
}
},