1 | <?php |
||
22 | class HeaderParser implements RobotsTxtInterface |
||
23 | { |
||
24 | /** |
||
25 | * ANSI C's asctime() format |
||
26 | */ |
||
27 | const DATE_ASCTIME = 'D M j h:i:s Y'; |
||
28 | |||
29 | /** |
||
30 | * HTTP date formats |
||
31 | * @link https://tools.ietf.org/html/rfc7231#section-7.1.1 |
||
32 | * @link https://tools.ietf.org/html/rfc2616#section-3.3 |
||
33 | */ |
||
34 | const DATE_HTTP = [ |
||
35 | DATE_RFC1123, |
||
36 | DATE_RFC850, |
||
37 | self::DATE_ASCTIME, |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * cURL resource |
||
42 | * @var resource |
||
43 | */ |
||
44 | protected $curlHandler; |
||
45 | |||
46 | /** |
||
47 | * Headers |
||
48 | * @var string[] |
||
49 | */ |
||
50 | private $headers; |
||
51 | |||
52 | /** |
||
53 | * HeaderParser constructor. |
||
54 | * |
||
55 | * @param resource $handler |
||
56 | */ |
||
57 | public function __construct($handler) |
||
61 | |||
62 | /** |
||
63 | * cURL CURLOPT_HEADERFUNCTION callback |
||
64 | * @link https://tools.ietf.org/html/rfc7230#section-3.2.4 |
||
65 | * |
||
66 | * This callback function must return the number of bytes actually taken care of. |
||
67 | * If that amount differs from the amount passed in to your function, it'll signal an error to the library. |
||
68 | * This will cause the transfer to get aborted and the libcurl function in progress will return CURLE_WRITE_ERROR. |
||
69 | * @link https://curl.haxx.se/libcurl/c/CURLOPT_HEADERFUNCTION.html |
||
70 | * |
||
71 | * @param resource $handler - cURL resource |
||
72 | * @param string $line - cURL header line string |
||
73 | * @return int - the number of bytes written |
||
74 | */ |
||
75 | public function curlCallback($handler, $line) |
||
82 | |||
83 | /** |
||
84 | * Content-Type encoding HTTP header |
||
85 | * @link https://tools.ietf.org/html/rfc2616#section-14.17 |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getCharset() |
||
98 | |||
99 | /** |
||
100 | * Get inline header variable value |
||
101 | * |
||
102 | * @param string $header |
||
103 | * @param string $part |
||
104 | * @param string $delimiter |
||
105 | * @return string|false |
||
106 | */ |
||
107 | private function getInlineValue($header, $part, $delimiter = ";") |
||
116 | |||
117 | /** |
||
118 | * Cache-Control max-age HTTP header |
||
119 | * @link https://tools.ietf.org/html/rfc7234#section-5.2.1.1 |
||
120 | * @link https://tools.ietf.org/html/rfc7234#section-5.2.2.8 |
||
121 | * @link https://tools.ietf.org/html/rfc2616#section-14.9.3 |
||
122 | * |
||
123 | * @return int |
||
124 | */ |
||
125 | public function getMaxAge() |
||
134 | |||
135 | /** |
||
136 | * Cache-Control Retry-After HTTP header |
||
137 | * @link https://tools.ietf.org/html/rfc2616#section-14.37 |
||
138 | * |
||
139 | * @param int $requestTime |
||
140 | * @return int |
||
141 | */ |
||
142 | public function getRetryAfter($requestTime) |
||
154 | |||
155 | /** |
||
156 | * Parse HTTP-date |
||
157 | * @link https://tools.ietf.org/html/rfc7231#section-7.1.1 |
||
158 | * @link https://tools.ietf.org/html/rfc2616#section-3.3 |
||
159 | * |
||
160 | * @param string $string |
||
161 | * @return int|false |
||
162 | */ |
||
163 | private function parseHttpDate($string) |
||
172 | } |
||
173 |