PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.3
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.3
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / htaccess-capability-tester / src / SimpleHttpRequester.php

SimpleHttpRequester.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.3, at vendor/rosell-dk/htaccess-capability-tester/src/SimpleHttpRequester.php

49 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace HtaccessCapabilityTester;
4
5 class SimpleHttpRequester implements HttpRequesterInterface
6 {
7 /**
8 * Make a HTTP request to a URL.
9 *
10 * @param string $url The URL to make the HTTP request to
11 *
12 * @return HttpResponse A HttpResponse object, which simply contains body, status code and response headers.
13 * In case the request itself fails, the status code is "0" and the body should contain
14 * error description (if available)
15 */
16 public function makeHttpRequest($url)
17 {
18 // PS: We suppress the E_WARNING level error generated on failure
19 $body = @file_get_contents($url);
20 if ($body === false) {
21 //$body = '';
22 return new HttpResponse('The following request failed: file_get_contents(' . $url . ')', '0', []);
23 }
24
25 // $http_response_header materializes out of thin air when file_get_contents() is called
26
27 // Get status code
28 $statusLine = $http_response_header[0];
29 preg_match('{HTTP\/\S*\s(\d{3})}', $statusLine, $match);
30 $statusCode = $match[1];
31
32 // Create headers map
33 $headersMap = [];
34 foreach ($http_response_header as $header) {
35 $pos = strpos($header, ':');
36 if ($pos > 0) {
37 $fieldName = strtolower(trim(substr($header, 0, $pos)));
38 $value = trim(substr($header, $pos + 1));
39 if (!isset($headersMap[$fieldName])) {
40 $headersMap[$fieldName] = $value;
41 } else {
42 $headersMap[$fieldName] .= ', ' . $value;
43 }
44 }
45 }
46 return new HttpResponse($body, $statusCode, $headersMap);
47 }
48 }
49