Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Added CORS Access header for yacysearch.rss output used some of the recommendations from Copro: http://forum.yacy-websuche.de/viewtopic.php?p=21015#p21015 Original Request: http://forum.yacy-websuche.de/viewtopic.php?p=20829#p20829
orbiter70c95608d468
diff --git a/htroot/api/ymarks/import_html.java b/htroot/api/ymarks/import_html.javaindex a080ac4ee..4a8197419 100644--- a/htroot/api/ymarks/import_html.java+++ b/htroot/api/ymarks/import_html.java@@ -41,8 +41,8 @@ public class import_html {}} catch (UnsupportedEncodingException e) {Log.logException(e);- } catch (IOException e) {- Log.logException(e);+ //} catch (IOException e) {+ // Log.logException(e);}prop.put("result", "1");}diff --git a/htroot/yacysearch.java b/htroot/yacysearch.javaindex 9b952bba4..ed2351122 100644--- a/htroot/yacysearch.java+++ b/htroot/yacysearch.java@@ -36,6 +36,7 @@ import net.yacy.cora.document.RSSMessage;import net.yacy.cora.protocol.Domains;import net.yacy.cora.protocol.HeaderFramework;import net.yacy.cora.protocol.RequestHeader;+import net.yacy.cora.protocol.ResponseHeader;import net.yacy.document.Condenser;import net.yacy.document.Document;import net.yacy.document.Parser;@@ -67,6 +68,7 @@ import de.anomic.search.SwitchboardConstants;import de.anomic.server.serverCore;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;+import de.anomic.server.servletProperties;import de.anomic.yacy.yacyNewsPool;import de.anomic.yacy.graphics.ProfilingGraph;import de.anomic.yacy.yacyChannel;@@ -100,7 +102,7 @@ public class yacysearch {String originalquerystring = (post == null) ? "" : post.get("query", post.get("search", "")).trim();String querystring = originalquerystring.replace('+', ' ');CrawlProfile.CacheStrategy snippetFetchStrategy = (post == null) ? null : CrawlProfile.CacheStrategy.parse(post.get("verify", "cacheonly"));- final serverObjects prop = new serverObjects();+ final servletProperties prop = new servletProperties();// get segmentSegment indexSegment = null;@@ -114,7 +116,7 @@ public class yacysearch {indexSegment = sb.indexSegments.segment(Segments.Process.PUBLIC);}- //final boolean rss = (post == null) ? false : post.get("rss", "false").equals("true");+ final boolean rss = header.get("EXT", "").equals("rss");prop.put("promoteSearchPageGreeting", promoteSearchPageGreeting);prop.put("promoteSearchPageGreeting.homepage", sb.getConfig(SwitchboardConstants.GREETING_HOMEPAGE, ""));prop.put("promoteSearchPageGreeting.smallImage", sb.getConfig(SwitchboardConstants.GREETING_SMALL_IMAGE, ""));@@ -163,6 +165,13 @@ public class yacysearch {prop.put("jsonp-end", "");}+ // Adding CORS Access header for yacysearch.rss output+ if (rss) {+ final ResponseHeader outgoingHeader = new ResponseHeader();+ outgoingHeader.addHeader(HeaderFramework.CORS_ALLOW_ORIGIN, "*");+ prop.setOutgoingHeader(outgoingHeader);+ }+// collect search attributesboolean newsearch = post.hasValue("query") && post.hasValue("former") && !post.get("query","").equalsIgnoreCase(post.get("former","")); //new search termdiff --git a/source/de/anomic/data/YMarksHTMLImporter.java b/source/de/anomic/data/YMarksHTMLImporter.javaindex dc899b79c..ee0fca29c 100644--- a/source/de/anomic/data/YMarksHTMLImporter.java+++ b/source/de/anomic/data/YMarksHTMLImporter.java@@ -35,7 +35,7 @@ public class YMarksHTMLImporter extends HTMLEditorKit.ParserCallback implementsprivate final BlockingQueue<HashMap<String,String>> bookmarks;private final ParserDelegator htmlParser;- public YMarksHTMLImporter(final InputStream input, int queueSize) throws IOException {+ public YMarksHTMLImporter(final InputStream input, int queueSize) {this.state = STATE.NOTHING;this.prevTag = null;this.bmk = new HashMap<String,String>();diff --git a/source/de/anomic/http/server/HTTPDFileHandler.java b/source/de/anomic/http/server/HTTPDFileHandler.javaindex dbd621532..dacbaa0ad 100644--- a/source/de/anomic/http/server/HTTPDFileHandler.java+++ b/source/de/anomic/http/server/HTTPDFileHandler.java@@ -802,7 +802,7 @@ public final class HTTPDFileHandler {if (location.length() == 0) location = path;final ResponseHeader headers = getDefaultHeaders(path);- headers.setCookieVector(templatePatterns.getOutgoingHeader().getCookieVector()); //put the cookies into the new header TODO: can we put all headerlines, without trouble?+ headers.setAdditionalHeaderProperties(templatePatterns.getOutgoingHeader().getAdditionalHeaderProperties()); //put the cookies into the new header TODO: can we put all headerlines, without trouble?headers.put(HeaderFramework.LOCATION,location);HTTPDemon.sendRespondHeader(conProp,out,httpVersion,302,headers);return;diff --git a/source/de/anomic/http/server/HTTPDemon.java b/source/de/anomic/http/server/HTTPDemon.javaindex 237004f13..8efc153e7 100644--- a/source/de/anomic/http/server/HTTPDemon.java+++ b/source/de/anomic/http/server/HTTPDemon.java@@ -1274,7 +1274,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {httpHeader outgoingHeader=requestProperties.getOutgoingHeader();if (outgoingHeader!=null){*/- final Iterator<ResponseHeader.Entry> it = responseHeader.getCookies();+ final Iterator<ResponseHeader.Entry> it = responseHeader.getAdditionalHeaderProperties().iterator();while(it.hasNext()) {//Append user properties to the main String//TODO: Should we check for user properites. What if they intersect properties that are already in header?diff --git a/source/net/yacy/cora/protocol/HeaderFramework.java b/source/net/yacy/cora/protocol/HeaderFramework.javaindex 89f06627f..4b21f7622 100644--- a/source/net/yacy/cora/protocol/HeaderFramework.java+++ b/source/net/yacy/cora/protocol/HeaderFramework.java@@ -113,6 +113,8 @@ public class HeaderFramework extends TreeMap<String, String> implements Map<Stripublic static final String SET_COOKIE2 = "Set-Cookie2";public static final String EXPIRES = "Expires";+ public static final String CORS_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; // Cross-Origin Resource Sharing properties (http://www.w3.org/TR/cors/)+/* =============================================================@@ -594,7 +596,7 @@ public class HeaderFramework extends TreeMap<String, String> implements Map<Stri* Holds header properties*///Since properties such as cookies can be multiple, we cannot use HashMap here. We have to use Vector.- private Vector<Entry> cookies = new Vector<Entry>();+ private Vector<Entry> headerProps = new Vector<Entry>();/*** Implementation of Map.Entry. Structure that hold two values - exactly what we need!@@ -642,7 +644,7 @@ public class HeaderFramework extends TreeMap<String, String> implements Map<Striif (path != null) cookieString += " path=" + path + ";";if (domain != null) cookieString += " domain=" + domain + ";";if (secure) cookieString += " secure;";- cookies.add(new Entry("Set-Cookie", cookieString));+ headerProps.add(new Entry("Set-Cookie", cookieString));}/*** Sets Cookie on the client machine.@@ -715,31 +717,19 @@ public class HeaderFramework extends TreeMap<String, String> implements Map<Stri}return "";}- public Vector<Entry> getCookieVector(){- return cookies;++ public void addHeader(final String key, final String value) {+ headerProps.add(new Entry(key, value));}- public void setCookieVector(final Vector<Entry> mycookies){- cookies=mycookies;++ public Vector<Entry> getAdditionalHeaderProperties() {+ return headerProps;}- /**- * Returns an iterator within all properties can be reached.- * Is used mainly by httpd.- *- * <p>Example:</p>- * <pre>- * Iterator it=serverObjects.getRequestProperties();- * while(it.hasNext())- * {- * java.util.Map.Entry e=(java.util.Map.Entry)it.next();- * String propertyName=e.getKey();- * String propertyValue=e.getValue();- * }</pre>- * @return iterator to read all request properties.- */- public Iterator<Entry> getCookies()- {- return cookies.iterator();++ public void setAdditionalHeaderProperties(final Vector<Entry> mycookies){+ headerProps=mycookies;}+/** Patch END:* Name: Header Property Patch