Make the encode option a boolean value to determine whether to encode

This commit is contained in:
Hiroki Uchikawa
2019-02-01 17:15:07 +09:00
parent 7c6eb7c794
commit f3d2053878
2 changed files with 12 additions and 8 deletions

View File

@@ -161,9 +161,13 @@ module.exports = function(RED) {
// This case clears a cookie for HTTP In/Response nodes.
// Ignore for this node.
} else if (typeof msg.cookies[name] === 'object') {
// If the encode option is specified, pass it.
var options = msg.cookies[name].encode ? {encode: msg.cookies[name].encode} : undefined;
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value, options), url);
if(msg.cookies[name].encode === false){
// If the encode option is false, the value is not encoded.
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value, {encode: String}), url);
} else {
// The value is encoded by encodeURIComponent().
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value), url);
}
} else {
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name]), url);
}