Ticket #831 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

Content-Type is always text/html when using X-LIGHTTPD-send-file from PHP fastcgi

Reported by: matthias@rpmforge.net Assigned to: jan
Priority: normal Milestone:
Component: core Version: 1.4.11
Severity: normal Keywords:
Cc: Blocking:
Need Feedback: 0

Description

I'm trying to protect some video files behind a PHP script, because I need to rename them on the fly, otherwise I'd stick with mod_secdownload. My problem is that although I don't set any Content-Type header from PHP, it always ends up being "text/html" instead of the correct type which is configured in lighttpd.

It seems like lighttpd should be able to properly set that header since I see that it properly sets the Content-Length header already.

I also noticed that I could force the Content-Type to something else from the PHP script, so maybe it's PHP defaulting to text/html and lighttpd not wanting to overwrite it? Still, I'm not sure which behavior makes more sense... either way, some mean to force the Content-Type of a file sent by X-LIGHTTPD-send-file to be the mime type configured in lighttpd would seem to make sense to me.

Attachments

Change History

09/03/2006 05:36:24 PM changed by jan

  • status changed from new to closed.
  • resolution set to invalid.

X-Sendfile is only changing the Content of the response and none of the headers. As PHP uses Content-Type: text/html by default your content will be announced as HTML. lighttpd is only forwarding the headers and replaces the content.

Closed with: not a bug.

01/20/2007 03:26:41 PM changed by rhinofly

I have post a short script for send custom Content-Type base on the file name in the topic:

http://forum.lighttpd.net/topic/4403#5910

Hope this help more people.

01/22/2007 11:44:19 AM changed by matthias@rpmforge.net

  • status changed from closed to reopened.
  • resolution deleted.

Hi, I had long since forgotten this bug :-) Anyway, I know how to override the Content-Type from the PHP script, it's just that it would make more sense to me to have lighttpd be able to generate the header itself, based on the extension of the file passed to X-LIGHTTPD-send-file.

For now, what I've done in PHP is to use the fileinfo PECL module :

// Get file MIME type
if (function_exists('finfo_open')) {
        $finfo = finfo_open(FILEINFO_MIME, "/usr/share/magic");
        $mimetype = finfo_file($finfo, $file);
        finfo_close($finfo);
} else {
        $mimetype = "application/force-download";
}
header("Content-Type: " . $mimetype);

But this is all redundant, and will only slow things down. How hard would it be to have a lighttpd configure option like "x-send-file-mime-override" => <boolean> which would send out the mime type configured in "mimetype.assign" for the file extension being sent by X-LIGHTTPD-send-file?

Jan : About your first comment, lighttpd seems to be changing at least one header when X-LIGHTTPD-send-file is used, the Content-Length one.

08/17/2007 11:09:05 PM changed by jan

  • status changed from reopened to closed.
  • resolution set to fixed.
  • blocking changed.
  • pending changed.

One line in PHP vs. several lines of code in lighttpd + config-options.

Nope, I don't see a benefit in such a feature for now. Anyway, please open a feature request instead of reopening this bug. :)


Add/Change #831 (Content-Type is always text/html when using X-LIGHTTPD-send-file from PHP fastcgi)




Change Properties
Action