yii2-psr7-bridge icon indicating copy to clipboard operation
yii2-psr7-bridge copied to clipboard

support sendFile and sendStreamAsFile for Response

Open niqingyang opened this issue 1 year ago • 1 comments

support sendFile and sendStreamAsFile for Response, it is ok with workerman ,hope to provide an idea,

use GuzzleHttp\Psr7\Utils;

class Response extends \yii\Psr7\web\Response
{
    /**
     * {@inheritDoc}
     */
    public function sendStreamAsFile($handle, $attachmentName, $options = [])
    {
        $response = parent::sendStreamAsFile($handle, $attachmentName, $options);
        $this->stream = Utils::streamFor($this->stream[0]);
        return $response;
    }
}

niqingyang avatar Oct 07 '22 16:10 niqingyang

Hi. sendFile and sendStreamAsFile are outstanding items that remain to be implemented. I'd prefer not to introduce Guzzle as a dependency, however if the method you outlined is sufficient and covers all of the Yii2 tests I'd consider it.

A merge request would be welcome. I'd consider a solution that doesn't depend on Guzzle.

charlesportwoodii avatar Oct 11 '22 22:10 charlesportwoodii