[php,cmd:open] fix #1586 RFC7233 violation, add commandsOptions.open.method

- php:connector - range request supports on GET request only
- js - add an option `commandsOptions.open.method`
```javascript
open : {
	// HTTP method that request to the connector when item URL is not valid URL.
	// If you set to "get" will be displayed request parameter in the browser's location field
	// so if you want to conceal its parameters should be given "post".
	// Nevertheless, please specify "get" if you want to enable the partial request by HTTP Range header.
	method : 'post'
},
```
This commit is contained in:
nao-pon
2016-08-09 12:07:51 +09:00
parent d736de869b
commit fb8a74cd51
3 changed files with 31 additions and 11 deletions
+22 -10
View File
@@ -27,7 +27,13 @@ class elFinderConnector {
**/
protected $header = 'Content-Type: application/json';
/**
* HTTP request method
*
* @var string
*/
protected $reqMethod = '';
/**
* Constructor
*
@@ -38,6 +44,7 @@ class elFinderConnector {
public function __construct($elFinder, $debug=false) {
$this->elFinder = $elFinder;
$this->reqMethod = strtoupper($_SERVER["REQUEST_METHOD"]);
if ($debug) {
$this->header = 'Content-Type: text/html; charset=utf-8';
}
@@ -50,8 +57,8 @@ class elFinderConnector {
* @author Dmitry (dio) Levashov
**/
public function run() {
$isPost = $_SERVER["REQUEST_METHOD"] == 'POST';
$src = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET;
$isPost = $this->reqMethod === 'POST';
$src = $isPost ? $_POST : $_GET;
if ($isPost && !$src && $rawPostData = @file_get_contents('php://input')) {
// for support IE XDomainRequest()
$parts = explode('&', $rawPostData);
@@ -151,7 +158,9 @@ class elFinderConnector {
if (isset($data['pointer'])) {
$toEnd = true;
$fp = $data['pointer'];
if (elFinder::isSeekableStream($fp) && (array_search('Accept-Ranges: none', headers_list()) === false)) {
if (($this->reqMethod === 'GET' || $this->reqMethod === 'HEAD')
&& elFinder::isSeekableStream($fp)
&& (array_search('Accept-Ranges: none', headers_list()) === false)) {
header('Accept-Ranges: bytes');
$psize = null;
if (!empty($_SERVER['HTTP_RANGE'])) {
@@ -201,13 +210,16 @@ class elFinderConnector {
// client disconnect should abort
ignore_user_abort(false);
if ($toEnd) {
fpassthru($fp);
} else {
$out = fopen('php://output', 'wb');
stream_copy_to_stream($fp, $out, $psize);
fclose($out);
if ($reqMethod !== 'HEAD') {
if ($toEnd) {
fpassthru($fp);
} else {
$out = fopen('php://output', 'wb');
stream_copy_to_stream($fp, $out, $psize);
fclose($out);
}
}
if (!empty($data['volume'])) {
$data['volume']->close($data['pointer'], $data['info']['hash']);
}