jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [3/4] git commit: JENA-652 : Set CORS headers
Date Thu, 23 Oct 2014 19:42:51 GMT
JENA-652 : Set CORS headers


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

Branch: refs/heads/master
Commit: 6be12e58327e15c0e4b48a7dd8df6c4699946352
Parents: cb7a6d1
Author: Andy Seaborne <andy@apache.org>
Authored: Thu Oct 23 18:36:14 2014 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Thu Oct 23 19:48:47 2014 +0100

----------------------------------------------------------------------
 jena-fuseki/src/main/java/org/apache/jena/fuseki/HttpNames.java | 3 ++-
 .../main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java | 3 +--
 .../java/org/apache/jena/fuseki/servlets/SPARQL_REST_R.java     | 5 ++++-
 .../java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java    | 1 +
 .../java/org/apache/jena/fuseki/servlets/SPARQL_Update.java     | 1 +
 .../java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java     | 1 +
 .../main/java/org/apache/jena/fuseki/servlets/ServletBase.java  | 5 +++++
 7 files changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/6be12e58/jena-fuseki/src/main/java/org/apache/jena/fuseki/HttpNames.java
----------------------------------------------------------------------
diff --git a/jena-fuseki/src/main/java/org/apache/jena/fuseki/HttpNames.java b/jena-fuseki/src/main/java/org/apache/jena/fuseki/HttpNames.java
index f6cee56..65d73c7 100644
--- a/jena-fuseki/src/main/java/org/apache/jena/fuseki/HttpNames.java
+++ b/jena-fuseki/src/main/java/org/apache/jena/fuseki/HttpNames.java
@@ -42,7 +42,8 @@ public class HttpNames
     
     // CORS: 
     //   http://www.w3.org/TR/cors/  http://esw.w3.org/CORS_Enabled
-    public static final String hAccessControlAllowOrigin = "Access-Control-Allow-Origin"
;
+    public static final String hAccessControlAllowOrigin  = "Access-Control-Allow-Origin"
;
+    public static final String hAccessControlAllowHeaders = "Access-Control-Allow-Headers"
;
     
     // Fuseki parameter names 
     public static final String paramGraph           = "graph" ;

http://git-wip-us.apache.org/repos/asf/jena/blob/6be12e58/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
----------------------------------------------------------------------
diff --git a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
index 27e76ac..9de80bc 100644
--- a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
+++ b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
@@ -69,8 +69,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/6be12e58/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_R.java
----------------------------------------------------------------------
diff --git a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_R.java
b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_R.java
index 3c5c926..0c02b51 100644
--- a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_R.java
+++ b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_R.java
@@ -47,7 +47,7 @@ public class SPARQL_REST_R extends SPARQL_REST
         // Assume success - do the set up before grabbing the lock.
         // Sets content type.
         MediaType mediaType = HttpAction.contentNegotationRDF(action) ;
-        
+       
         ServletOutputStream output ;
         try { output = action.response.getOutputStream() ; }
         catch (IOException ex) { errorOccurred(ex) ; output = null ; }
@@ -60,6 +60,7 @@ public class SPARQL_REST_R extends SPARQL_REST
                             action.id, mediaType.getContentType(), mediaType.getCharset(),
lang.getName())) ;
 
         action.beginRead() ;
+        setCommonHeaders(action.response) ;
 
         try {
             Target target = determineTarget(action) ;
@@ -84,6 +85,7 @@ public class SPARQL_REST_R extends SPARQL_REST
     @Override
     protected void doOptions(HttpAction action)
     {
+        setCommonHeadersForOptions(action.response) ;
         action.response.setHeader(HttpNames.hAllow, "GET,HEAD,OPTIONS") ;
         action.response.setHeader(HttpNames.hContentLengh, "0") ;
         success(action) ;
@@ -92,6 +94,7 @@ public class SPARQL_REST_R extends SPARQL_REST
     @Override
     protected void doHead(HttpAction action)
     {
+        setCommonHeaders(action.response) ;
         action.beginRead() ;
         try { 
             Target target = determineTarget(action) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/6be12e58/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java
----------------------------------------------------------------------
diff --git a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java
b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java
index 32a65e6..712d543 100644
--- a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java
+++ b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java
@@ -49,6 +49,7 @@ public class SPARQL_REST_RW extends SPARQL_REST_R
     @Override
     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") ;
         success(action) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/6be12e58/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
----------------------------------------------------------------------
diff --git a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
index a54715c..f16f634 100644
--- a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
+++ b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
@@ -84,6 +84,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/6be12e58/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
----------------------------------------------------------------------
diff --git a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
index d5956e5..d21855f 100644
--- a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
+++ b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
@@ -69,6 +69,7 @@ public class SPARQL_Upload extends SPARQL_ServletBase
     @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/6be12e58/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
----------------------------------------------------------------------
diff --git a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
index 473a7db..7a74fa9 100644
--- a/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
+++ b/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
@@ -228,6 +228,11 @@ public abstract class ServletBase extends HttpServlet
         httpResponse.setHeader(HttpNames.hVary, varyHeaderSetting) ;
     }
 
+    public static void setCommonHeadersForOptions(HttpServletResponse httpResponse)
+    {
+        httpResponse.setHeader(HttpNames.hAccessControlAllowHeaders, "X-Requested-With, Content-Type,
Authorization") ;
+        setCommonHeaders(httpResponse) ;
+    }
     
     public static void setCommonHeaders(HttpServletResponse httpResponse)
     {


Mime
View raw message