Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Conversation

@ponelat
Copy link

@ponelat ponelat commented May 22, 2017

Hi,

My use case is to synchronize two cookies, one plaintext and the other a secret.
This hook allows me to update the plaintext cookie, just as the secret one gets updated.

Would love to get this merged, but don't mind alternatives. If any spring to mind.

@seanmonstar
Copy link
Contributor

So, this runs a possible callback when the cookies are serialized? And the reason to do this in your case is to so that the 2 cookies are synchronized, and you don't want to forget to update the plaintext cookie accidentally?

Could this also be achieved with another middleware and override res.writeHead again?

@ponelat
Copy link
Author

ponelat commented May 23, 2017

@seanmonstar thanks for the prompt response.
Some assumptions:

  1. We don't have access to rawSession
  2. clientSession will only write the cookie, when rawSession#isDirty

I think decorating writeHead again isn't a bad idea. But based on the assumptions above, I would need to write my plaintext cookie on every request, as apposed to when clientSession writes its cookie. Since I don't know when the rawSession is dirty ( and needs to send a new cookie ).

Hence, I just stuck a callback into client session code. So I could know exactly when clientSession was going to write its cookie, and I could do something about, it before the headers were sent.

@seanmonstar
Copy link
Contributor

If the session was dirty, you'll see the Set-Cookie header in res.getHeaders(), right?

@ponelat
Copy link
Author

ponelat commented May 23, 2017

@seanmonstar good point!
I'll see if I can't make a workaround with that in mind, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants