|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
/** |
|
5
|
|
|
* @copyright Copyright (c) 2020, Roeland Jago Douma <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license GNU AGPL version 3 or any later version |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
14
|
|
|
* License, or (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace OCA\DAV\Connector\Sabre; |
|
27
|
|
|
|
|
28
|
|
|
use Sabre\DAV\ServerPlugin; |
|
29
|
|
|
use Sabre\HTTP\Request; |
|
30
|
|
|
use Sabre\HTTP\Response; |
|
31
|
|
|
|
|
32
|
|
|
class PropfindCompressionPlugin extends ServerPlugin { |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Reference to main server object |
|
36
|
|
|
* |
|
37
|
|
|
* @var Server |
|
38
|
|
|
*/ |
|
39
|
|
|
private $server; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* This initializes the plugin. |
|
43
|
|
|
* |
|
44
|
|
|
* This function is called by \Sabre\DAV\Server, after |
|
45
|
|
|
* addPlugin is called. |
|
46
|
|
|
* |
|
47
|
|
|
* This method should set up the required event subscriptions. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \Sabre\DAV\Server $server |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
|
|
public function initialize(\Sabre\DAV\Server $server) { |
|
53
|
|
|
$this->server = $server; |
|
|
|
|
|
|
54
|
|
|
$this->server->on('afterMethod:PROPFIND', [$this, 'compressResponse'], 100); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function compressResponse(Request $request, Response $response) { |
|
58
|
|
|
$header = $request->getHeader('Accept-Encoding'); |
|
59
|
|
|
|
|
60
|
|
|
if ($header === null) { |
|
61
|
|
|
return $response; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (strpos($header, 'gzip') !== false) { |
|
65
|
|
|
$body = $response->getBody(); |
|
66
|
|
|
if (is_string($body)) { |
|
67
|
|
|
$response->setHeader('Content-Encoding', 'gzip'); |
|
68
|
|
|
$response->setBody(gzencode($body)); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $response; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.