flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.6k stars 407 forks source link

Fix content length when using response body callbacks #572

Closed BelleNottelling closed 3 months ago

BelleNottelling commented 3 months ago

571 introduced an issue where the response body could be modified after Flight calculates & sends the content length to the browser. Since the response body callback modifies the body, the content length is no longer correct.

In my testing things seemed to still work okay locally with the PHP dev server, but once I moved to an actual server I noticed the browser would sit and continue to try to load after the body has already sent as the response body was compressed after the content length was sent.

Switching the order so the callback is called and then headers are sent fixes this

n0nag0n commented 3 months ago

Want to give my changes a go real quick to make sure I didn't mess up anything on your end?

BelleNottelling commented 3 months ago

Want to give my changes a go real quick to make sure I didn't mess up anything on your end?

Still works as expected on my end, thanks for checking

n0nag0n commented 3 months ago

Merged and released as v3.8.1. Thanks for the assist!

BelleNottelling commented 2 months ago

Thanks for getting this merged and releasing the fix!