jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/4] git commit: Code for setting CORS headers. This is controlled by the global flag, which defaults to "off".
Date Thu, 23 Oct 2014 19:42:50 GMT
Code for setting CORS headers.
This is controlled by the global flag, which defaults to "off".

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/38dd7822
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/38dd7822
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/38dd7822

Branch: refs/heads/master
Commit: 38dd7822de1cc4c8fcb7e3efee719a000a39c1db
Parents: c08530f
Author: Andy Seaborne <andy@apache.org>
Authored: Thu Oct 23 18:37:20 2014 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Thu Oct 23 18:37:20 2014 +0100

----------------------------------------------------------------------
 .../org/apache/jena/fuseki/servlets/SPARQL_GSP_R.java    |  4 +++-
 .../org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java   |  7 +++----
 .../org/apache/jena/fuseki/servlets/SPARQL_Query.java    |  3 +--
 .../org/apache/jena/fuseki/servlets/SPARQL_Update.java   |  1 +
 .../org/apache/jena/fuseki/servlets/SPARQL_Upload.java   |  2 ++
 .../org/apache/jena/fuseki/servlets/ServletBase.java     | 11 ++++++++++-
 6 files changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/38dd7822/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_R.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_R.java
b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_R.java
index be3ad4a..a706e57 100644
--- a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_R.java
+++ b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_R.java
@@ -58,7 +58,7 @@ public class SPARQL_GSP_R extends SPARQL_GSP
                             action.id, mediaType.getContentType(), mediaType.getCharset(),
lang.getName())) ;
 
         action.beginRead() ;
-
+        setCommonHeaders(action.response) ;
         try {
             Target target = determineTarget(action) ;
             if ( action.log.isDebugEnabled() )
@@ -81,6 +81,7 @@ public class SPARQL_GSP_R extends SPARQL_GSP
     
     @Override
     protected void doOptions(HttpAction action) {
+        setCommonHeadersForOptions(action.response) ;
         action.response.setHeader(HttpNames.hAllow, "GET,HEAD,OPTIONS") ;
         action.response.setHeader(HttpNames.hContentLengh, "0") ;
         ServletOps.success(action) ;
@@ -89,6 +90,7 @@ public class SPARQL_GSP_R extends SPARQL_GSP
     @Override
     protected void doHead(HttpAction action) {
         action.beginRead() ;
+        setCommonHeaders(action.response) ;
         try { 
             Target target = determineTarget(action) ;
             if ( action.log.isDebugEnabled() )

http://git-wip-us.apache.org/repos/asf/jena/blob/38dd7822/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java
b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java
index 538a8c1..d3c3179 100644
--- a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java
+++ b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java
@@ -46,16 +46,15 @@ public class SPARQL_GSP_RW extends SPARQL_GSP_R
     { super() ; }
 
     @Override
-    protected void doOptions(HttpAction action)
-    {
+    protected void doOptions(HttpAction action) {
+        setCommonHeadersForOptions(action.response) ;
         action.response.setHeader(HttpNames.hAllow, "GET,HEAD,OPTIONS,PUT,DELETE,POST");
         action.response.setHeader(HttpNames.hContentLengh, "0") ;
         ServletOps.success(action) ;
     }
     
     @Override
-    protected void doDelete(HttpAction action)
-    {
+    protected void doDelete(HttpAction action) {
         action.beginWrite() ;
         try {
             Target target = determineTarget(action) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/38dd7822/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
index 8e88901..6ab3f71 100644
--- a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
+++ b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
@@ -87,8 +87,7 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
 
     @Override
     protected void doOptions(HttpServletRequest request, HttpServletResponse response) {
-        // response.setHeader(HttpNames.hAllow, "GET,HEAD,OPTIONS,POST");
-        setCommonHeaders(response) ;
+        setCommonHeadersForOptions(response) ;
         response.setHeader(HttpNames.hAllow, "GET,OPTIONS,POST") ;
         response.setHeader(HttpNames.hContentLengh, "0") ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/38dd7822/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
index f2543e7..215c50e 100644
--- a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
+++ b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
@@ -89,6 +89,7 @@ public class SPARQL_Update extends SPARQL_Protocol
     @Override
     protected void doOptions(HttpServletRequest request, HttpServletResponse response)
     {
+        setCommonHeadersForOptions(response) ;
         response.setHeader(HttpNames.hAllow, "OPTIONS,POST");
         response.setHeader(HttpNames.hContentLengh, "0") ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/38dd7822/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
index 699d06a..458c924 100644
--- a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
+++ b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
@@ -69,6 +69,8 @@ public class SPARQL_Upload extends ActionSPARQL
     @Override
     protected void doOptions(HttpServletRequest request, HttpServletResponse response)
     {
+        setCommonHeaders(response);
+        setCommonHeadersForOptions(response) ;
         response.setHeader(HttpNames.hAllow, "OPTIONS,POST");
         response.setHeader(HttpNames.hContentLengh, "0") ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/38dd7822/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
index 4ac30be..a39cdd1 100644
--- a/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
+++ b/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
@@ -82,8 +82,17 @@ public abstract class ServletBase extends HttpServlet {
         httpResponse.setHeader(HttpNames.hVary, varyHeaderSetting) ;
     }
 
+    public static boolean CORS_ENABLED = false ;
+    
+    public static void setCommonHeadersForOptions(HttpServletResponse httpResponse) {
+        if ( CORS_ENABLED )
+            httpResponse.setHeader(HttpNames.hAccessControlAllowHeaders, "X-Requested-With,
Content-Type, Authorization") ;
+        setCommonHeaders(httpResponse) ;
+    }
+
     public static void setCommonHeaders(HttpServletResponse httpResponse) {
-        httpResponse.setHeader(HttpNames.hAccessControlAllowOrigin, "*") ;
+        if ( CORS_ENABLED )
+            httpResponse.setHeader(HttpNames.hAccessControlAllowOrigin, "*") ;
         httpResponse.setHeader(HttpNames.hServer, Fuseki.serverHttpName) ;
     }
 }


Mime
View raw message