add exit proxy link to UrlProxy

on proxied pages a link to exit proxy is added to top of page.
Link text can be configured in web.xml init-parameter (see default/web.xml). If missing no link is displayed.
pull/1/head
reger 11 years ago
parent 78d08998db
commit d812f80784

@ -47,6 +47,11 @@
<servlet-class>net.yacy.http.servlets.YaCyProxyServlet</servlet-class>
-->
<servlet-class>net.yacy.http.servlets.UrlProxyServlet</servlet-class>
<init-param>
<description>Link text on top of proxied page to stop use of proxy</description>
<param-name>stopProxyText</param-name>
<param-value>YaCy stop proxy</param-value>
</init-param>
</servlet>
<!-- mappings activated by the application - hardcoded (added here for completness) -->

@ -75,12 +75,18 @@ import org.jsoup.select.Elements;
*/
public class UrlProxyServlet extends ProxyServlet implements Servlet {
private String _stopProxyText = null;
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
// must be lower case (header names are internally converted to lower)
_DontProxyHeaders.add("host"); // to prevent Host header setting from original servletrequest (which is localhost)
String tmps = config.getInitParameter("stopProxyText");
if (tmps != null) {
_stopProxyText = tmps;
}
}
/* ------------------------------------------------------------ */
@ -248,8 +254,11 @@ public class UrlProxyServlet extends ProxyServlet implements Servlet {
// 8 - add interaction elements (e.g. proxy exit button to switch back to original url)
// TODO: use a template file for
//de.prepend("<div><form action='" + proxyurl + "'><input type='submit' value='YaCy stop proxy' /></form></div>");
if (_stopProxyText != null) {
bde.prepend("<div width='100%' style='padding:5px; background:white; border-bottom: medium solid lightgrey;'>"
+ "<div align='center' style='font-size:11px; color:darkgrey;'><a href='" + proxyurl + "'>" + _stopProxyText + "</a></div></div>");
}
// 9 - deliver to client
byte[] sbb = UTF8.getBytes(doc.toString());

Loading…
Cancel
Save