]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/baculum/protected/API/Class/BaculumAPIServer.php
baculum: Use api client version and introduce api server version
[bacula/bacula] / gui / baculum / protected / API / Class / BaculumAPIServer.php
index feb15e11fcec24b0672485b5c52d21a84124e412..8216a564d96eb54c1062db8b0a8c4a9d36a5859c 100644 (file)
@@ -38,6 +38,11 @@ Prado::using('Application.API.Class.OAuth2.TokenRecord');
  */
 abstract class BaculumAPIServer extends TPage {
 
+       /**
+        * API server version (used in HTTP header)
+        */
+       const API_SERVER_VERSION = 0.1;
+
        /**
         * Storing output from API commands in numeric array.
         */
@@ -208,7 +213,9 @@ abstract class BaculumAPIServer extends TPage {
         * Set output headers to send in response.
         */
        private function setOutputHeaders() {
-               $this->getResponse()->setContentType('application/json');
+               $response = $this->getResponse();
+               $response->setContentType('application/json');
+               $response->appendHeader('Baculum-API-Version: ' . strval(self::API_SERVER_VERSION));
        }
 
        /**
@@ -345,5 +352,19 @@ abstract class BaculumAPIServer extends TPage {
        public function getModule($name) {
                return $this->Application->getModule($name);
        }
+
+       /**
+        * Get Baculum web client version.
+        *
+        * @return float client version
+        */
+       public function getClientVersion() {
+               $version = 0;
+               $headers = $this->getRequest()->getHeaders(CASE_LOWER);
+               if (array_key_exists('x-baculum-api', $headers)) {
+                       $version = floatval($headers['x-baculum-api']);
+               }
+               return $version;
+       }
 }
 ?>