Add WebResponse::getHeader()
authorOri Livneh <ori@wikimedia.org>
Fri, 7 Nov 2014 18:52:23 +0000 (10:52 -0800)
committerOri Livneh <ori@wikimedia.org>
Fri, 7 Nov 2014 19:19:12 +0000 (11:19 -0800)
Equivalent to FauxResponse::getHeader()
Also change case of FauxResponse::getHeader.

Change-Id: I569b2ebbcd166f5d0a5a5f2dfa913a6aa49e13f4

includes/WebResponse.php

index ad9f4e6..d39f884 100644 (file)
@@ -37,6 +37,22 @@ class WebResponse {
                header( $string, $replace, $http_response_code );
        }
 
+       /**
+        * Get a response header
+        * @param string $key The name of the header to get (case insensitive).
+        * @return string|null The header value (if set); null otherwise.
+        * @since 1.25
+        */
+       public function getHeader( $key ) {
+               foreach ( headers_list() as $header ) {
+                       list( $name, $val ) = explode( ':', $header, 2 );
+                       if ( !strcasecmp( $name, $key ) ) {
+                               return trim( $val );
+                       }
+               }
+               return null;
+       }
+
        /**
         * Set the browser cookie
         * @param string $name Name of cookie
@@ -150,7 +166,7 @@ class FauxResponse extends WebResponse {
         * @param string $key The name of the header to get (case insensitive).
         * @return string
         */
-       public function getheader( $key ) {
+       public function getHeader( $key ) {
                $key = strtoupper( $key );
 
                if ( isset( $this->headers[$key] ) ) {