summaryrefslogtreecommitdiffstats
path: root/attachment.cgi
diff options
context:
space:
mode:
authorDamien Nozay <damien.nozay@gmail.com>2014-10-24 10:14:19 +0200
committerGervase Markham <gerv@gerv.net>2014-10-24 10:14:19 +0200
commitd2685d0a7e2d75e3f334dc18babfcc53f53aa973 (patch)
treef464b10e91ee12e60f0b28a3b6f86a59d6a337e5 /attachment.cgi
parent424bbc87bd2c105c4c5c6aab6c3f101606a400ec (diff)
downloadbugzilla-d2685d0a7e2d75e3f334dc18babfcc53f53aa973.tar.gz
bugzilla-d2685d0a7e2d75e3f334dc18babfcc53f53aa973.tar.xz
Bug 1073264 - allow attachment download to be offloaded to the webserver using X-SendFile or equivalent. r=gerv, a=glob.
Diffstat (limited to 'attachment.cgi')
-rwxr-xr-xattachment.cgi18
1 files changed, 17 insertions, 1 deletions
diff --git a/attachment.cgi b/attachment.cgi
index 5db8f5909..61e6f58d8 100755
--- a/attachment.cgi
+++ b/attachment.cgi
@@ -26,6 +26,7 @@ use Bugzilla::Attachment::PatchReader;
use Bugzilla::Token;
use Encode qw(encode find_encoding);
+use Cwd qw(realpath);
# For most scripts we don't make $cgi and $template global variables. But
# when preparing Bugzilla for mod_perl, this script used these
@@ -361,9 +362,24 @@ sub view {
}
}
}
+ my $sendfile_header = {};
+ my $sendfile_param = Bugzilla->params->{'xsendfile_header'};
+ if ($attachment->is_on_filesystem && $sendfile_param ne 'off') {
+ # attachment is on filesystem and Admin turned on feature.
+ # This means we can let webserver handle the request and stream the file
+ # for us. This is called the X-Sendfile feature. see bug 1073264.
+ my $attachment_path = realpath($attachment->_get_local_filename());
+ $sendfile_header->{$sendfile_param} = $attachment_path;
+ }
print $cgi->header(-type=>"$contenttype; name=\"$filename\"",
-content_disposition=> "$disposition; filename=\"$filename\"",
- -content_length => $attachment->datasize);
+ -content_length => $attachment->datasize,
+ %$sendfile_header);
+ if ($attachment->is_on_filesystem && $sendfile_param ne 'off') {
+ # in case of X-Sendfile, we do not print the data.
+ # that is handled directly by the webserver.
+ return;
+ }
disable_utf8();
print $attachment->data;
}