1 | <?php |
||
6 | class VarnishResponse |
||
7 | { |
||
8 | /** |
||
9 | * Varnish return codes (from vcli.h) |
||
10 | * https://github.com/varnishcache/varnish-cache/blob/master/include/vcli.h#L42. |
||
11 | */ |
||
12 | const VARN_SYNTAX = 100; |
||
13 | const VARN_UNKNOWN = 101; |
||
14 | const VARN_UNIMPL = 102; |
||
15 | const VARN_TOOFEW = 104; |
||
16 | const VARN_TOOMANY = 105; |
||
17 | const VARN_PARAM = 106; |
||
18 | const VARN_AUTH = 107; |
||
19 | const VARN_OK = 200; |
||
20 | const VARN_TRUNCATED = 201; |
||
21 | const VARN_CANT = 300; |
||
22 | const VARN_COMMS = 400; |
||
23 | const VARN_CLOSE = 500; |
||
24 | |||
25 | /** |
||
26 | * Varnish control command contains the status code and content length |
||
27 | * e.g. 107 59. |
||
28 | */ |
||
29 | const CONTROL_COMMAND_REGEX = '/^(\d{3}) (\d+)/'; |
||
30 | |||
31 | /** |
||
32 | * Authentication challenge length. |
||
33 | */ |
||
34 | const CHALLENGE_LENGTH = 32; |
||
35 | |||
36 | /** |
||
37 | * @var int: The varnish return code |
||
38 | */ |
||
39 | private $code = null; |
||
40 | |||
41 | /** |
||
42 | * @var int: The length of the following content |
||
43 | */ |
||
44 | private $length = null; |
||
45 | |||
46 | /** |
||
47 | * @var string: The actual content of the response |
||
48 | */ |
||
49 | private $content = ''; |
||
50 | |||
51 | /** |
||
52 | * @return int |
||
53 | */ |
||
54 | public function getCode() |
||
58 | |||
59 | /** |
||
60 | * @param int $code |
||
61 | */ |
||
62 | public function setCode($code) |
||
66 | |||
67 | /** |
||
68 | * @return int |
||
69 | */ |
||
70 | public function getLength() |
||
74 | |||
75 | /** |
||
76 | * @param int $length |
||
77 | */ |
||
78 | public function setLength($length) |
||
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getContent(): string |
||
90 | |||
91 | /** |
||
92 | * @param string $content |
||
93 | */ |
||
94 | public function setContent(string $content) |
||
98 | |||
99 | public function appendContent(string $content) |
||
103 | |||
104 | /** |
||
105 | * @return bool |
||
106 | */ |
||
107 | public function isAuthRequest() |
||
111 | |||
112 | /** |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getAuthChallenge() |
||
123 | |||
124 | /** |
||
125 | * @param $chunk |
||
126 | * @return bool |
||
127 | */ |
||
128 | public function parseControlCommand($chunk) |
||
138 | |||
139 | /** |
||
140 | * @return bool |
||
141 | */ |
||
142 | public function hasLength() |
||
146 | |||
147 | /** |
||
148 | * @return bool |
||
149 | */ |
||
150 | public function contentLengthReached() |
||
154 | |||
155 | /* |
||
156 | * @return bool |
||
157 | */ |
||
158 | public function finishedReading() |
||
162 | } |