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

Bug fix: Replace header when sending first one of each header #2441

Merged
merged 1 commit into from
Aug 4, 2018
Merged

Bug fix: Replace header when sending first one of each header #2441

merged 1 commit into from
Aug 4, 2018

Conversation

akrabat
Copy link
Member

@akrabat akrabat commented May 16, 2018

When we call header() to send the headers in the Response, set the
replace parameter to true for the first of that header name and then
set it to false.

Don't do this if the header is Set-Cookie so we don't break sessions.

Fixes #2282
Fixes #2246

When we call `header()` to send the headers in the Response, set the
`replace` parameter to true for the first of that header name and then
set it to false.

Don't do this if the header is Set-Cookie so we don't break sessions.

Fixes #2282
Fixes #2246
@coveralls
Copy link

coveralls commented May 16, 2018

Coverage Status

Coverage increased (+0.7%) to 97.803% when pulling b504149 on akrabat:override-previously-set-headers into 2be185b on slimphp:3.x.

@ncou
Copy link

ncou commented May 17, 2018

Hi,

just my 2 cents opinion, but i believe this modification could break some applications who use multiple header. I think for example to the header Content-Security-Policy you could use multiple headers with cumulative policies. With this modification only the first header will be sent. But this case is probably rare...

Keep up the good work.

@akrabat akrabat added the Slim 3 label May 24, 2018
@akrabat akrabat removed the request for review from geggleto May 24, 2018 18:26
@@ -1742,6 +1763,80 @@ public function testResponseWithStreamReadYieldingLessBytesThanAsked()
$this->expectOutputString(str_repeat('.', Mocks\SmallChunksStream::SIZE));
}

public function testResponseReplacesPreviouslySetHeaders()

Choose a reason for hiding this comment

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

wdyt about using a dataProvider and trying to pass the test using "strange" values too?

@akrabat akrabat added this to the 3.10.1 milestone Jun 24, 2018
@akrabat
Copy link
Member Author

akrabat commented Jun 24, 2018

@ncou That's not what this patch does. It will allow multiple Content-Security-Policy headers if you add them to the Request object.

This patch replaces headers set by header() if the same header name is used in a header in the Request object.

@ncou
Copy link

ncou commented Jun 24, 2018

hummm i think i am starting to understand (or perhaps not :)). In fact this patch will replace (one time) the header if it's already present in the header() list. To sumup it will overwrite the possible headers added by the server (like for example the "Cache-Control" header). And for the Set-Cookie it will do an exception and not replace the first occurrence, because it could be added by the server (i suppose it's to handle the case with the session cookies).
Am i right ?

@akrabat
Copy link
Member Author

akrabat commented Jul 15, 2018

@ncou pretty much, yes.

@ncou
Copy link

ncou commented Jul 16, 2018

thank you it's more clear. 👍

akrabat added a commit that referenced this pull request Aug 4, 2018
@akrabat akrabat merged commit efa19d7 into slimphp:3.x Aug 4, 2018
@akrabat akrabat changed the title Replace header when sending first one of each header Bug fix: Replace header when sending first one of each header Aug 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants