Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Add X-Accel-Redirect support for Nginx (a sibiling of X-Sendfile) #240

Merged
merged 1 commit into from
Jul 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/src/plugins/access.fs/class.fsAccessDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,22 @@ function readFile($filePathOrData, $headerType="plain", $localName="", $data=fal
header('Content-Disposition: attachment; filename="' . basename($filePathOrData) . '"');
return;
}
if($this->getFilteredOption("USE_XACCELREDIRECT", $this->repository->getId()) && $this->wrapperClassName == "fsAccessWrapper" && array_key_exists("X-Accel-Mapping",$_SERVER)){
if(!$realfileSystem) $filePathOrData = fsAccessWrapper::getRealFSReference($filePathOrData);
$filePathOrData = str_replace("\\", "/", $filePathOrData);
$filePathOrData = SystemTextEncoding::toUTF8($filePathOrData);
$mapping = explode('=',$_SERVER['X-Accel-Mapping']);
$replacecount = 0;
$accelfile = str_replace($mapping[0],$mapping[1],$filePathOrData,$replacecount);
if($replacecount == 1){
header("X-Accel-Redirect: $accelfile");
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($accelfile) . '"');
return;
} else {
AJXP_Logger::logAction("error","Problem with X-Accel-Mapping for file $filePathOrData");
}
}
$stream = fopen("php://output", "a");
if($realfileSystem){
AJXP_Logger::debug("realFS!", array("file"=>$filePathOrData));
Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/access.fs/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<global_param name="PROBE_REAL_SIZE" type="boolean" label="CONF_MESSAGE[Real Size Probing]" description="CONF_MESSAGE[Use system command line to get the filesize instead of php built-in function (fixes the 2Go limitation)]" default="false"/>
<global_param name="USE_POSIX" type="boolean" label="CONF_MESSAGE[Use POSIX]" description="CONF_MESSAGE[Use php POSIX extension to read files permissions. Only works on *nix systems.]" default="false"/>
<global_param name="USE_XSENDFILE" type="boolean" label="CONF_MESSAGE[X-SendFile Active]" description="CONF_MESSAGE[Delegates all download operations to the webserver using the X-SendFile header. Warning, this is an external module to install for Apache. Module is active by default in Lighttpd. Warning, you have to manually add the folders where files will be downloaded in the module configuration (XSendFilePath directive)]" default="false"/>
<global_param name="USE_XACCELREDIRECT" type="boolean" label="CONF_MESSAGE[X-Accel-Redirect Active]" description="CONF_MESSAGE[Delegates all download operations to nginx using the X-Accel-Redirect header. Warning, you have to add some configuration in nginx, like X-Accel-Mapping]" default="false"/>
<global_param group="MIXIN_MESSAGE[Metadata and indexation]" name="DEFAULT_METASOURCES" type="string" label="MIXIN_MESSAGE[Default Metasources]" description="MIXIN_MESSAGE[Comma separated list of metastore and meta plugins, that will be automatically applied to all repositories created with this driver]" mandatory="false" default="metastore.serial,meta.filehasher,index.lucene"/>
</server_settings>
<class_definition filename="plugins/access.fs/class.fsAccessDriver.php" classname="fsAccessDriver"/>
Expand All @@ -38,4 +39,4 @@
</hooks>
</registry_contributions>
<class_stream_wrapper filename="plugins/access.fs/class.fsAccessWrapper.php" classname="fsAccessWrapper" protocol="ajxp.fs"/>
</ajxpdriver>
</ajxpdriver>