8000 Updating symfony/http-foundation (v6.1.4 => v6.1.5) brokes file download · Issue #44399 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

Updating symfony/http-foundation (v6.1.4 => v6.1.5) brokes file download #44399

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

Closed
realtebo opened this issue Sep 30, 2022 · 10 comments
Closed

Comments

@realtebo
Copy link
  • Laravel Version: 9.280
  • PHP Version: 8.1.2
  • Database Driver & Version: Not influent

Description:

We upgraded from v9.27.0 => v9.28.0.

This syntax, note $headers, not works anymore

    $headers = [
        'Content-Type: application/pdf',
    ];

      . ...  . omissis ..

    return response()->file($pathToFile, $headers);

This only works now

    $headers = [
        'Content-Type: application/pdf',
    ];

      . ...  . omissis ..

    return response()->file($pathToFile, $headers);

This is due to the upgrade from a symfony package

  symfony/http-foundation (v6.1.4 => v6.1.5)

Actual result is that downloading a pdf with a mimetype is not working anymore because we syy in the response an header "0" with value of 'Content-Type: application/pdf'

Steps To Reproduce:

Go back until symfony/http-foundatio will back to 6.1.4.

Use old syntax

Upgrade until symfony/http-foundatio will upgrade to 6.1.5.

String array will no work any amore.
Only associative array works.

This is the guilty commit: symfony/symfony@7023db1
I opened an issue on symfony also : symfony/symfony#47747

@driesvints
Copy link
Member

Thanks for making us aware. We hope Symfony patches this soon.

@wouterj
Copy link
Contributor
wouterj commented Sep 30, 2022

For information of other Laravel users ending up here instead of in the Symfony issue:

Passing the headers as a list (['Content-Type: application/pdf']) has never worked, an associative array (['Content-Type' => 'application/pdf']) works.

It appears 6.1.5 includes a bug in the automatic configuration of content-type. As the content-type header in the parameter was never understood, the co 8000 de shown in this issue is relying on the automatic configuration.

@driesvints
Copy link
Member

Thanks @wouterj. I don't think we document using it like that and if we do we'd be happy to correct those if anyone can find them.

@realtebo
Copy link
Author
realtebo commented Oct 2, 2022

For information of other Laravel users ending up here instead of in the Symfony issue:

Passing the headers as a list (['Content-Type: application/pdf']) has never worked, an associative array (['Content-Type' => 'application/pdf']) works.

Not true. We were (guilty and wrongly) using it in 3 different projects and it worked (since a lot of time, about 2 year the oldest commit).

Anywhere, there is no documentation about HOW to send headers and I think laravel doc team should add a small example

@realtebo
Copy link
Author
realtebo commented Oct 2, 2022

Thanks @wouterj. I don't think we document using it like that and if we do we'd be happy to correct those if anyone can find them.

Yes, but also there is not documentation about the right way to do it. There is no documentation about HOW to send headers and I think laravel doc team should add a small example

@wouterj
Copy link
Contributor
wouterj commented Oct 2, 2022

Not true. We were (guilty and wrongly) using it in 3 different projects and it worked (since a lot of time, about 2 year the oldest commit).

It has worked by the shear luck that the automatic content type algorithm produced the same content type as you were passing. Doing $response->headers->allPreserveCaseWithoutCookies() (which is what is send to the client) with the provided code example shows 0 => "Content-Type: application/json" in any version of Symfony.

I think laravel doc team should add a small example

I'm sure they welcome contributions :)

@realtebo
Copy link
Author
realtebo commented Oct 2, 2022

I understand and I agree.
We was 'lucky' ... no more lucky now

@realtebo
Copy link
Author
realtebo commented Oct 2, 2022

. Doing $response->headers->allPreserveCaseWithoutCookies() (which is what is send to the client) with the provided code example shows 0 => "Content-Type: application/json" in any version of Symfony.

I have not clear in mind why.. but in previous version of pair laravel + httpfoundation it worked in a different way.
But I hope this issue will help future googlers to avoid our mistake or fix if someone did same mistake we make: we surely copy/pasted something from somewhere and from somelucky it someworked ... :)

@ryanmortier
Copy link
ryanmortier commented Oct 3, 2022

Ran into this today. All my streamed PDFs look like this:

image

@marin246
Copy link

Apparently, this should be fixed with the next symfony release: Symfony Github

Does anybody know when that will be relased?

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

5 participants
0