This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 4905fdf19cef55cfa5fa6d433310f4ce284a9764 Author: Benoit Tellier <[email protected]> AuthorDate: Mon Mar 23 14:04:19 2020 +0700 JAMES-3078 Add cors headers for all requests --- .../org/apache/james/jmap/http/AuthenticationRoutes.java | 6 +++--- .../main/java/org/apache/james/jmap/http/DownloadRoutes.java | 8 ++++---- .../main/java/org/apache/james/jmap/http/JMAPApiRoutes.java | 2 +- .../main/java/org/apache/james/jmap/http/UploadRoutes.java | 2 +- .../jmap/src/main/java/org/apache/james/jmap/JMAPRoutes.java | 12 ++++++++---- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/AuthenticationRoutes.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/AuthenticationRoutes.java index 586da3a..6f02ec8 100644 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/AuthenticationRoutes.java +++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/AuthenticationRoutes.java @@ -98,9 +98,9 @@ public class AuthenticationRoutes implements JMAPRoutes { @Override public HttpServerRoutes define(HttpServerRoutes builder) { return builder - .post(AUTHENTICATION, this::post) - .get(AUTHENTICATION, this::returnEndPointsResponse) - .delete(AUTHENTICATION, this::delete) + .post(AUTHENTICATION, JMAPRoutes.corsHeaders(this::post)) + .get(AUTHENTICATION, JMAPRoutes.corsHeaders(this::returnEndPointsResponse)) + .delete(AUTHENTICATION, JMAPRoutes.corsHeaders(this::delete)) .options(AUTHENTICATION, CORS_CONTROL); } diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/DownloadRoutes.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/DownloadRoutes.java index b9ff099..d307858 100644 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/DownloadRoutes.java +++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/DownloadRoutes.java @@ -92,10 +92,10 @@ public class DownloadRoutes implements JMAPRoutes { @Override public HttpServerRoutes define(HttpServerRoutes builder) { - return builder.post(DOWNLOAD_FROM_ID, this::postFromId) - .get(DOWNLOAD_FROM_ID, this::getFromId) - .post(DOWNLOAD_FROM_ID_AND_NAME, this::postFromIdAndName) - .get(DOWNLOAD_FROM_ID_AND_NAME, this::getFromIdAndName) + return builder.post(DOWNLOAD_FROM_ID, JMAPRoutes.corsHeaders(this::postFromId)) + .get(DOWNLOAD_FROM_ID, JMAPRoutes.corsHeaders(this::getFromId)) + .post(DOWNLOAD_FROM_ID_AND_NAME, JMAPRoutes.corsHeaders(this::postFromIdAndName)) + .get(DOWNLOAD_FROM_ID_AND_NAME, JMAPRoutes.corsHeaders(this::getFromIdAndName)) .options(DOWNLOAD_FROM_ID, CORS_CONTROL) .options(DOWNLOAD_FROM_ID_AND_NAME, CORS_CONTROL); } diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/JMAPApiRoutes.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/JMAPApiRoutes.java index 5451a8f..c37ac88 100644 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/JMAPApiRoutes.java +++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/JMAPApiRoutes.java @@ -80,7 +80,7 @@ public class JMAPApiRoutes implements JMAPRoutes { @Override public HttpServerRoutes define(HttpServerRoutes builder) { - return builder.post(JMAP, this::post) + return builder.post(JMAP, JMAPRoutes.corsHeaders(this::post)) .options(JMAP, CORS_CONTROL); } diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java index 7589cbb..921a5dc 100644 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java +++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/http/UploadRoutes.java @@ -81,7 +81,7 @@ public class UploadRoutes implements JMAPRoutes { @Override public HttpServerRoutes define(HttpServerRoutes builder) { - return builder.post(UPLOAD, this::post) + return builder.post(UPLOAD, JMAPRoutes.corsHeaders(this::post)) .options(UPLOAD, CORS_CONTROL); } diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutes.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutes.java index 4c76901..565c9c1 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutes.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutes.java @@ -36,10 +36,14 @@ import reactor.netty.http.server.HttpServerRoutes; public interface JMAPRoutes { HttpServerRoutes define(HttpServerRoutes builder); - BiFunction<HttpServerRequest, HttpServerResponse, Publisher<Void>> CORS_CONTROL = (req, res) -> res.header("Access-Control-Allow-Origin", "*") - .header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT") - .header("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept") - .send(); + BiFunction<HttpServerRequest, HttpServerResponse, Publisher<Void>> CORS_CONTROL = corsHeaders((req, res) -> res.send()); + + static BiFunction<HttpServerRequest, HttpServerResponse, Publisher<Void>> corsHeaders(BiFunction<HttpServerRequest, HttpServerResponse, Publisher<Void>> action) { + return (req, res) -> action.apply(req, res + .header("Access-Control-Allow-Origin", "*") + .header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT") + .header("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept")); + } Logger logger(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
