Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpFoundation] Create cookie from string + synchronize response cookies#20569

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromro0NL:http-foundation/cookie-from-string
Dec 17, 2016
Merged

[HttpFoundation] Create cookie from string + synchronize response cookies#20569

fabpot merged 1 commit intosymfony:masterfromro0NL:http-foundation/cookie-from-string
Dec 17, 2016

Conversation

@ro0NL
Copy link
Contributor

@ro0NLro0NL commentedNov 19, 2016
edited
Loading

QA
Branch?"master"
Bug fix?yes
New feature?yes
BC breaks?no-ish
Deprecations?no
Tests pass?yes
Fixed ticketscomma-separated list of tickets fixed by the PR, if any
LicenseMIT
Doc PRreference to the documentation PR, if any

Fixes the conversion/synchroniczation of cookies between the object API and string API, ie;

$headers->setCookie(newCookie('foo','bar'));$headers->has('set-cookie');// true$headers->set('set-cookie','foo2=bar2',false);count($headers->getCookies());// 2

With an additional featureCookie::fromString($cookie)

The BC break happens in terms you cannot set a customSet-Cookie header anymore, all cookies are set viaset(raw)cookie by PHP.

We could go one step further by tracking misc. attributes (Cookie::getAttributes()) and populate accordingly fromCookie::fromString. If the cookie has attributes we should bypasssetcookie and write a header instead, but im not sure it's worth it.

constSAMESITE_LAX ='lax';
constSAMESITE_STRICT ='strict';

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Creates

@HeahDude
Copy link
Contributor

It seems there is no deprecation in your PR, wrong description or WIP?

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedNov 19, 2016
edited
Loading

Not sure :) i tend to think it solves more then it would break. Right now all cookies are dealt with in a consistent manner, which is good.

However we could lose some raw cookie attributes though, and people benefit from this bug before in terms of preserving those attributes. I thinkCookie should fix this in terms of getting the same output string for the given input string. Which means no BC break :)

@HeahDude

wrong description

yes :) deprecation label should be removed

@ro0NL
Copy link
ContributorAuthor

The synchronization is also missing inall,has, etc. Should this go all the way?

Or what about the other way around? Add aSet-Cookie header fromsetCookie().

@ro0NL
Copy link
ContributorAuthor

Ready :)


$headers =str_replace("\r\n",PHP_EOL, (string)$bag);
$this->assertRegExp('#^Set-Cookie:\s+foo=bar; path=/path/foo; domain=foo.bar; httponly$#m',$headers);
$this->assertRegExp('#^Set-Cookie:\s+foo=bar; path=/path/foo; domain=foo.bar; httponly$#m',$headers);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it bepath=/path/bar;?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Nice catch, also regex escaping was missing. Fixed.

@ro0NL
Copy link
ContributorAuthor

Green :)

@nicolas-grekasnicolas-grekas added this to the3.x milestoneDec 6, 2016

if ($this->path) {
$str .='; path='.$this->path;
}
Copy link
Member

Choose a reason for hiding this comment

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

Why? IIRC,path is optional.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Based onhttps://github.com/ro0NL/symfony/blob/721fc351b2dcf81ba1888682a42155288f5474d2/src/Symfony/Component/HttpFoundation/Cookie.php#L124 i chose to force/ by default here as well. Maybe it's not needed indeed.

I guess the only case we dont have a path is when a developer overridesCookie::$path (set it manually).

What about

if ($this->getPath()) {//..}

to be consistent with the domain attribute handling.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

publicfunction__toString()
{
if (!$this->headers) {
if (!$headers =$this->all()) {
Copy link
Member

Choose a reason for hiding this comment

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

If you removeheaders usage, the property should be removed as well... but it is protected, so that's a BC break.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

ResponsHeaderBag overridesall() by including the additional cookie headers.HeaderBag::all still returns$this->headers... so it's not removed.

However internally it now usesall() (the API method) instead of$headers (the property) so those cookie headers are taken into account when using for exampleHeaderBag::has.

Copy link
Member

Choose a reason for hiding this comment

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

the property is still used.

In the normal HeaderBag,->all() is a simple getter for it. But it is now overwritten in ResponseHeaderBag to add the set-cookie header

if ('' === (string)$this->getValue()) {
$str .='deleted; expires='.gmdate('D, d-M-Y H:i:s T',time() -31536001);
}else {
$str .=urlencode($this->getValue());
Copy link
Member

Choose a reason for hiding this comment

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

isn't this a bug fix ? If yes, it should go in older branches

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Guess so. I will separate it this evening 👍

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

publicfunction__toString()
{
if (!$this->headers) {
if (!$headers =$this->all()) {
Copy link
Member

Choose a reason for hiding this comment

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

the property is still used.

In the normal HeaderBag,->all() is a simple getter for it. But it is now overwritten in ResponseHeaderBag to add the set-cookie header

{
returnarray_combine($this->headerNames,$this->headers);
$headers =$this->allPreserveCase();
if (isset($this->headerNames['set-cookie'])) {
Copy link
Member

Choose a reason for hiding this comment

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

what if a case is not provided for theset-cookie header ? you will not remove it at all

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

It's always provided.. ie.here andhere

fabpot added a commit that referenced this pull requestDec 14, 2016
…ookies (ro0NL)This PR was squashed before being merged into the 3.1 branch (closes#20910).Discussion----------[HttpFoundation] Fix cookie to string conversion for raw cookies| Q             | A| ------------- | ---| Branch?       | 3.1| Bug fix?      | yes| New feature?  | not really| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#20569 (comment)| License       | MIT| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->Separated from#20569This mimics PHP's `setrawcookie` behavior.Commits-------5e899cd [HttpFoundation] Fix cookie to string conversion for raw cookies
fabpot added a commit that referenced this pull requestDec 15, 2016
This PR was merged into the 3.3-dev branch.Discussion----------[HttpFoundation] Compute cookie max-age attribute| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | comma-separated list of tickets fixed by the PR, if any| License       | MIT| Doc PR        | reference to the documentation PR, if anySeehttps://wiki.php.net/rfc/cookie_max-age, PHP sends it since 5.5.~~The date format actually differs now from PHP (`Saturday` instead of `Sat`). But it really doesnt matter much imo, using the constant seems more reliable to me and max-age overrules anyway ;)~~Relates to#20569Commits-------8c28317 [HttpFoundation] Compute cookie max-age attribute
@ro0NL
Copy link
ContributorAuthor

Rebased with the latest cookie changes. Still all good :)

@fabpot
Copy link
Member

Thank you@ro0NL.

@fabpotfabpot merged commit7314456 intosymfony:masterDec 17, 2016
fabpot added a commit that referenced this pull requestDec 17, 2016
…ze response cookies (ro0NL)This PR was merged into the 3.3-dev branch.Discussion----------[HttpFoundation] Create cookie from string + synchronize response cookies| Q             | A| ------------- | ---| Branch?       | "master"| Bug fix?      | yes| New feature?  | yes| BC breaks?    | no-ish| Deprecations? | no| Tests pass?   | yes| Fixed tickets | comma-separated list of tickets fixed by the PR, if any| License       | MIT| Doc PR        | reference to the documentation PR, if anyFixes the conversion/synchroniczation of cookies between the object API and string API, ie;```php$headers->setCookie(new Cookie('foo', 'bar'));$headers->has('set-cookie'); // true$headers->set('set-cookie', 'foo2=bar2', false);count($headers->getCookies()); // 2```With an additional feature `Cookie::fromString($cookie)`The BC break happens in terms you cannot set a custom `Set-Cookie` header anymore, all cookies are set via `set(raw)cookie` by PHP.We could go one step further by tracking misc. attributes (`Cookie::getAttributes()`) and populate accordingly from `Cookie::fromString`. If the cookie has attributes we should bypass `setcookie` and write a header instead, but im not sure it's worth it.Commits-------7314456 [HttpFoundation] Create cookie from string + synchronize response cookies
@ro0NLro0NL deleted the http-foundation/cookie-from-string branchDecember 17, 2016 19:31
fabpot added a commit that referenced this pull requestDec 19, 2016
This PR was merged into the 3.3-dev branch.Discussion----------[HttpFoundation] update changelog| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#20569| License       | MIT| Doc PR        |Commits-------e91a654 [HttpFoundation] update changelog
fabpot added a commit that referenced this pull requestDec 22, 2016
This PR was merged into the 3.3-dev branch.Discussion----------[HttpKernel] Continuation of#20569| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#20567 (comment)| License       | MIT| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->Forgotten in#20569 and makes#20567 truly a feature only.Before![image](https://cloud.githubusercontent.com/assets/1047696/21361738/971e4f8e-c6e5-11e6-8b08-8a5f8ab4f1f0.png)After![image](https://cloud.githubusercontent.com/assets/1047696/21361752/a6dc5380-c6e5-11e6-9f18-3bc3d7db94be.png)Commits-------e1616b3 [HttpKernel] Continuation of#20569
fabpot added a commit that referenced this pull requestJan 6, 2017
This PR was squashed before being merged into the 2.7 branch (closes#20972).Discussion----------[HttpFoundation] Improved set cookie header tests| Q             | A| ------------- | ---| Branch?       | 2.7 (already in master)| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->| License       | MIT| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->Separated from#20569Commits-------05bce71 [HttpFoundation] Improved set cookie header tests
fabpot added a commit that referenced this pull requestMar 22, 2017
This PR was merged into the 3.3-dev branch.Discussion----------[WebProfilerBundle] Improved cookie traffic| Q             | A| ------------- | ---| Branch?       | "master"| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | comma-separated list of tickets fixed by the PR, if any| License       | MIT| Doc PR        | reference to the documentation PR, if any![image](https://cloud.githubusercontent.com/assets/1047696/20455635/a033a814-ae60-11e6-8500-e60146f4619e.png)Relates to#20569 in terms of getting _all_ the cookies.Commits-------171c6d1 [WebProfilerBundle] Improved cookie traffic
@nicolas-grekasnicolas-grekas modified the milestones:3.x,3.3Mar 24, 2017
@fabpotfabpot mentioned this pull requestMay 1, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@stofstofstof left review comments

+2 more reviewers

@HeahDudeHeahDudeHeahDude left review comments

@chinhpl1904chinhpl1904chinhpl1904 approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

8 participants

@ro0NL@HeahDude@fabpot@stof@chinhpl1904@nicolas-grekas@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp