From 9d9ed2d1fcf1331b4e1709228ec56efd378efea8 Mon Sep 17 00:00:00 2001
From: Brett Bieber <brett.bieber@gmail.com>
Date: Tue, 1 Apr 2014 17:00:14 -0500
Subject: [PATCH] Send CORS headers so content can be included

---
 src/UNL/Catalog/OutputController.php | 28 ++++++++++++++++++++++++++++
 www/index.php                        |  2 +-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/UNL/Catalog/OutputController.php b/src/UNL/Catalog/OutputController.php
index fe18a6f..4bc5d24 100644
--- a/src/UNL/Catalog/OutputController.php
+++ b/src/UNL/Catalog/OutputController.php
@@ -92,4 +92,32 @@ class OutputController extends \Savvy
         }
     }
 
+    /**
+     * 
+     * @param timestamp $expires timestamp
+     * 
+     * @return void
+     */
+    function sendCORSHeaders($expires = null)
+    {
+        // Specify domains from which requests are allowed
+        header('Access-Control-Allow-Origin: *');
+
+        // Specify which request methods are allowed
+        header('Access-Control-Allow-Methods: GET, OPTIONS');
+
+        // Additional headers which may be sent along with the CORS request
+        // The X-Requested-With header allows jQuery requests to go through
+
+        header('Access-Control-Allow-Headers: X-Requested-With');
+
+        // Set the ages for the access-control header to 20 days to improve speed/caching.
+        header('Access-Control-Max-Age: 1728000');
+
+        if (isset($expires)) {
+            // Set expires header for 24 hours to improve speed caching.
+            header('Expires: '.date('r', $expires));
+        }
+    }
+
 }
diff --git a/www/index.php b/www/index.php
index bb71d84..976a856 100644
--- a/www/index.php
+++ b/www/index.php
@@ -30,5 +30,5 @@ $catalog = new Controller($router->route($_SERVER['REQUEST_URI'], $_GET));
 $savvy = new OutputController($catalog->options);
 $savvy->addGlobal('controller', $catalog);
 $savvy->addGlobal('course_search_driver', new CourseSearch\DBSearcher());
-
+$savvy->sendCORSHeaders(strtotime('tomorrow'));
 echo $savvy->render($catalog);
\ No newline at end of file
-- 
GitLab