Skip to content
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

Ability to pass HTTP headers? #321

Open
liepumartins opened this issue Mar 16, 2023 · 0 comments
Open

Ability to pass HTTP headers? #321

liepumartins opened this issue Mar 16, 2023 · 0 comments

Comments

@liepumartins
Copy link

Laravel Vapor requires custom headers for binary file downloads. https://docs.vapor.build/1.0/projects/development.html#binary-responses

Attempting to do

return (new FastExcel($data))->download('name.xlsx'); 

will cause an error

Fatal error: Uncaught Exception: Error encoding runtime JSON response: Malformed UTF-8 characters, possibly incorrectly encoded in /var/task/vendor/laravel/vapor-core/src/Runtime/NotifiesLambda.php:49 

I see that streamDownload() can take HTTP headers, but there is no way to pass them down from calling download().

return response()->streamDownload(function () use ($path, $callback) {

Trying to extend the class and customize download method is not viable as many used methods are private.

This should work

public function download($path, callable $callback = null)
    {
        if (method_exists(response(), 'streamDownload')) {
            return response()->streamDownload(function () use ($path, $callback) {
                self::exportOrDownload($path, 'openToBrowser', $callback);
            }, null, ['X-Vapor-Base64-Encode' => 'True']);
        }
        self::exportOrDownload($path, 'openToBrowser', $callback);

        return '';
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant