cookie icon indicating copy to clipboard operation
cookie copied to clipboard

Update serialize to accept a object of key/values.

Open jgornick opened this issue 9 years ago • 7 comments

The serialize method should be updated to accept an object of key/values and serialize to a cookie string. This would make the serialize/parse methods complement each other.

jgornick avatar Mar 27 '15 15:03 jgornick

I could agree with that. PR would be appreciated.

defunctzombie avatar Mar 27 '15 19:03 defunctzombie

@frogcjn It looks like #47 is a PR for this functionality.

@dougwilson This issue should be closed and marked as a duplicate, right?

jgornick avatar Aug 04 '16 15:08 jgornick

This issue should be closed and marked as a duplicate, right?

Why? This issue was opening prior to that PR, so if anything should be closed for being a duplicate, it should be the PR, right?

dougwilson avatar Aug 04 '16 15:08 dougwilson

@dougwilson I didn't see that the PR (#47) referenced this issue in the description:

Resolves #30

So, in my view, yes this issue should stay open until the PR has been merged.

jgornick avatar Aug 04 '16 15:08 jgornick

I have another use-case for Cookie.serialize to accept objects that goes beyond Set-Cookie, which you may not have considered.

I'm building a WebExtension that modifies the Cookie header of requests going out of the browser. This library has been very useful in parsing the cookies into objects, but isn't as convenient to serialize them back to a single Cookie line.

I realize that mine is probably an edge-case, but I found it surprising that the parse, and serialize do not compliment one another. i.e, Cookie.serialize(Cookie.parse(str)) === str

gurupras avatar Mar 01 '20 03:03 gurupras

Hi @gurupras , I don't think this issue will help you, though, because this proposal will still not make them compliment one another as you're expecting, as Cookie.serialize creates Set-Cookie header format and not the Cookie header format. Accepting an object (as in this proposal) would not change that; it sounds like you are make a separate request from the one in this issue.

dougwilson avatar Mar 01 '20 03:03 dougwilson

I have wanted this feature recently and updated it to create a new PR against the current state of the main branch.

#119

export-mike avatar Jan 13 '21 01:01 export-mike