Prechádzať zdrojové kódy

Add Http::responseCode()
To add the code string for us. And used internally in Http::header()

Joanhey 6 rokov pred
rodič
commit
6268bc8d83
1 zmenil súbory, kde vykonal 19 pridanie a 10 odobranie
  1. 19 10
      Protocols/Http.php

+ 19 - 10
Protocols/Http.php

@@ -288,23 +288,20 @@ class Http
             return;
         }
         if (\strpos($content, 'HTTP') === 0) {
-            $key = 'Http-Code';
-        } else {
+            HttpCache::$status = $content;
+            return true;
+        }
+
             $key = \strstr($content, ":", true);
             if (empty($key)) {
                 return false;
             }
-        }
 
-        if ('location' === \strtolower($key) && !$http_response_code) {
+        if ('location' === \strtolower($key)) {
+            if (!$http_response_code) {
             $http_response_code = 302;
         }
-
-        if ($http_response_code && isset(HttpCache::$codes[$http_response_code])) {
-            HttpCache::$header['Http-Code'] = "HTTP/1.1 $http_response_code " . HttpCache::$codes[$http_response_code];
-            if ($key === 'Http-Code') {
-                return true;
-            }
+            self::responseCode($http_response_code);
         }
 
         if ($key === 'Set-Cookie') {
@@ -332,6 +329,18 @@ class Http
     }
 
     /**
+     * Add response header (http_response_code).
+     *
+     * @param int $code
+     * @return void
+     */
+    public static function responseCode($code) {
+        if (isset(HttpCache::$codes[$code])) {
+            HttpCache::$status = "HTTP/1.1 $code " . HttpCache::$codes[$code];
+        }
+    }
+
+    /**
      * Set cookie.
      *
      * @param string  $name