Currently there is no way of modifying file_download file headers, you can only supply them and overwrite previous ones (in no specific order, unless you deliberately make sure your module is first or last in the module order).

This arose as an issue because Chrome currently has a bug which means that images can be displayed for a second and then vanish.

http://www.google.com/support/forum/p/Chrome/thread?tid=1d825178248ab136...

The solution is to remove the Content-Length which can only be achieved by weighting a module as very heavy and inserting a Content-Length => NULL array.

However this Chrome bug aside what we need is a drupal_alter() for $headers.

The attached patch adds drupal_alter('file_download_headers', $headers, $uri) to the file_download function.

Files: 
CommentFileSizeAuthor
file_download_alter_headers.patch440 bytesadaddinsane

Comments

bfroehle’s picture

Version: 7.x-dev » 8.x-dev

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Drupal 8.3.x has hook_file_download() which allows you to return headers which are merged with other implementations: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21File%21fi...

It might be a similar race condition problem in that different hooks execute arbitrarily.

This hook is invoked by FileDownloadController, which means you can also listen for KernelEvents::RESPONSE with an appropriately-weighted listener in order to modify headers: https://www.drupal.org/node/2549159 and https://www.drupal.org/node/2047751

Closing this as outdated, since the patch is for Drupal 7. Please re-open if there is still an issue.