From 67e9b8e3946389c2797fa41eccbd439aab7e211d Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Fri, 7 Nov 2014 10:52:23 -0800 Subject: [PATCH] Add WebResponse::getHeader() Equivalent to FauxResponse::getHeader() Also change case of FauxResponse::getHeader. Change-Id: I569b2ebbcd166f5d0a5a5f2dfa913a6aa49e13f4 --- includes/WebResponse.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/WebResponse.php b/includes/WebResponse.php index ad9f4e664c..d39f884789 100644 --- a/includes/WebResponse.php +++ b/includes/WebResponse.php @@ -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] ) ) { -- 2.20.1