Skip to content

Add cookie #22

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

Merged
merged 1 commit into from
Dec 29, 2015
Merged

Add cookie #22

merged 1 commit into from
Dec 29, 2015

Conversation

sagikazarmark
Copy link
Member

This PR adds Cookie implementation as discussed in php-http/httplug#98

Fix #15

A few open issues left in the original repository:
https://github.com/php-http/cookie/issues

  • php-http/cookie#4: Make CookieJar a single class and support Persistence through a separate interface
  • php-http/cookie#5: Double check matching implementation, I remember I had some issues with it

@sagikazarmark sagikazarmark added this to the v0.2 milestone Dec 27, 2015
*
* @return self
*/
public function withExpiration($expiration)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the ordering logic of these methods? for max-age its get/has/with, here its with/get/has. i propose we sort all of them the same way. has/get/with feels most natural to me but i am happy with any, as long as its consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just a mistake. I usually follow get/has/set order.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sorry, i whould have read the the phpdoc. but then i don't get what the idea is. if the param is an int, we use it as max-age, if its a datetime we use it as expires? are we sure that this is a good idea?

i would prefer to have withMaxAge remove the expires property, and vice versa.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expires is the old way of doing things, HTTP 1.1 has max-age: http://mrcoles.com/blog/cookies-max-age-vs-expires/ (IE9+ supports max-age). i guess we can keep expires support, but i would not support the mixed approach. if anything, it would be the job of some hypothetical server side code that sets expires from the max-age.

though when we speak about client side code, we could receive a cookie with both values set and might care about that (and be it just to report that the server is sending ambigous data) - so probably setting one value should not null out the other.

but i would still remove this method, it seems weird. and we could phpdoc that expires is the old way of doing things and no longer recomended

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@sagikazarmark
Copy link
Member Author

Thanks for the feedback.

@sagikazarmark
Copy link
Member Author

About the expires thing: currently you can pass an expiration parameter in the constructor. Should we have max age instead. Also, this expiration is set for both max age and expires property ATM.

Should we keep both max age and expires and only remove the magic expiration method?

@dbu
Copy link
Contributor

dbu commented Dec 27, 2015 via email

@sagikazarmark
Copy link
Member Author

What about order of arguments: should expires be the last?

public function __construct(
$name,
$value = null,
$maxAge = 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct or should default value be null?

@dbu
Copy link
Contributor

dbu commented Dec 28, 2015

👍 agree to have expires last so it can be ignored when not recording an exact Server response

* @param string|null $path
* @param bool $secure
* @param bool $httpOnly
* @param \DateTime|null $expires
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add the deprication note here too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a @deprecated phpdoc to methods as well?

@deprecated since HTTP 1.0

Copy link
Contributor

@dbu dbu Dec 28, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sagikazarmark
Copy link
Member Author

We could add cookie related helpers here.

One thing I am thinking about:

We could have the cookie parser as is OR provide a compat package around this method:

http://php.net/manual/en/function.http-parse-cookie.php

In general, we could have a pecl_http compatibility layer, but I have never used it before and don't plan in the future, so I wonder if it makes sense.

Applied fixes from StyleCI

Make CookieJar a single class

Update Cookie docblocks

Make properties private

Remove virtual expiration attribute

Improve character match tests

Improve cookie tests

Make Max-Age defatul null

Add deprecation notice to expires constructor argument

Add docblock constructor

Allow null to be passed to expires

Fine tune regex

Add some more tests for path matching

Add test for invalid max age
@sagikazarmark
Copy link
Member Author

Let's make cookie parsers in another PR. I think this is good to merge. Checked RFC compliance, but I am not sure about it. I've read the RFC several times, it is not always clear. From what I can understand, everything is OK.

dbu added a commit that referenced this pull request Dec 29, 2015
@dbu dbu merged commit 43f9488 into master Dec 29, 2015
@dbu dbu deleted the cookie branch December 29, 2015 08:36
@dbu
Copy link
Contributor

dbu commented Dec 29, 2015

the pecl_http compatibility layer sounds like a good idea but lets move forward. it can always be added later.

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

Successfully merging this pull request may close these issues.

3 participants