-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Symfony duplicates content-type header #21204
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
Comments
Maybe this is an issue with your php settings regarding output buffering? http://php.net/manual/de/function.headers-sent.php#75835 Because normally the headers will not be send again: |
dmaicher, thank you for response.
This is not that case, because headers are sent before the body content.
As a result, header Content-Type is duplicated, I get FCGI error. |
Ok indeed for me in your example |
i've experienced this very same issue a few times as well, mostly triggered by the ExceptionHandler.
I've also found a possible solution, instead of using Example: <?php
public function sendHeaders()
{
// headers have already been sent by the developer
if (headers_sent() || !empty(headers_list())) {
return $this;
}
...
} i could open a pull-request for this, if no-one sees any obvious fault with this? |
Thanks Mneuhaus, your patch works ! |
Arf... now I have a mistake every morning at the same time. this error is triggered by googlebot every morning at 2:20 AM, every day. [Thu Dec 07 02:20:34 2017] [error] [client 66.249.64.19] [host www.binano.fr] (104)Connection reset by peer: AH10143: FastCGI: comm with server "/homez.xx/user/www/viewtopic.php" aborted: read failed |
@mneuhaus Is there any existing PR for this fix? Currently it isn't possible to use sendHeaders with output buffering on, without having multiple headers sent. |
@thejahweh no, there is no PR yet, because i can't really tell the implications, because this is quite deep in the core of Symfony. i could open one of course. |
I'm having the same issue with Symfony 4.0 and PHP 7.1 |
I have the same issue. By using @mneuhaus fix in // headers
foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) {
foreach ($values as $value) {
header($name.': '.$value, true, $this->statusCode);
}
} I don't have enough knowledge of the HttpFoundation to understand if these are good solutions. |
you shouldn't set the replace to true as for example the Links header can appear multiple times and this is perfectly legal. |
I was wondering why the |
Any news on this error ? I started few weeks, having the same kind of errors on production website.. |
I understand what happens here. Looking for a fix now. |
Introduced in #10941. Headers need to be recalled like the body is already. |
Should be fixed by #29057, please confirm if possible. |
I was curious about how to fix this so I read the fix you propose and it might solve the issue in most cases but actually the last thing setting "Content-Type" header will be used no matters what. And my question remains unanswered, are we sure I do not know if I made my point clear I can try to be more exhaustive if you want :) |
The answer is yes: the exception handler buffers a response that should be sent to the browser whenever the regular error handling fails. When it doesn't, it's the responsibility of the regular error handling to take over. |
…ers (nicolas-grekas) This PR was merged into the 2.8 branch. Discussion ---------- [HttpFoundation] replace any preexisting Content-Type headers | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21204 | License | MIT | Doc PR | - Commits ------- de2ce58 [HttpFoundation] replace any preexisting Content-Type headers
I use php 7.0.0 with symfony 3.1.8. The issue is when I got errors from php - symfony doesn't return me stack trace, all I can see is "Internal Server Error" page. In logs of apache I found FastCGI: comm with server "/Applications/MAMP/fcgi-bin/php7.0.0.fcgi" aborted: error parsing headers: duplicate header 'Content-Type'
I started debugging, and that's what I found. I use php scalar type hinting, so when the wrong type comes as argument, php returns TypeError, symfony catches it, and then step by step:
call_user_func($this->exceptionHandler, $exception) L:546
$this->sendPhpResponse($exception); L:121
header('Content-Type: text/html; charset='.$this->charset); L:173 - which sends me header of content type first time.
call_user_func($this->handler, $exception); L:144
$response->sendHeaders(); L:104
header($name.': '.$value, false, $this->statusCode); L:339 - which sends me header of content type second time.
The output of headers_list function:
0 = "X-Powered-By: PHP/7.0.0"
1 = "Content-Type: text/html; charset=UTF-8"
2 = "Cache-Control: no-cache"
3 = "X-Debug-Token: 242fbb"
4 = "X-Debug-Token-Link: http://pr.project/app_dev.php/_profiler/242fbb"
5 = "Content-Type: text/html; charset=UTF-8"
6 = "Date: Sun, 08 Jan 2017 18:45:04 GMT"
Which causes error of duplicating headers.
Please fix.
The text was updated successfully, but these errors were encountered: