]> _ Git - cubist_net.git/commitdiff
#7825
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 Nov 2025 14:59:01 +0000 (15:59 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 Nov 2025 14:59:01 +0000 (15:59 +0100)
src/HTTP.php

index 4f31e1572c1838f2b270d643fa847230626f09e1..4646c6d3180fb24988593847a3c24eee455c5136 100644 (file)
@@ -7,14 +7,21 @@ class HTTP
     /**
      * @param string $url
      * @param string|null $flaresolverr
-     * @return void
+     * @return int
      */
-    public static function getResponseCode(string $url, string $flaresolverr = null)
+    public static function getResponseCode(string $url, string $flaresolverr = null): int
     {
-
+        $headers = get_headers($url, 1);
+        if ($headers['Server'] === "cloudflare") {
+            $response = self::getHttpCodeCloudflare($url);
+        } else {
+            $response = self::getHttpCode($url);
+        }
+        return (int)$response;
     }
 
-    public static function getHttpCodeCloudflare($url) {
+    public static function getHttpCodeCloudflare($url)
+    {
         $apiUrl = 'http://flaresolverr:8191/v1';
 
         $payload = json_encode([
@@ -32,9 +39,9 @@ class HTTP
         $ch = curl_init($apiUrl);
         self::$curlOpt = [
             CURLOPT_RETURNTRANSFER => true,
-            CURLOPT_HEADER         => true,
-            CURLOPT_NOBODY         => true,
-            CURLOPT_TIMEOUT        => self::$timeout,
+            CURLOPT_HEADER => true,
+            CURLOPT_NOBODY => true,
+            CURLOPT_TIMEOUT => self::$timeout,
             CURLOPT_POST => true,
             CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
             CURLOPT_POSTFIELDS => $payload,
@@ -42,7 +49,7 @@ class HTTP
         curl_setopt_array($ch, self::$curlOpt);
         $response = curl_exec($ch);
 
-        if(preg_match('/(error|code) \b(301|302|308|404|401|403|405|500|502|503)\b/', $response, $matches)) {
+        if (preg_match('/(error|code) \b(301|302|308|404|401|403|405|500|502|503)\b/', $response, $matches)) {
             $httpcode = $matches[2] ?? '';
             $finalUrl = '';
             $finalHttpCode = '';
@@ -53,25 +60,17 @@ class HTTP
         return ['httpcode' => $httpcode, 'finalurl' => $finalUrl, 'finalHttpCode' => $finalHttpCode];
     }
 
-    protected static function setCurlOpt($moreOptions = []) {
+    protected static function setCurlOpt($moreOptions = [])
+    {
         self::$curlOpt = [
             CURLOPT_RETURNTRANSFER => true,
-            CURLOPT_HEADER         => true,
-            CURLOPT_NOBODY         => true,
-            CURLOPT_TIMEOUT        => self::$timeout,
+            CURLOPT_HEADER => true,
+            CURLOPT_NOBODY => true,
+            CURLOPT_TIMEOUT => self::$timeout,
             ...$moreOptions
         ];
     }
 
-    public static function getUrlInfo($url) {
-        $headers = get_headers($url, 1);
-        if($headers['Server'] === "cloudflare") {
-            $response = self::getHttpCodeCloudflare($url);
-        }else {
-            $response = self::getHttpCode($url);
-        }
-        return $response;
-    }
 
     public static function getHttpCodeComment($httpcode)
     {