Prechádzať zdrojové kódy

Merge pull request #472 from joanhey/response2

Add Http::responseCode()
walkor 6 rokov pred
rodič
commit
36f53c47e2
1 zmenil súbory, kde vykonal 15 pridanie a 5 odobranie
  1. 15 5
      Protocols/Http.php

+ 15 - 5
Protocols/Http.php

@@ -283,18 +283,16 @@ class Http
             return true;
         }
 
-            $key = \strstr($content, ":", true);
+        $key = \strstr($content, ":", true);
             if (empty($key)) {
                 return false;
-            }
+        }
 
         if ('location' === \strtolower($key)) {
             if (!$http_response_code) {
             $http_response_code = 302;
-        }
-            if (isset(HttpCache::$codes[$http_response_code])) {
-                HttpCache::$status = "HTTP/1.1 $http_response_code " . HttpCache::$codes[$http_response_code];
             }
+            self::responseCode($http_response_code);
         }
 
         if ($key === 'Set-Cookie') {
@@ -322,6 +320,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