-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Missing Content-Length header when serving through Apache #51127
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
I think it's not a Symfony bug, rather a bug / missing feature in your http client (which is understandable if we're talking about embedded devices). Anyway, as a workaround, maybe this would do the job? namespace App\EventListener;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
class KernelResponseListener
{
public function __invoke(ResponseEvent $event)
{
$response = $event->getResponse();
$response->headers->set('Content-Length', strlen($response->getContent()));
}
} services:
App\EventListener\KernelResponseListener:
tags: ['kernel.event_listener'] |
@valtzu It's interesting that the response got the right content length when I substituted "echo json_encode" for the JsonResponse. A minor performance issue seems to be brought on by the response's lack of a content-length header. |
@aanair08 What place are talking about where you made that substitution? |
@xabbuh
|
I have solved my problem with an event listener. Thank you, @valtzu. Closing, as my problem has been resolved. |
Symfony version(s) affected
4.4.44+, v5, v6
Description
In Symfony up to 4.4.43 the Apache automatically add the
Content-Lenght
header.After the 4.4.44 (and also in 5+ and 6+) the Apache does not set this header and also switches itself to
Transfer-Encoding: chunked
. The headers sent after v4.4.44 are:How to reproduce
I have tracked this issue to appear after introducing the
flush()
call in #46931 and later moved to another place in #47434. Removing theflush()
call reverts to the original behavior in v4.4.44+ and v5.I wouldn't have noticed this change if my API wouldn't be used by some hand-crafted HTTP clients that are used inside firmwares of low-level devices. They can't parse the
chunked
responses so I really need to maintain the response encoding for some of my endpoints.I understand that such change is not a breaking change for most of the users, but in my case it prevents me from upgrading to v4.4.44 and later to v5.
Possible Solution
I would like to ask if you know of some solution that would force the Apache to behave as previously. It might be an Apache configuration or some PHP code extension. Maybe the
flush()
call should be optional and turned on in the configuration?I lack a knowledge of this internals and therefore could not come up with a solution myself.
Additional Context
No response
The text was updated successfully, but these errors were encountered: