You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using mezzio-swoole in front of the this package is problematic because this package uses a CallbackStream. mezzio-swoole isn't capable of using that currently (there is a PR for that mezzio/mezzio-swoole#31). However, even when that PR get's merged, the CallbackStream Psr7Assets echo's the contents which doesn't work with mezzio-swoole. The contents ends up in the log not in the browser :-).
A simple but somewhat naive fix would be change the echo into a return;
$callable = function () use ($path) {
$file = new SplFileObject($path);
$content = '';
while (! $file->eof()) {
$content .= $file->fgets();
}
return $content;
};
This would -however- defeat the purpose of being capable of streaming large files. So in my project I have overwritten the AssetResponder and am using a Diactoros Stream as a response. That works great!
<?php
namespace MyApp;
use Laminas\Diactoros\Stream;
use Psr\Http\Message\ResponseInterface;
class AssetResponder extends \Hkt\Psr7Asset\AssetResponder
{
/**
* Sets a 200 OK response with the asset contents.
*
* @return ResponseInterface
*/
protected function ok()
{
$response = $this->responseFactory->createResponse(200);
return $response
->withBody(new Stream($this->data->asset->path))
->withHeader('Content-Length', (string) filesize($this->data->asset->path))
->withHeader('Content-Type', $this->data->asset->type);
}
}
Before I create PR, this would introduce a dependency on laminas-diactoros or... I could write a minimal Stream implementation s was done with the CallbackStream class...
The text was updated successfully, but these errors were encountered:
using mezzio-swoole in front of the this package is problematic because this package uses a CallbackStream. mezzio-swoole isn't capable of using that currently (there is a PR for that mezzio/mezzio-swoole#31). However, even when that PR get's merged, the CallbackStream Psr7Assets echo's the contents which doesn't work with mezzio-swoole. The contents ends up in the log not in the browser :-).
https://github.com/harikt/psr7-asset/blob/master/src/AssetResponder.php#L110
A simple but somewhat naive fix would be change the echo into a return;
This would -however- defeat the purpose of being capable of streaming large files. So in my project I have overwritten the AssetResponder and am using a Diactoros Stream as a response. That works great!
Before I create PR, this would introduce a dependency on laminas-diactoros or... I could write a minimal Stream implementation s was done with the CallbackStream class...
The text was updated successfully, but these errors were encountered: