Fixed /News.html and /Wiki.html pages in Search Portal mode (issue #87).

Also fixes theses pages rendering when the peer is not online.

Re-factored code in common with /opensearchdescription.xml and
ConfigPortal.html.
This commit is contained in:
luccioman 2016-11-03 02:33:36 +01:00
parent 8fe28a83f2
commit 2da5f339f8
8 changed files with 103 additions and 60 deletions

View File

@ -149,7 +149,7 @@
</pre></fieldset> </pre></fieldset>
This would look like: This would look like:
<iframe name="target" <iframe name="target"
src="#[myPreviewProtocol]#://#[myPreviewAddress]#/index.html?display=2&amp;resource=local&amp;focus=0" src="#[myPreviewContext]#/index.html?display=2&amp;resource=local&amp;focus=0"
width="100%" width="100%"
height="410" height="410"
frameborder="0" frameborder="0"
@ -172,7 +172,7 @@
</pre></fieldset> </pre></fieldset>
This would look like: This would look like:
<iframe name="target2" <iframe name="target2"
src="#[myPreviewProtocol]#://#[myPreviewAddress]#/yacysearch.html?display=2&amp;resource=local&amp;focus=0" src="#[myPreviewContext]#/yacysearch.html?display=2&amp;resource=local&amp;focus=0"
width="100%" width="100%"
height="180" height="180"
frameborder="0" frameborder="0"
@ -196,7 +196,7 @@
</pre></fieldset> </pre></fieldset>
This would look like: This would look like:
<iframe name="target3" <iframe name="target3"
src="#[myPreviewProtocol]#://#[myPreviewAddress]#/yacyinteractive.html?display=2&amp;focus=0" src="#[myPreviewContext]#/yacyinteractive.html?display=2&amp;focus=0"
width="100%" width="100%"
height="180" height="180"
frameborder="0" frameborder="0"

View File

@ -33,11 +33,10 @@ import java.net.MalformedURLException;
import java.util.Properties; import java.util.Properties;
import net.yacy.cora.document.id.DigestURL; import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader; import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ConcurrentLog; import net.yacy.cora.util.ConcurrentLog;
import net.yacy.data.WorkTables; import net.yacy.data.WorkTables;
import net.yacy.http.servlets.YaCyDefaultServlet;
import net.yacy.search.Switchboard; import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants; import net.yacy.search.SwitchboardConstants;
import net.yacy.server.serverObjects; import net.yacy.server.serverObjects;
@ -230,29 +229,13 @@ public class ConfigPortal {
prop.put("target_special_pattern", sb.getConfig(SwitchboardConstants.SEARCH_TARGET_SPECIAL_PATTERN, "")); prop.put("target_special_pattern", sb.getConfig(SwitchboardConstants.SEARCH_TARGET_SPECIAL_PATTERN, ""));
/* Address used in code template */ /* Address used in code template */
String myaddress = (sb.peers == null) || sb.peers.mySeed() == null || sb.peers.mySeed().getIP() == null ? null : sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP()); String myaddress = (sb.peers == null) || sb.peers.mySeed() == null || sb.peers.mySeed().getIPs().isEmpty() ? null : sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIPs().iterator().next());
if (myaddress == null) { if (myaddress == null) {
myaddress = "localhost:" + sb.getLocalPort(); myaddress = "localhost:" + sb.getLocalPort();
} }
prop.put("myaddress", myaddress); prop.put("myaddress", myaddress);
/* Address used to generate the preview frames : let's use the adress and port as requested. (Same behavior as opensearchdescription.java) */ prop.put("myPreviewContext", YaCyDefaultServlet.getContext(header, sb));
String myPreviewAddress = header.get(HeaderFramework.HOST); // returns host:port (if not default http/https ports)
String myPreviewProtocol = "http";
if (myPreviewAddress == null) {
myPreviewAddress = Domains.LOCALHOST + ":" + sb.getConfig("port", "8090");
} else {
final String sslport = ":" + sb.getConfig("port.ssl", "8443");
if (myPreviewAddress.endsWith(sslport)) { // connection on ssl port, use https protocol
myPreviewProtocol = "https";
}
}
/* YaCyDefaultServelt should have filled this custom header, making sure we know here wether original request is http or https
* (when default ports (80 and 443) are used, there is no way to distinguish the two schemes relying only on the Host header) */
myPreviewProtocol = header.get(HeaderFramework.X_YACY_REQUEST_SCHEME, myPreviewProtocol);
prop.put("myPreviewAddress", myPreviewAddress);
prop.put("myPreviewProtocol", myPreviewProtocol);
return prop; return prop;
} }

View File

@ -26,12 +26,14 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.yacy.cora.date.GenericFormatter; import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.HeaderFramework; import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader; import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ConcurrentLog; import net.yacy.cora.util.ConcurrentLog;
import net.yacy.http.servlets.YaCyDefaultServlet;
import net.yacy.peers.NewsDB; import net.yacy.peers.NewsDB;
import net.yacy.peers.NewsPool; import net.yacy.peers.NewsPool;
import net.yacy.peers.Seed; import net.yacy.peers.Seed;
@ -157,11 +159,29 @@ public class News {
title = record.attribute("title", ""); title = record.attribute("title", "");
description = record.attribute("url", ""); description = record.attribute("url", "");
} else if (category.equals(NewsPool.CATEGORY_WIKI_UPDATE)) { } else if (category.equals(NewsPool.CATEGORY_WIKI_UPDATE)) {
link = (seed == null)? "" : "http://" + seed.getPublicAddress(seed.getIP()) + "/Wiki.html?page=" + record.attribute("page", ""); if(seed == null) {
link = "";
} else {
Set<String> ips = seed.getIPs();
if(!ips.isEmpty()) {
link = "http://" + seed.getPublicAddress(ips.iterator().next()) + "/Wiki.html?page=" + record.attribute("page", "");
} else {
link = "";
}
}
title = record.attribute("author", "Anonymous") + ": " + record.attribute("page", ""); title = record.attribute("author", "Anonymous") + ": " + record.attribute("page", "");
description = "Wiki Update: " + record.attribute("description", ""); description = "Wiki Update: " + record.attribute("description", "");
} else if (category.equals(NewsPool.CATEGORY_BLOG_ADD)) { } else if (category.equals(NewsPool.CATEGORY_BLOG_ADD)) {
link = (seed == null)? "" : "http://" + seed.getPublicAddress(seed.getIP()) + "/Blog.html?page=" + record.attribute("page", ""); if(seed == null) {
link = "";
} else {
Set<String> ips = seed.getIPs();
if(!ips.isEmpty()) {
link = "http://" + seed.getPublicAddress(ips.iterator().next()) + "/Blog.html?page=" + record.attribute("page", "");
} else {
link = "";
}
}
title = record.attribute("author", "Anonymous") + ": " + record.attribute("page", ""); title = record.attribute("author", "Anonymous") + ": " + record.attribute("page", "");
description = "Blog Entry: " + record.attribute("subject", ""); description = "Blog Entry: " + record.attribute("subject", "");
} else { } else {
@ -179,8 +199,8 @@ public class News {
} }
} }
// adding the peer address // add the peer web context (used by News.rss)
prop.put("address", sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP())); prop.put("context", YaCyDefaultServlet.getContext(header, sb));
// return rewrite properties // return rewrite properties
return prop; return prop;

View File

@ -2,11 +2,11 @@
<rss version="2.0"> <rss version="2.0">
<channel> <channel>
<title><![CDATA[YaCy '#[clientname]#': #(page)#News Overview::Incoming News::Processed News::Outgoing News::Published News#(/page)#]]></title> <title><![CDATA[YaCy '#[clientname]#': #(page)#News Overview::Incoming News::Processed News::Outgoing News::Published News#(/page)#]]></title>
<link>http://#[address]#/News.html?page=#[page]#</link> <link>#[context]#/News.html?page=#[page]#</link>
<image> <image>
<url>http://#[address]#/env/grafics/YaCyLogo_60ppi.png</url> <url>#[context]#/env/grafics/YaCyLogo_60ppi.png</url>
<title>YaCy</title> <title>YaCy</title>
<link>http://#[address]#/</link> <link>#[context]#/</link>
</image> </image>
#(table)#<!-- News Overview --> #(table)#<!-- News Overview -->
::<!-- News Tables --> ::<!-- News Tables -->

View File

@ -37,6 +37,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set;
import net.yacy.cora.document.encoding.UTF8; import net.yacy.cora.document.encoding.UTF8;
import net.yacy.cora.protocol.Domains; import net.yacy.cora.protocol.Domains;
@ -127,6 +128,18 @@ public class Wiki {
prop.putHTML(serverObjects.ACTION_LOCATION, "/Wiki.html?page=" + pagename); prop.putHTML(serverObjects.ACTION_LOCATION, "/Wiki.html?page=" + pagename);
prop.put(serverObjects.ACTION_LOCATION, prop.get(serverObjects.ACTION_LOCATION)); prop.put(serverObjects.ACTION_LOCATION, prop.get(serverObjects.ACTION_LOCATION));
} }
String hostAndPort = null;
Set<String> ips = null;
if(sb.peers.mySeed() != null) {
ips = sb.peers.mySeed().getIPs();
}
if(ips != null && !ips.isEmpty()) {
hostAndPort = sb.peers.mySeed().getPublicAddress(ips.iterator().next());
}
if (hostAndPort == null) {
hostAndPort = Domains.LOCALHOST + ":" + sb.getLocalPort();
}
if (post != null && post.containsKey("edit")) { if (post != null && post.containsKey("edit")) {
if ((access.equals("admin") && (!sb.verifyAuthentication(header)))) { if ((access.equals("admin") && (!sb.verifyAuthentication(header)))) {
@ -147,7 +160,8 @@ public class Wiki {
prop.putHTML("mode_pagename", pagename); prop.putHTML("mode_pagename", pagename);
prop.putHTML("mode_author", author); prop.putHTML("mode_author", author);
prop.put("mode_date", dateString(new Date())); prop.put("mode_date", dateString(new Date()));
prop.putWiki(sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP()), "mode_page", post.get("content", "")); // Note : it would be better to not only pass the peer host and port but also the protocol (http or https)
prop.putWiki(hostAndPort, "mode_page", post.get("content", ""));
prop.putHTML("mode_page-code", post.get("content", "")); prop.putHTML("mode_page-code", post.get("content", ""));
} }
//end contrib of [MN] //end contrib of [MN]
@ -237,7 +251,7 @@ public class Wiki {
prop.putHTML("mode_versioning_pagename", pagename); prop.putHTML("mode_versioning_pagename", pagename);
prop.putHTML("mode_versioning_author", oentry.author()); prop.putHTML("mode_versioning_author", oentry.author());
prop.put("mode_versioning_date", dateString(oentry.date())); prop.put("mode_versioning_date", dateString(oentry.date()));
prop.putWiki(sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP()), "mode_versioning_page", oentry.page()); prop.putWiki(hostAndPort, "mode_versioning_page", oentry.page());
prop.putHTML("mode_versioning_page-code", UTF8.String(oentry.page())); prop.putHTML("mode_versioning_page-code", UTF8.String(oentry.page()));
} }
} catch (final IOException e) { } catch (final IOException e) {
@ -252,7 +266,7 @@ public class Wiki {
prop.putHTML("mode_pagename", pagename); prop.putHTML("mode_pagename", pagename);
prop.putHTML("mode_author", page.author()); prop.putHTML("mode_author", page.author());
prop.put("mode_date", dateString(page.date())); prop.put("mode_date", dateString(page.date()));
prop.putWiki(sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP()), "mode_page", page.page()); prop.putWiki(hostAndPort, "mode_page", page.page());
prop.put("controls", "0"); prop.put("controls", "0");
prop.putHTML("controls_pagename", pagename); prop.putHTML("controls_pagename", pagename);

View File

@ -24,9 +24,8 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader; import net.yacy.cora.protocol.RequestHeader;
import net.yacy.http.servlets.YaCyDefaultServlet;
import net.yacy.search.Switchboard; import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants; import net.yacy.search.SwitchboardConstants;
import net.yacy.server.serverObjects; import net.yacy.server.serverObjects;
@ -40,26 +39,12 @@ public class opensearchdescription {
String promoteSearchPageGreeting = env.getConfig(SwitchboardConstants.GREETING, ""); String promoteSearchPageGreeting = env.getConfig(SwitchboardConstants.GREETING, "");
if (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) promoteSearchPageGreeting = env.getConfig("network.unit.description", ""); if (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) promoteSearchPageGreeting = env.getConfig("network.unit.description", "");
String thisaddress = header.get(HeaderFramework.HOST); // returns host:port (if not default http/https ports) final String thisContext = YaCyDefaultServlet.getContext(header, sb);
String thisprotocol = "http";
if (thisaddress == null) {
thisaddress = Domains.LOCALHOST + ":" + sb.getConfig("port", "8090");
} else {
final String sslport = ":" + sb.getConfig("port.ssl", "8443");
if (thisaddress.endsWith(sslport)) { // connection on ssl port, use https protocol
thisprotocol = "https";
}
}
/* YaCyDefaultServelt should have filled this custom header, making sure we know here wether original request is http or https
* (when default ports (80 and 443) are used, there is no way to distinguish the two schemes relying only on the Host header) */
thisprotocol = header.get(HeaderFramework.X_YACY_REQUEST_SCHEME, thisprotocol);
final serverObjects prop = new serverObjects(); final serverObjects prop = new serverObjects();
prop.put("compareyacy", post != null && post.getBoolean("compare_yacy") ? 1 : 0); prop.put("compareyacy", post != null && post.getBoolean("compare_yacy") ? 1 : 0);
prop.putXML("thisaddress", thisaddress); prop.putXML("thisContext", thisContext);
prop.putXML("compareyacy_thisaddress", thisaddress); prop.putXML("compareyacy_thisContext", thisContext);
prop.putXML("thisprotocol", thisprotocol);
prop.putXML("compareyacy_thisprotocol", thisprotocol);
prop.putXML("SearchPageGreeting", promoteSearchPageGreeting); prop.putXML("SearchPageGreeting", promoteSearchPageGreeting);
prop.putXML("clientname", sb.peers.mySeed().getName()); prop.putXML("clientname", sb.peers.mySeed().getName());
prop.putXML("compareyacy_search_left", post == null ? compare_yacy.defaultsearchL : post.get("left", compare_yacy.defaultsearchL)); prop.putXML("compareyacy_search_left", post == null ? compare_yacy.defaultsearchL : post.get("left", compare_yacy.defaultsearchL));

View File

@ -4,7 +4,7 @@
xmlns:suggestions="http://www.opensearch.org/specifications/opensearch/extensions/suggestions/1.1"> xmlns:suggestions="http://www.opensearch.org/specifications/opensearch/extensions/suggestions/1.1">
<ShortName>#(compareyacy)#::Compare #(/compareyacy)#YaCy '#[clientname]#'</ShortName> <ShortName>#(compareyacy)#::Compare #(/compareyacy)#YaCy '#[clientname]#'</ShortName>
<LongName>YaCy.net - #[SearchPageGreeting]#</LongName> <LongName>YaCy.net - #[SearchPageGreeting]#</LongName>
<Image type="image/gif">#[thisprotocol]#://#[thisaddress]#/env/grafics/yacy.png</Image> <Image type="image/gif">#[thisContext]#/env/grafics/yacy.png</Image>
<Image width="16" height="16">data:image/x-icon;base64,AAABAAEAEBAAAAAAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD////////Chiu+fBm+fRq+fRq+fRq+fRq+fRq8ehXMmk////////////////////////////++exjUqGfZsnjYsXbYsXbYsXbZsnjTp2W+fBr///////////////////////////+9exfs2r/69/L58+z58+z58+z59e/z59bChSn///////////////////////////+9fBnnz638+fX69O369e748un38Ob59O3Ll0fVrGz////////////////////////Jk0HJlUjXuYrWt4jVtYPr28T58+r59OzPn1fPnlX////////////////////////Rolu8eRXCiTPEjTvCijbNnlj169359e7Zs3vLlkf////////////////////////UqmrAgSLt3MP27eH1693169327+T59Ozo0rG/gB////////////////////////////+/gCDv4Mn48+v38Of59Oz58+v48+vr2b2+fRv///////////////////////////+9ehXr17n58+z48ejo0bDp07T48+zx49DBhCj///////////////////////////+/fhzjyJ/59Oz59OzQoVvNmU759Oz58+vKlUbXrnH////////////////////////LlkfUqmn59Oz48+vZtHzNm1D48+v59OzPoFjOnlX////////////////////////OnVPOnFL59e348+vq1rnEiC7u38j69vDXsHTIkT3////////////////////////UqWjIkD327+T58+3s2bzAgSLp07T79/Pmzqq+fBn///////////////////////////+/fx7v4Mr7+PTx5NDHkD3kyqP8+vjs2r+9exf///////////////////////////++fBjQoFnVq2zTp2bGjTjJk0LWrW7SpWC+exf////////////////////////////Nm1C6dQy7eBG8eBK9exe8ehS7dxC6dQzLlkj////////////AH///wB8x+sAf///AD/+PwA///8AP///AD///4A9PU+APoz/gB///4AdxvOAHoz/gB3368AfjU/AHT1PwB/+P <Image width="16" height="16">data:image/x-icon;base64,AAABAAEAEBAAAAAAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD////////Chiu+fBm+fRq+fRq+fRq+fRq+fRq8ehXMmk////////////////////////////++exjUqGfZsnjYsXbYsXbYsXbZsnjTp2W+fBr///////////////////////////+9exfs2r/69/L58+z58+z58+z59e/z59bChSn///////////////////////////+9fBnnz638+fX69O369e748un38Ob59O3Ll0fVrGz////////////////////////Jk0HJlUjXuYrWt4jVtYPr28T58+r59OzPn1fPnlX////////////////////////Rolu8eRXCiTPEjTvCijbNnlj169359e7Zs3vLlkf////////////////////////UqmrAgSLt3MP27eH1693169327+T59Ozo0rG/gB////////////////////////////+/gCDv4Mn48+v38Of59Oz58+v48+vr2b2+fRv///////////////////////////+9ehXr17n58+z48ejo0bDp07T48+zx49DBhCj///////////////////////////+/fhzjyJ/59Oz59OzQoVvNmU759Oz58+vKlUbXrnH////////////////////////LlkfUqmn59Oz48+vZtHzNm1D48+v59OzPoFjOnlX////////////////////////OnVPOnFL59e348+vq1rnEiC7u38j69vDXsHTIkT3////////////////////////UqWjIkD327+T58+3s2bzAgSLp07T79/Pmzqq+fBn///////////////////////////+/fx7v4Mr7+PTx5NDHkD3kyqP8+vjs2r+9exf///////////////////////////++fBjQoFnVq2zTp2bGjTjJk0LWrW7SpWC+exf////////////////////////////Nm1C6dQy7eBG8eBK9exe8ehS7dxC6dQzLlkj////////////AH///wB8x+sAf///AD/+PwA///8AP///AD///4A9PU+APoz/gB///4AdxvOAHoz/gB3368AfjU/AHT1PwB/+P
</Image> </Image>
<Language>en-us</Language> <Language>en-us</Language>
@ -13,19 +13,19 @@
<AdultContent>true</AdultContent> <AdultContent>true</AdultContent>
<Description>YaCy is an open-source GPL-licensed software that can be used for stand-alone search engine installations or as a client for a multi-user P2P-based web indexing cluster. This is the access to peer '#[clientname]#'.</Description> <Description>YaCy is an open-source GPL-licensed software that can be used for stand-alone search engine installations or as a client for a multi-user P2P-based web indexing cluster. This is the access to peer '#[clientname]#'.</Description>
#(compareyacy)# #(compareyacy)#
<Url type="text/html" method="GET" template="#[thisprotocol]#://#[thisaddress]#/yacysearch.html?query={searchTerms}&amp;startRecord={startIndex?}&amp;maximumRecords={count?}&amp;nav=all&amp;resource=global" /> <Url type="text/html" method="GET" template="#[thisContext]#/yacysearch.html?query={searchTerms}&amp;startRecord={startIndex?}&amp;maximumRecords={count?}&amp;nav=all&amp;resource=global" />
<Url type="application/rss+xml" method="GET" template="#[thisprotocol]#://#[thisaddress]#/yacysearch.rss?nav=&amp;query={searchTerms}&amp;startRecord={startIndex?}&amp;maximumRecords={count?}&amp;nav=all&amp;resource=global" /> <Url type="application/rss+xml" method="GET" template="#[thisContext]#/yacysearch.rss?nav=&amp;query={searchTerms}&amp;startRecord={startIndex?}&amp;maximumRecords={count?}&amp;nav=all&amp;resource=global" />
<Url type="application/atom+xml" method="GET" template="#[thisprotocol]#://#[thisaddress]#/yacysearch.atom?query={searchTerms}&amp;startRecord={startIndex?}&amp;maximumRecords={count?}&amp;resource=global" /> <Url type="application/atom+xml" method="GET" template="#[thisContext]#/yacysearch.atom?query={searchTerms}&amp;startRecord={startIndex?}&amp;maximumRecords={count?}&amp;resource=global" />
:: ::
<Url type="text/html" method="GET" template="#[thisprotocol]#://#[thisaddress]#/compare_yacy.html?query={searchTerms}&amp;left=#[search_left]#&amp;right=#[search_right]#&amp;display=2" /> <Url type="text/html" method="GET" template="#[thisContext]#/compare_yacy.html?query={searchTerms}&amp;left=#[search_left]#&amp;right=#[search_right]#&amp;display=2" />
#(/compareyacy)# #(/compareyacy)#
<Url type="application/x-suggestions+json" template="#[thisprotocol]#://#[thisaddress]#/suggest.json?query={searchTerms}"/> <Url type="application/x-suggestions+json" template="#[thisContext]#/suggest.json?query={searchTerms}"/>
<Url type="application/x-suggestions+xml" template="#[thisprotocol]#://#[thisaddress]#/suggest.xml?query={searchTerms}"/> <Url type="application/x-suggestions+xml" template="#[thisContext]#/suggest.xml?query={searchTerms}"/>
<!-- syntax according to http://www.loc.gov/standards/sru/. Set verify=true to get snippets in the search results --> <!-- syntax according to http://www.loc.gov/standards/sru/. Set verify=true to get snippets in the search results -->
<Developer>See https://github.com/orgs/yacy/teams/yacy_developers</Developer> <Developer>See https://github.com/orgs/yacy/teams/yacy_developers</Developer>
<Query role="example" searchTerms="yacy+free+software" /> <Query role="example" searchTerms="yacy+free+software" />
<Tags>YaCy Free Software Open Source P2P Peer-to-Peer Uncensored Distributed Web Search Engine</Tags> <Tags>YaCy Free Software Open Source P2P Peer-to-Peer Uncensored Distributed Web Search Engine</Tags>
<Contact>See #[thisprotocol]#://#[thisaddress]#/ViewProfile.html?hash=localhash</Contact> <Contact>See #[thisContext]#/ViewProfile.html?hash=localhash</Contact>
<Attribution>http://yacy.net YaCy Software &amp;copy; 2004-2014 by Michael Christen et al., YaCy.net; Content: ask peer owner</Attribution> <Attribution>http://yacy.net YaCy Software &amp;copy; 2004-2014 by Michael Christen et al., YaCy.net; Content: ask peer owner</Attribution>
<SyndicationRight>open</SyndicationRight> <SyndicationRight>open</SyndicationRight>
</OpenSearchDescription> </OpenSearchDescription>

View File

@ -62,6 +62,7 @@ import javax.servlet.http.HttpServletResponse;
import net.yacy.cora.date.GenericFormatter; import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.analysis.Classification; import net.yacy.cora.document.analysis.Classification;
import net.yacy.cora.order.Base64Order; import net.yacy.cora.order.Base64Order;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.HeaderFramework; import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader; import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ByteBuffer; import net.yacy.cora.util.ByteBuffer;
@ -692,6 +693,46 @@ public class YaCyDefaultServlet extends HttpServlet {
} }
return result; return result;
} }
/**
* Returns the URL base for this peer, determined from request header when present. Use this when absolute URL rendering is required,
* otherwise relative URLs should be preferred.
* @param header request header.
* @param sb Switchboard instance.
* @return the application context (URL request base) from request header or default configuration. This is
* either http://hostname:port or https://hostname:sslport
*/
public static String getContext(final RequestHeader header, final Switchboard sb) {
String hostAndPort = null;
if(header != null) {
hostAndPort = header.get(HeaderFramework.HOST);
}
String protocol = "http";
if (hostAndPort == null) {
if(sb != null) {
hostAndPort = Domains.LOCALHOST + ":" + sb.getConfigInt("port", 8090);
} else {
hostAndPort = Domains.LOCALHOST + ":8090";
}
} else {
final String sslport;
if(sb != null) {
sslport = ":" + sb.getConfigInt("port.ssl", 8443);
} else {
sslport = ":8443";
}
if (hostAndPort.endsWith(sslport)) { // connection on ssl port, use https protocol
protocol = "https";
}
}
/* YaCyDefaultServelt should have filled this custom header, making sure we know here whether original request is http or https
* (when default ports (80 and 443) are used, there is no way to distinguish the two schemes relying only on the Host header) */
protocol = header.get(HeaderFramework.X_YACY_REQUEST_SCHEME, protocol);
/* Note : this implementation lets the responsibility to any eventual Reverse Proxy to eventually rewrite the rendered absolute URL */
return protocol + "://" + hostAndPort;
}
protected RequestHeader generateLegacyRequestHeader(HttpServletRequest request, String target, String targetExt) { protected RequestHeader generateLegacyRequestHeader(HttpServletRequest request, String target, String targetExt) {
RequestHeader legacyRequestHeader = convertHeaderFromJetty(request); RequestHeader legacyRequestHeader = convertHeaderFromJetty(request);