for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Copyright (c) 2017 Viktar Dubiniuk <[email protected]>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Files_Antivirus;
use \OCP\IRequest;
class RequestHelper {
/** @var IRequest */
private $request;
public function __construct(IRequest $request) {
$this->request = $request;
}
* @return int|null
public function getUploadSize() {
// Chunks are not scanned anyway. Skip chunks dav v1 due to performance
if (\OC_FileChunking::isWebdavChunk()) {
return null;
try {
$pathInfo = $this->request->getPathInfo();
} catch (\Exception $e) {
// CLI?
$requestMethod = $this->request->getMethod();
$isRemoteScript = $this->isScriptName('remote.php');
$isDavPathV1 = $pathInfo === '/webdav' || strpos($pathInfo, '/webdav/') === 0;
$isDavPathV2 = $pathInfo === '/dav/files'
|| strpos($pathInfo, '/dav/files/') === 0
|| strpos($pathInfo, '/dav/uploads/') === 0
;
$isDavRequest = $isRemoteScript && ($isDavPathV1 || $isDavPathV2);
// No upload in progress
if (!$isDavRequest || !in_array($requestMethod, ['MOVE', 'PUT'])){
$uploadSize = (int) $this->request->getHeader('CONTENT_LENGTH');
return $uploadSize;
*
* @param $string
* @return bool
public function isScriptName($string) {
$pattern = sprintf('|/%s|', preg_quote($string));
return preg_match($pattern, $this->request->getScriptName()) === 1;