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
pull/1/head
orbiter 15 years ago
parent 917d715374
commit 70c95608d4

@ -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");
}

@ -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

@ -35,7 +35,7 @@ public class YMarksHTMLImporter extends HTMLEditorKit.ParserCallback implements
private 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>();

@ -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;

@ -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?

@ -113,6 +113,8 @@ public class HeaderFramework extends TreeMap<String, String> implements Map<Stri
public 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<Stri
if (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

Loading…
Cancel
Save