|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Laravoole\Wrapper; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse; |
|
6
|
|
|
|
|
7
|
|
|
trait HttpTrait |
|
8
|
|
|
{ |
|
9
|
|
|
protected $accept_gzip = false; |
|
10
|
12 |
|
protected function handleResponse($response, $illuminateResponse, $accept_encoding = '') |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
12 |
|
$accept_gzip = $this->accept_gzip && stripos($accept_encoding, 'gzip') !== false; |
|
14
|
|
|
|
|
15
|
|
|
// status |
|
16
|
12 |
|
$response->status($illuminateResponse->getStatusCode()); |
|
17
|
|
|
// headers |
|
18
|
12 |
|
$response->header('Server', config('laravoole.base_config.server')); |
|
19
|
12 |
|
foreach ($illuminateResponse->headers->allPreserveCase() as $name => $values) { |
|
20
|
12 |
|
foreach ($values as $value) { |
|
21
|
12 |
|
$response->header($name, $value); |
|
22
|
6 |
|
} |
|
23
|
6 |
|
} |
|
24
|
|
|
// cookies |
|
25
|
12 |
|
foreach ($illuminateResponse->headers->getCookies() as $cookie) { |
|
26
|
12 |
|
$response->rawcookie( |
|
27
|
12 |
|
$cookie->getName(), |
|
28
|
12 |
|
urlencode($cookie->getValue()), |
|
29
|
12 |
|
$cookie->getExpiresTime(), |
|
30
|
12 |
|
$cookie->getPath(), |
|
31
|
12 |
|
$cookie->getDomain(), |
|
32
|
12 |
|
$cookie->isSecure(), |
|
33
|
12 |
|
$cookie->isHttpOnly() |
|
34
|
6 |
|
); |
|
35
|
6 |
|
} |
|
36
|
|
|
// content |
|
37
|
12 |
|
if ($illuminateResponse instanceof BinaryFileResponse) { |
|
38
|
12 |
|
$content = function () use ($illuminateResponse) { |
|
39
|
12 |
|
return $illuminateResponse->getFile()->getPathname(); |
|
40
|
12 |
|
}; |
|
41
|
12 |
|
if ($accept_gzip && isset($response->header['Content-Type'])) { |
|
42
|
12 |
|
$size = $illuminateResponse->getFile()->getSize(); |
|
|
|
|
|
|
43
|
6 |
|
} |
|
44
|
6 |
|
} else { |
|
45
|
12 |
|
$content = $illuminateResponse->getContent(); |
|
46
|
|
|
// check gzip |
|
47
|
12 |
|
if ($accept_gzip && isset($response->header['Content-Type'])) { |
|
48
|
12 |
|
$mime = $response->header['Content-Type']; |
|
49
|
|
|
|
|
50
|
12 |
|
if (strlen($content) > config('laravoole.base_config.gzip_min_length') && is_mime_gzip($mime)) { |
|
51
|
12 |
|
$response->gzip(config('laravoole.base_config.gzip')); |
|
52
|
6 |
|
} |
|
53
|
6 |
|
} |
|
54
|
|
|
} |
|
55
|
12 |
|
return $this->endResponse($response, $content); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.