From 053e54a2c734f1ac8f3f5a589f04b74b2b8f7dd2 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Tue, 5 Nov 2019 11:50:56 +0100 Subject: [PATCH] grand CORS for json files --- source/net/yacy/http/servlets/YaCyDefaultServlet.java | 6 +++++- source/net/yacy/server/http/HTTPDProxyHandler.java | 4 ++-- source/net/yacy/server/http/HTTPDemon.java | 10 ---------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/source/net/yacy/http/servlets/YaCyDefaultServlet.java b/source/net/yacy/http/servlets/YaCyDefaultServlet.java index f01dde542..6b3e39a10 100644 --- a/source/net/yacy/http/servlets/YaCyDefaultServlet.java +++ b/source/net/yacy/http/servlets/YaCyDefaultServlet.java @@ -841,7 +841,11 @@ public class YaCyDefaultServlet extends HttpServlet { response.setDateHeader(HeaderFramework.LAST_MODIFIED, now); response.setDateHeader(HeaderFramework.EXPIRES, now); // expires now } - + + if (target.endsWith(".json")) { + response.setHeader(HeaderFramework.CORS_ALLOW_ORIGIN, "*"); + } + if ((targetClass != null)) { serverObjects args = new serverObjects(); Enumeration argNames = request.getParameterNames(); // on ssi jetty dispatcher merged local ssi query parameters diff --git a/source/net/yacy/server/http/HTTPDProxyHandler.java b/source/net/yacy/server/http/HTTPDProxyHandler.java index 832b90122..b181d687b 100644 --- a/source/net/yacy/server/http/HTTPDProxyHandler.java +++ b/source/net/yacy/server/http/HTTPDProxyHandler.java @@ -668,7 +668,7 @@ public final class HTTPDProxyHandler { cachedResponseHeader.put(HeaderFramework.CONTENT_LENGTH, Integer.toString(0)); // send cached header with replaced date and added length - HTTPDemon.sendRespondHeader(conProp,respond,clienthttpVer,304,cachedResponseHeader); + HTTPDemon.sendRespondHeader(conProp,respond,clienthttpVer,304,null,cachedResponseHeader); //respondHeader(respond, "304 OK", cachedResponseHeader); // respond with 'not modified' } else { // unconditional request: send content of cache @@ -679,7 +679,7 @@ public final class HTTPDProxyHandler { cachedResponseHeader.put(HeaderFramework.CONTENT_LENGTH, Long.toString(cacheEntry.length)); // send cached header with replaced date and added length - HTTPDemon.sendRespondHeader(conProp,respond,clienthttpVer,203,cachedResponseHeader); + HTTPDemon.sendRespondHeader(conProp,respond,clienthttpVer,203,null,cachedResponseHeader); //respondHeader(respond, "203 OK", cachedResponseHeader); // respond with 'non-authoritative' // send also the complete body now from the cache diff --git a/source/net/yacy/server/http/HTTPDemon.java b/source/net/yacy/server/http/HTTPDemon.java index 2245964c4..72631100a 100644 --- a/source/net/yacy/server/http/HTTPDemon.java +++ b/source/net/yacy/server/http/HTTPDemon.java @@ -215,16 +215,6 @@ public final class HTTPDemon { } } - static final void sendRespondHeader( - final HashMap conProp, - final OutputStream respond, - final String httpVersion, - final int httpStatusCode, - final ResponseHeader header - ) throws IOException { - sendRespondHeader(conProp,respond,httpVersion,httpStatusCode,null,header); - } - static final void sendRespondHeader( final HashMap conProp, final OutputStream respond,