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

How to get the cookie name when parsing? #67

Closed
goldbergyoni opened this issue Aug 16, 2017 · 4 comments
Closed

How to get the cookie name when parsing? #67

goldbergyoni opened this issue Aug 16, 2017 · 4 comments
Assignees
Labels

Comments

@goldbergyoni
Copy link

Hi,

When parsing a cookie, I can see all the properties but how can realize which key represents the cookie name? I want to iterate over all http response cookies and act on a specific cookie, this why I need its name

Thanks!

Yoni

@dougwilson
Copy link
Contributor

dougwilson commented Aug 16, 2017

Hi @Yonatannn I'm not sure what you mean; when you pare the Cookie HTTP header, you get an object back, where each key is the name of the cookie and each value is the cookie's value. You can iterate over all the properties using for in, for example:

var cookies = cookie.parse('foo=bar; equation=E%3Dmc%5E2');
for (var name in cookies) {
  console.log('cookie name = "%s", cookie value = "%s"', name, cookie[name])
}

I hope this helps!

@dougwilson dougwilson self-assigned this Aug 16, 2017
@goldbergyoni
Copy link
Author

@dougwilson thanks!

I use 'Cookie' to parse superagent http header cookies which is in the format of:
Set-Cookie: =; Domain=; Secure; HttpOnly

Do I misuse/abuse Cookie which was supposed to handle other format?

Yoni

@dougwilson
Copy link
Contributor

Ah, sorry, didn't realize. Yea, currently this module parse method only understands the format of the Cookie header. If you are inferested in formulating a pull request to add Set-Cookie parsing, that would be welcome, though you're always welcome to use a different module to accomplish your task if you are not tied to using this one :)

@markcellus

This comment was marked as spam.

@jshttp jshttp locked and limited conversation to collaborators Mar 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants