question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Get Cookies` should support returning cookies as objects and have better logging

See original GitHub issue

Currently Get Cookies returns a cookies as a string in format cookie1=value1; cookie2=value2. This isn’t very useful if you need to actually handle all cookies somehow, and the return format isn’t even documented anywhere. We should change the keyword to return cookies as a list (or ordered dictionary) of CookieInformation objects that were introduced as part of #932.

Changing keyword return value is obviously backwards incompatible, so we cannot do it without a deprecation period. I propose that in v3.1 we add an argument like return_objects=False that can be used to explicitly change the return value. This allows users to opt-in if they want to get objects. In v3.2 we could then change the argument to return_objects=True, making it possible to opt-out if needed. And in v3.3 or later the whole argument can be removed. This issue only covers adding return_objects=False (or similar), changing and removing it later require separate issues later.

Another problem in Get Cookies is that it doesn’t log anything. The beginning of the return value is logged automatically if the return value is assigned to a variable, but it would be better to log at least names and values explicitly.


UPDATE: @Mohorelien commented below that there actually is a use case for the current format in HTTP request headers. I still think having a way to return cookie information as objects is useful, but we should preserver the current functionality too. I’d also keep the current functionality as the default functionality to avoid all backwards incompatible changes. That way this change could even be done in SL 3.0 if we have time.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pekkaklarckcommented, Nov 1, 2017

Thanks @Mohorelien for letting us know about this use case! Since the current format actually is useful, I think it’s better we leave it like it is and add an optional argument like objects=False that can be used if CookieInformation objects are needed. This simplifies things a lot as adding such functionality is not backwards incompatible and we don’t need to deprecate anything. Implementation is also so simple that this could even make it to 3.0.

1reaction
aaltatcommented, Oct 31, 2017

There seems to be real use case for the current format, we did not know that. Thank you for the input. We did have a different use case in mind and it’s seems that we have to think this little bit more.

Because there is a good use case for the current format, we should provide support for it. Either by this keyword or by some other means. But it would be good to enhance keyword to actually return cookies as an object which would provide possibly to iterate through the cookies with for loop and provide a value suitable for the RequestLibrary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Everything You Need to Know About Cookies for Web ...
Cookies with HttpOnly can only be accessed by the server, and not by the browser's Document.cookie API. This is perfect for things like...
Read more >
Protractor: getting cookie value returns object instead of the ...
Both getCookie and getCookies return a JSON object, so this seems to be working correctly. Try using console.dir() to print out the object....
Read more >
How to wrap your head around the cookie object - Medium
The document.cookie property allows you to store a string that will persist data across page reloads and different pages in the same domain!...
Read more >
SameSite cookies explained - web.dev
Learn how to mark your cookies for first-party and third-party usage with the SameSite attribute. You can enhance your site's security by ...
Read more >
Caching content based on cookies - Amazon CloudFront
That can cause CloudFront to forward more requests to the origin for the same ... CloudFront also caches the Set-Cookie headers with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found