summaryrefslogtreecommitdiffstats
path: root/middleware
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-08-28 23:41:18 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-08-28 23:41:18 +0200
commit47436cd007694492ac0ab9530e33f890189d54b9 (patch)
tree2bc42317b96280467ed180d85aeccf9334ac46b1 /middleware
parent6191bf5339501b1e137769e42047d431b0214a23 (diff)
add middleware for cors requests
Diffstat (limited to 'middleware')
-rw-r--r--middleware/corsmiddleware.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/middleware/corsmiddleware.php b/middleware/corsmiddleware.php
new file mode 100644
index 000000000..a5d460280
--- /dev/null
+++ b/middleware/corsmiddleware.php
@@ -0,0 +1,53 @@
+<?php
+
+/**
+ * ownCloud - App Framework
+ *
+ * @author Bernhard Posselt
+ * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\News\Middleware;
+
+use OCA\AppFramework\Http\Response;
+use OCA\AppFramework\Middleware\Middleware;
+use OCA\AppFramework\Utility\MethodAnnotationReader;
+
+class CORSMiddleware extends Middleware {
+
+
+ /**
+ * This is being run after a successful controllermethod call and allows
+ * the manipulation of a Response object. The middleware is run in reverse order
+ *
+ * @param Controller $controller the controller that is being called
+ * @param string $methodName the name of the method that will be called on
+ * the controller
+ * @param Response $response the generated response from the controller
+ * @return Response a Response object
+ */
+ public function afterController($controller, $methodName, Response $response){
+ $annotationReader = new MethodAnnotationReader($controller, $methodName);
+ if($annotationReader->hasAnnotation('API')) {
+ $response->addHeader('Access-Control-Allow-Origin', '*');
+ }
+ return $response;
+ }
+
+
+}