From 70c95608d4689f5d92dcf80ced2d5b6f119c9cef Mon Sep 17 00:00:00 2001 From: orbiter Date: Tue, 2 Nov 2010 16:28:40 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7288 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/api/ymarks/import_html.java | 4 +- htroot/yacysearch.java | 13 ++++++- source/de/anomic/data/YMarksHTMLImporter.java | 2 +- .../anomic/http/server/HTTPDFileHandler.java | 2 +- source/de/anomic/http/server/HTTPDemon.java | 2 +- .../yacy/cora/protocol/HeaderFramework.java | 38 +++++++------------ 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/htroot/api/ymarks/import_html.java b/htroot/api/ymarks/import_html.java index 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.java index 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 segment Segment 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 attributes boolean newsearch = post.hasValue("query") && post.hasValue("former") && !post.get("query","").equalsIgnoreCase(post.get("former","")); //new search term diff --git a/source/de/anomic/data/YMarksHTMLImporter.java b/source/de/anomic/data/YMarksHTMLImporter.java index 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 implements private final BlockingQueue> 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(); diff --git a/source/de/anomic/http/server/HTTPDFileHandler.java b/source/de/anomic/http/server/HTTPDFileHandler.java index 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.java index 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 it = responseHeader.getCookies(); + final Iterator 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.java index 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 implements Map implements Map cookies = new Vector(); + private Vector headerProps = new Vector(); /** * Implementation of Map.Entry. Structure that hold two values - exactly what we need! @@ -642,7 +644,7 @@ public class HeaderFramework extends TreeMap implements Map implements Map getCookieVector(){ - return cookies; + + public void addHeader(final String key, final String value) { + headerProps.add(new Entry(key, value)); } - public void setCookieVector(final Vector mycookies){ - cookies=mycookies; + + public Vector getAdditionalHeaderProperties() { + return headerProps; } - /** - * Returns an iterator within all properties can be reached. - * Is used mainly by httpd. - * - *

Example:

- *
-     * 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();
-     * }
- * @return iterator to read all request properties. - */ - public Iterator getCookies() - { - return cookies.iterator(); + + public void setAdditionalHeaderProperties(final Vector mycookies){ + headerProps=mycookies; } + /* * Patch END: * Name: Header Property Patch