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

HTTP client: Support for handling cookies #445

Open
JustBeYou opened this issue Mar 7, 2022 · 3 comments
Open

HTTP client: Support for handling cookies #445

JustBeYou opened this issue Mar 7, 2022 · 3 comments

Comments

@JustBeYou
Copy link

While I was trying to port some blocking libcURL code to ReactPHP I found there is no support for handling cookies when using the HTTP client. Inspired by other clients (especially cURL) I propose that the following features should be added:

  • compliance with HTTP State Management Mechanism (expiration, send the cookie only to the corresponding domain, etc.)
  • cookie support can be enabled/disabled
  • cookies can be added/removed manually
  • serialization/deserialization to/from a format like Netscape Cookie Jar (ideally this should be decoupled so other formats could be easily added)

As suggested by @WyriHaximus, storing the cookie jar could be done with react/cache which I find totally ok. Saving and loading to/from files could be implemented by the user or we could build something on top of ArrayCache.

After we settle the details of this, I would be happy to implement it :D

@WyriHaximus
Copy link
Member

As suggested by @WyriHaximus, storing the cookie jar could be done with react/cache which I find totally ok. Saving and loading to/from files could be implemented by the user or we could build something on top of ArrayCache.

The main reason I mentioned react/cache is so that other 3rd party packages can also provide storage: https://packagist.org/?query=react%20cache

After we settle the details of this, I would be happy to implement it :D

<3!

@clue
Copy link
Member

clue commented Mar 10, 2022

@JustBeYou Excellent input, would love to see this in ReactPHP!

The HTTP Set-Cookie request headers and Cookie response headers are indeed supported just fine in ReactPHP, but there's no automatic behavior to make sense from them, so you'd have to "remember" the values somehow as suggested. Being able to turn this on and off makes perfect sense. The Cache component might indeed be a possible candidate here, but actual semantics may demand a dedicated interface. Sounds like you're on to something already, so I'm curious what you're going to come up with.

@clue clue changed the title Support for handling cookies on the client side HTTP client: Support for handling cookies Aug 26, 2022
@clue
Copy link
Member

clue commented Aug 26, 2022

Providing an API to set and retrieve cookies isn't really too hard, but we'd also have to take persistence into consideration. I don't think there's an agreed upon standard, but the Netscape cookie file format used by curl seems to be a decent contender.

acme.localhost   FALSE   /   FALSE   0   session  abc123

Some useful pointers:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants