Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding Cookie Value #13

Closed
jobartim44 opened this issue Nov 22, 2019 · 5 comments
Closed

Encoding Cookie Value #13

jobartim44 opened this issue Nov 22, 2019 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@jobartim44
Copy link

Hi,
I need to access the cookie value on the server-side with a Java Application (Apache Tomcat). For that the JSON String need to be encoded otherwise I have an exception.

It's simply a encodeURIComponent(JSON.stringify(this.consents)) and JSON.parse(decodeURIComponent(e.value)).

Can you imagine it as an option in the configuration ?

Thanks

@jobartim44 jobartim44 changed the title Enconding Cookie Value Encoding Cookie Value Nov 22, 2019
@felixgirault felixgirault self-assigned this Nov 22, 2019
@felixgirault
Copy link
Contributor

Hi,
It seems like a legit use case, I'm just wondering if we should add a specific configuration option (like encodeCookie: true), or something more generic that would allow the user to handle serialization any way he'd like. This could look like:

Orejime.init({
  stringifyCookie(consents) {
    return encodeURIComponent(JSON.stringify(consents));
  },
  parseCookie(cookie) {
    return JSON.parse(decodeURIComponent(cookie));
  }
});

Of course those options would default to the current behavior if not specified.
Would that solution be ok to you?

@jobartim44
Copy link
Author

The generic version is interesting, we could imagine someone wanting to crypt the data.

It ok to me.

@felixgirault
Copy link
Contributor

Here's a PR, do you want to try it out before merging ?
#14

@felixgirault felixgirault added the enhancement New feature or request label Nov 26, 2019
@jobartim44
Copy link
Author

It's ok to me you can merge it.

@felixgirault
Copy link
Contributor

Hi @jobartim44, I just released version 1.2.0 with this feature, I hope it gets the job done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants