'Laravel: download() does not trigger file save dialog

My laravel(8.0) test code (web.php):

Route::get(
  '/dddd',
  fn () =>
  response()->download(public_path('version.pdf'), null, ['Content-Type' => 'application/pdf'])
);

This code works perfert in my homestead test environment. The browser will popup a file dialog and ask user to save the file.

But when I put this application inside docker (image: php:8.0-apache-buster), the popup dialog will not show and the browser open the file directly with binary characters. I tried to catch the response in chrome, the response headers is like following:

Request URL: http://redtrain.test:8080/dddd
Request Method: GET
Status Code: 200 OK
Remote Address: 192.168.10.10:8080
Referrer Policy: strict-origin-when-cross-origin
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 1305
Content-Type: text/html; charset=UTF-8
Date: Fri, 04 Mar 2022 05:39:56 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.38 (Debian)
Vary: Accept-Encoding
X-Powered-By: PHP/8.0.14

I noticed that header is not consistent with my code, maybe it is updated by Apache? Can someone give me some hint?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source