Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
- view image files from cache - fixed generic header settings; affects CORS functionality
orbiter7bb4b001edf1
diff --git a/htroot/CacheResource_p.java b/htroot/CacheResource_p.javaindex 65078bcce..3d29ab834 100644--- a/htroot/CacheResource_p.java+++ b/htroot/CacheResource_p.java@@ -24,18 +24,22 @@import java.net.MalformedURLException;+import net.yacy.cora.protocol.HeaderFramework;import net.yacy.cora.protocol.RequestHeader;+import net.yacy.cora.protocol.ResponseHeader;+import net.yacy.document.ImageParser;import net.yacy.kelondro.data.meta.DigestURI;import net.yacy.kelondro.logging.Log;import de.anomic.http.client.Cache;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;+import de.anomic.server.servletProperties;public class CacheResource_p {- public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {- final serverObjects prop = new serverObjects();+ public static Object respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {+ final servletProperties prop = new servletProperties();prop.put("resource", new byte[0]);if (post == null) return prop;@@ -52,10 +56,24 @@ public class CacheResource_p {byte[] resource = null;resource = Cache.getContent(url);if (resource == null) return prop;- //ResponseHeader responseHeader = Cache.getResponseHeader(url);- //String resMime = responseHeader.mime();- prop.put("resource", resource);- return prop;+ // check request type+ if (header.get("EXT", "html").equals("png")) {+ // a png was requested+ return ImageParser.parse(u, resource);+ } else {+ // get response header and set mime type+ ResponseHeader responseHeader = Cache.getResponseHeader(url);+ String resMime = responseHeader == null ? null : responseHeader.mime();+ if (resMime != null) {+ final ResponseHeader outgoingHeader = new ResponseHeader();+ outgoingHeader.put(HeaderFramework.CONTENT_TYPE, resMime);+ prop.setOutgoingHeader(outgoingHeader);+ }++ // add resource+ prop.put("resource", resource);+ return prop;+ }}}diff --git a/htroot/ViewFile.html b/htroot/ViewFile.htmlindex 13d45ffe8..7306bdb18 100644--- a/htroot/ViewFile.html+++ b/htroot/ViewFile.html@@ -107,7 +107,8 @@</fieldset>:: <!-- 5 --><fieldset><legend>Original from Cache</legend>- <iframe src="/CacheResource_p.html?url=#[url]#" width="800" height="400" />+ #(html)#::<iframe src="/CacheResource_p.html?url=#[url]#" width="800" height="400" />#(/html)#+ #(png)#::<iframe src="/CacheResource_p.png?url=#[url]#" width="800" height="400" />#(/png)#</fieldset>:: <!-- 6 --><fieldset><legend>Link List</legend>diff --git a/htroot/ViewFile.java b/htroot/ViewFile.javaindex 46ff114c1..089bc169d 100644--- a/htroot/ViewFile.java+++ b/htroot/ViewFile.java@@ -209,8 +209,14 @@ public class ViewFile {} else if (viewMode.equals("iframeCache")) {prop.put("viewMode", VIEW_MODE_AS_IFRAME_FROM_CACHE);- prop.put("viewMode_url", url.toNormalform(false, true));-+ String ext = url.getFileExtension();+ if ("jpg.jpeg.png.gif".indexOf(ext) >= 0) {+ prop.put("viewMode_png", 1);+ prop.put("viewMode_png_url", url.toNormalform(false, true));+ } else {+ prop.put("viewMode_html", 1);+ prop.put("viewMode_html_url", url.toNormalform(false, true));+ }} else if (viewMode.equals("parsed") || viewMode.equals("sentences") || viewMode.equals("words") || viewMode.equals("links")) {// parsing the resource contentDocument document = null;diff --git a/htroot/suggest.java b/htroot/suggest.javaindex 8e25d205e..36c494870 100644--- a/htroot/suggest.java+++ b/htroot/suggest.java@@ -97,7 +97,7 @@ public class suggest {// Adding CORS Access header for xml outputif (xml) {final ResponseHeader outgoingHeader = new ResponseHeader();- outgoingHeader.addHeader(HeaderFramework.CORS_ALLOW_ORIGIN, "*");+ outgoingHeader.put(HeaderFramework.CORS_ALLOW_ORIGIN, "*");prop.setOutgoingHeader(outgoingHeader);}diff --git a/htroot/yacysearch.java b/htroot/yacysearch.javaindex ed2351122..b9dd8f0c8 100644--- a/htroot/yacysearch.java+++ b/htroot/yacysearch.java@@ -168,7 +168,7 @@ public class yacysearch {// Adding CORS Access header for yacysearch.rss outputif (rss) {final ResponseHeader outgoingHeader = new ResponseHeader();- outgoingHeader.addHeader(HeaderFramework.CORS_ALLOW_ORIGIN, "*");+ outgoingHeader.put(HeaderFramework.CORS_ALLOW_ORIGIN, "*");prop.setOutgoingHeader(outgoingHeader);}diff --git a/source/de/anomic/http/server/HTTPDFileHandler.java b/source/de/anomic/http/server/HTTPDFileHandler.javaindex dacbaa0ad..cf4f4a154 100644--- a/source/de/anomic/http/server/HTTPDFileHandler.java+++ b/source/de/anomic/http/server/HTTPDFileHandler.java@@ -907,7 +907,10 @@ public final class HTTPDFileHandler {// apply templatesTemplateEngine.writeTemplate(fis, o, templatePatterns, "-UNRESOLVED_PATTERN-".getBytes("UTF-8"));fis.close();- HTTPDemon.sendRespondHeader(conProp, out, httpVersion, 200, null, mimeType, -1, targetDate, null, (templatePatterns == null) ? new ResponseHeader() : templatePatterns.getOutgoingHeader(), null, "chunked", nocache);+ HTTPDemon.sendRespondHeader(conProp, out,+ httpVersion, 200, null, mimeType, -1,+ targetDate, null, (templatePatterns == null) ? new ResponseHeader() : templatePatterns.getOutgoingHeader(),+ null, "chunked", nocache);// send the content in chunked parts, see RFC 2616 section 3.6.1final ChunkedOutputStream chos = new ChunkedOutputStream(out);ServerSideIncludes.writeSSI(o, chos, authorization, clientIP);diff --git a/source/de/anomic/http/server/HTTPDemon.java b/source/de/anomic/http/server/HTTPDemon.javaindex 79f8a3dfd..2ddebef17 100644--- a/source/de/anomic/http/server/HTTPDemon.java+++ b/source/de/anomic/http/server/HTTPDemon.java@@ -1194,7 +1194,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {}if (contentType == null) contentType = "text/html; charset=UTF-8";- headers.put(HeaderFramework.CONTENT_TYPE, contentType);+ if (headers.get(HeaderFramework.CONTENT_TYPE) == null) headers.put(HeaderFramework.CONTENT_TYPE, contentType);if (contentLength > 0) headers.put(HeaderFramework.CONTENT_LENGTH, Long.toString(contentLength));//if (cookie != null) headers.put(httpHeader.SET_COOKIE, cookie);if (expires != null) headers.put(HeaderFramework.EXPIRES, HeaderFramework.formatRFC1123(expires));