From 0595c05200a97f70df572e14ed54289ca96621cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20M=C3=BCller?= <thomas.mueller@tmit.eu>
Date: Fri, 7 Aug 2015 13:12:43 +0200
Subject: [PATCH] Adding header support to class OC_OCS_Result

---
 lib/private/api.php        |  4 ++++
 lib/private/ocs/result.php | 45 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/lib/private/api.php b/lib/private/api.php
index 6823a19881..fb2110471b 100644
--- a/lib/private/api.php
+++ b/lib/private/api.php
@@ -350,6 +350,10 @@ class OC_API {
 			header('HTTP/1.0 401 Unauthorized');
 		}
 
+		foreach($result->getHeaders() as $name => $value) {
+			header($name . ': ' . $value);
+		}
+
 		if (self::isV2()) {
 			$statusCode = self::mapStatusCodes($result->getStatusCode());
 			if (!is_null($statusCode)) {
diff --git a/lib/private/ocs/result.php b/lib/private/ocs/result.php
index 1ee2982ac4..c4b0fbf33f 100644
--- a/lib/private/ocs/result.php
+++ b/lib/private/ocs/result.php
@@ -27,7 +27,23 @@
 
 class OC_OCS_Result{
 
-	protected $data, $message, $statusCode, $items, $perPage;
+	/** @var array  */
+	protected $data;
+
+	/** @var null|string */
+	protected $message;
+
+	/** @var int */
+	protected $statusCode;
+
+	/** @var integer */
+	protected $items;
+
+	/** @var integer */
+	protected $perPage;
+
+	/** @var array */
+	private $headers = [];
 
 	/**
 	 * create the OCS_Result object
@@ -106,5 +122,32 @@ class OC_OCS_Result{
 		return ($this->statusCode == 100);
 	}
 
+	/**
+	 * Adds a new header to the response
+	 * @param string $name The name of the HTTP header
+	 * @param string $value The value, null will delete it
+	 * @return $this
+	 */
+	public function addHeader($name, $value) {
+		$name = trim($name);  // always remove leading and trailing whitespace
+		// to be able to reliably check for security
+		// headers
+
+		if(is_null($value)) {
+			unset($this->headers[$name]);
+		} else {
+			$this->headers[$name] = $value;
+		}
+
+		return $this;
+	}
+
+	/**
+	 * Returns the set headers
+	 * @return array the headers
+	 */
+	public function getHeaders() {
+		return $this->headers;
+	}
 
 }
-- 
GitLab