Skip to content

Conversation

NikoWoot
Copy link

Problem

Setting "header('Cache-Control: public, max-age=3600');" in my controller bad setted in Symfony Response (You set 0 in key and "Cache-Control: public, max-age=3600" in value).
This bug create duplication of HTTP Headers.

Solution

Use "greatResponseHeaders" (copy of apache_response_headers but available for all servers) and remove old http_headers because Symfony add all headers after pass to constructor.

// If you don't remove old headers, it's duplicated in HTTP Headers
foreach ($headers as $key => $head) {
header_remove($key);
}
Copy link
Member

Choose a reason for hiding this comment

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

I believe you could simply call header_remove(); to remove all headers (and therefore skip the foreach loop):
http://php.net/manual/fr/function.header-remove.php

Apart from this very small comment, I'm completely ok with this PR 👍

Copy link
Author

Choose a reason for hiding this comment

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

Thx for you comment.

I don't use header_remove without parameters because php.net indicate :

Caution
This function will remove all headers set by PHP, including cookies, session and the X-Powered-By headers.

Copy link
Member

Choose a reason for hiding this comment

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

I get it, let's merge this!

moufmouf added a commit that referenced this pull request May 27, 2015
Fix problem with http_headers, duplicated or bad setted in Symfony Response
@moufmouf moufmouf merged commit c81914f into thecodingmachine:5.1 May 27, 2015
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.

2 participants