tikiatua/internal-assets-plugin

Headers already sent

playcraftSystems opened this issue · 2 comments

Hello!

My php error log is filling up every second with a 'Headers already sent' error. Do you think you can look into this? Is it something I've done? This error occurs on any webpage accessing the internal assets. The error also injects itself at the bottom of internal xml documents (though the extension is labelled .kcd).

An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in /Users/johnathonsouthworth/Documents/Projects/playcraft/playcraft-craft/vendor/saccilottoconsulting/craft-internal-assets/src/controllers/AccessController.php on line 134. in /Users/johnathonsouthworth/Documents/Projects/playcraft/playcraft-craft/vendor/yiisoft/yii2/web/Response.php:368
Stack trace:
#0 /Users/johnathonsouthworth/Documents/Projects/playcraft/playcraft-craft/vendor/yiisoft/yii2/web/Response.php(341): yii\web\Response->sendHeaders()
#1 /Users/johnathonsouthworth/Documents/Projects/playcraft/playcraft-craft/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send()
#2 /Users/johnathonsouthworth/Documents/Projects/playcraft/playcraft-craft/vendor/craftcms/cms/src/web/ErrorHandler.php(192): yii\web\ErrorHandler->renderException(Object(yii\web\HeadersAlreadySentException))
#3 /Users/johnathonsouthworth/Documents/Projects/playcraft/playcraft-craft/vendor/yiisoft/yii2/base/ErrorHandler.php(152): craft\web\ErrorHandler->renderException(Object(yii\web\HeadersAlreadySentException))
#4 /Users/johnathonsouthworth/Documents/Projects/playcraft/playcraft-craft/vendor/craftcms/cms/src/web/ErrorHandler.php(66): yii\base\ErrorHandler->handleException(Object(yii\web\HeadersAlreadySentException))
#5 [internal function]: craft\web\ErrorHandler->handleException(Object(yii\web\HeadersAlreadySentException))
#6 {main}
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in /Users/johnathonsouthworth/Documents/Projects/playcraft/playcraft-craft/vendor/saccilottoconsulting/craft-internal-assets/src/controllers/AccessController.php on line 134. in /Users/johnathonsouthworth/Documents/Projects/playcraft/playcraft-craft/vendor/yiisoft/yii2/web/Response.php:368

Hi @playcraftSystems,

Thank you for reporting this. Probably a problem with my use of the fpassthrough method to send the file content stream to the browser. I replaced the respective section with yii2's sendStreamAsFile method, as they use as well for the Craft admin panel, and it should hopefully work correctly now.

This should also add support for mp4 files on mobiles, since the new method also supports range headers, which are often employed on mobile devices to load only partial video content.
https://www.yiiframework.com/doc/api/2.0/yii-web-response#sendStreamAsFile()-detail

Please update your plugin installation to version 4.1.0 and check if it works then.

It works! Thanks.