1 | <?php |
||
12 | class VarnishResponse |
||
13 | { |
||
14 | /** |
||
15 | * Varnish return codes (from vcli.h) |
||
16 | * https://github.com/varnishcache/varnish-cache/blob/master/include/vcli.h#L42. |
||
17 | */ |
||
18 | const VARN_SYNTAX = 100; |
||
19 | const VARN_UNKNOWN = 101; |
||
20 | const VARN_UNIMPL = 102; |
||
21 | const VARN_TOOFEW = 104; |
||
22 | const VARN_TOOMANY = 105; |
||
23 | const VARN_PARAM = 106; |
||
24 | const VARN_AUTH = 107; |
||
25 | const VARN_OK = 200; |
||
26 | const VARN_TRUNCATED = 201; |
||
27 | const VARN_CANT = 300; |
||
28 | const VARN_COMMS = 400; |
||
29 | const VARN_CLOSE = 500; |
||
30 | |||
31 | /** |
||
32 | * Varnish control command contains the status code and content length |
||
33 | * e.g. 107 59 |
||
34 | */ |
||
35 | const CONTROL_COMMAND_REGEX = '/^(\d{3}) (\d+)/'; |
||
36 | |||
37 | /** |
||
38 | * Authentication challenge length |
||
39 | */ |
||
40 | const CHALLENGE_LENGTH = 32; |
||
41 | |||
42 | /** |
||
43 | * @var $code int: The varnish return code |
||
44 | */ |
||
45 | private $code = null; |
||
46 | |||
47 | /** |
||
48 | * @var $length int: The length of the following content |
||
49 | */ |
||
50 | private $length = null; |
||
51 | |||
52 | /** |
||
53 | * @var $content string: The actual content of the response |
||
54 | */ |
||
55 | private $content = ''; |
||
56 | |||
57 | /** |
||
58 | * @return int |
||
59 | */ |
||
60 | public function getCode() |
||
64 | |||
65 | /** |
||
66 | * @param int $code |
||
67 | */ |
||
68 | public function setCode($code) |
||
72 | |||
73 | /** |
||
74 | * @return int |
||
75 | */ |
||
76 | public function getLength() |
||
80 | |||
81 | /** |
||
82 | * @param int $length |
||
83 | */ |
||
84 | public function setLength($length) |
||
88 | |||
89 | /** |
||
90 | * @return string |
||
91 | */ |
||
92 | public function getContent(): string |
||
96 | |||
97 | /** |
||
98 | * @param string $content |
||
99 | */ |
||
100 | public function setContent(string $content) |
||
104 | |||
105 | public function appendContent(string $content) |
||
109 | |||
110 | /** |
||
111 | * @return bool |
||
112 | */ |
||
113 | public function isAuthRequest() { |
||
116 | |||
117 | /** |
||
118 | * @return bool|string |
||
119 | */ |
||
120 | public function getAuthChallenge() { |
||
123 | |||
124 | /** |
||
125 | * @param $chunk |
||
126 | * @return bool |
||
127 | */ |
||
128 | public function parseControlCommand($chunk) { |
||
137 | |||
138 | /** |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function hasLength() { |
||
144 | |||
145 | /** |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function contentLengthReached() { |
||
151 | |||
152 | /* |
||
153 | * @return bool |
||
154 | */ |
||
155 | public function finishedReading() { |
||
158 | } |