]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12886 improved response headers in Zend servers
authorskodak <skodak>
Tue, 20 Oct 2009 22:59:10 +0000 (22:59 +0000)
committerskodak <skodak>
Tue, 20 Oct 2009 22:59:10 +0000 (22:59 +0000)
webservice/lib.php

index 2a05351ae15b11daf891b849039908d4ce9a9660..deb06577b2f48e909b367c820f24f728992ad96c 100644 (file)
@@ -135,7 +135,8 @@ abstract class webservice_zend_server implements webservice_server {
         // session cleanup
         $this->session_cleanup();
 
-        //TODO: we need to send some headers too I guess
+        //finally send the result
+        $this->send_headers();
         echo $response;
         die;
     }
@@ -381,6 +382,17 @@ class '.$classname.' {
         external_api::set_context_restriction($this->restricted_context);
     }
 
+    /**
+     * Internal implementation - sending of page headers.
+     * @return void
+     */
+    protected function send_headers() {
+        header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
+        header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
+        header('Pragma: no-cache');
+        header('Accept-Ranges: none');
+    }
+
     /**
      * Specialised exception handler, we can not use the standard one because
      * it can not just print html to output.
@@ -401,12 +413,13 @@ class '.$classname.' {
             }
         }
 
-        // now let the plugin send the exception to client
-        echo $this->zend_server->fault($ex);
-
         // some hacks might need a cleanup hook
         $this->session_cleanup($ex);
 
+        // now let the plugin send the exception to client
+        $this->send_headers();
+        echo $this->zend_server->fault($ex);
+
         // not much else we can do now, add some logging later
         exit(1);
     }
@@ -557,12 +570,12 @@ abstract class webservice_base_server implements webservice_server {
             }
         }
 
-        // now let the plugin send the exception to client
-        $this->send_error($ex);
-
         // some hacks might need a cleanup hook
         $this->session_cleanup($ex);
 
+        // now let the plugin send the exception to client
+        $this->send_error($ex);
+
         // not much else we can do now, add some logging later
         exit(1);
     }