[icinga-checkins] icinga.org: icingaweb2/master: Response: Add method getHeader

git at icinga.org git at icinga.org
Tue Oct 18 11:10:45 CEST 2016


Module: icingaweb2
Branch: master
Commit: f95c7893530418dc4fce9b18d257308a9dba9750
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=f95c7893530418dc4fce9b18d257308a9dba9750

Author: Noah Hilverling <noah.hilverling at netways.de>
Date:   Tue Oct 18 09:58:33 2016 +0200

Response: Add method getHeader

refs #12161

---

 library/Icinga/Web/Response.php |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/library/Icinga/Web/Response.php b/library/Icinga/Web/Response.php
index d96972d..2a90a97 100644
--- a/library/Icinga/Web/Response.php
+++ b/library/Icinga/Web/Response.php
@@ -154,6 +154,31 @@ class Response extends Zend_Controller_Response_Http
     }
 
     /**
+     * Get an array of every header value with a specified name
+     *
+     * @param  string $name
+     * @param  bool $lastOnly  If this is true, the last value will be returned as a string.
+     *
+     * @return null|array|string
+     */
+    public function getHeader($name, $lastOnly = false)
+    {
+        $result = ($lastOnly ? null : array());
+        $headers = $this->getHeaders();
+        foreach ($headers as $header) {
+            if ($header['name'] === $name) {
+                if ($lastOnly) {
+                    $result = $header['value'];
+                } else {
+                    $result[] = $header['value'];
+                }
+            }
+        }
+
+        return $result;
+    }
+
+    /**
      * Get the request
      *
      * @return Request



More information about the icinga-checkins mailing list