diff --git a/nginx_accel_redirect.module b/nginx_accel_redirect.module index f8a0269..4457117 100644 --- a/nginx_accel_redirect.module +++ b/nginx_accel_redirect.module @@ -22,17 +22,17 @@ function nginx_accel_redirect_help($path, $arg) { case 'admin/help#nginx_accel_redirect': $output = t('

The Nginx Accel Redirect Module implements the ' . l('XSendfile', 'http://wiki.nginx.org/XSendfile', array('attributes' => array('rel' => 'external'))) . ' facility in Nginx with Drupal.') . '

'; - $output .= '

' . t('You have to specify a private path at the' . ' ' . l(t('file settings page'), 'admin/config/media/file-system') . ' and then enable the X-Accel-Redirect transfer at the module ' . l(t('settings page'), 'admin/config/media/file-system/nginx-accel-redirect')) . '.

'; + $output .= '

' . t('You have to specify a private path at the' . ' ' . l(t('file settings page'), 'admin/settings/file-system') . ' and then enable the X-Accel-Redirect transfer at the module ' . l(t('settings page'), 'admin/settings/file-system/nginx-accel-redirect')) . '.

'; return $output; break; - case 'admin/config/media/file-system': + case 'admin/settings/file-system': $output = ''; if (module_exists('help')) { - $output = '

' . t('If using a private file system please enable fast file transfers using X-Accel-Redirect at the module ') . l(t('settings page'), 'admin/config/media/file-system/nginx-accel-redirect') . '.

'; + $output = '

' . t('If using a private file system please enable fast file transfers using X-Accel-Redirect at the module ') . l(t('settings page'), 'admin/settings/file-system/nginx-accel-redirect') . '.

'; } return $output; break; - case 'admin/config/media/file-system/nginx-accel-redirect': + case 'admin/settings/file-system/nginx-accel-redirect': $output = ''; if (module_exists('help')) { $output = '

' . t('To use Nginx X-Accel-Redirect for fast private file transfer enable it below.') . '

'; @@ -85,14 +85,26 @@ function nginx_accel_redirect_file_transfer() { $args = func_get_args(); // Get the stream wrapper scheme. $scheme = array_shift($args); + // In some cases, $scheme is actually already a full URI, but we need a bare $scheme variable as well. + if (!file_valid_uri($scheme)) { // Get the target: URI = scheme://target. $target = implode('/', $args); $uri = $scheme . '://' . $target; - - // Revert to default file_download if set to use PHP for transfer + } + else if (file_valid_uri($scheme)) { + $uri = $scheme; + $scheme = file_uri_scheme($scheme); + } + // Revert to default file_download if set to use PHP for transfer. if (!variable_get('nginx_accel_redirect_transfer', NGINX_ACCEL_REDIRECT_PHP_TRANSFER)) { - array_unshift($args, 'private'); // add the page argument back on - stream wrapper scheme + // Add the page argument back on - stream wrapper scheme. + if ($scheme == 'private') { + array_unshift($args, 'private'); + } + else if ($scheme == 'public') { + array_unshift($args, 'public'); + } call_user_func_array('file_download', $args); exit(); } @@ -118,8 +130,15 @@ function nginx_accel_redirect_file_transfer() { } drupal_send_headers(); // Setting the X-Accel-Redirect header for Nginx. - header('X-Accel-Redirect: ' . base_path() . variable_get('file_private_path', '') . '/' . file_uri_target($uri)); - exit(); + // Final path for header will vary based on scheme. + if ($scheme == 'private') { + header('X-Accel-Redirect: ' . base_path() . variable_get('file_private_path', '') . '/' . file_uri_target($uri)); + exit(); + } + else if ($scheme == 'public') { + header('X-Accel-Redirect: ' . base_path() . variable_get('file_public_path', '') . '/' . file_uri_target($uri)); + exit(); + } } } return drupal_not_found();