Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*) Adding possibility to configure if the http proxy should send the X-forwarded-for header (requested by TeeSee) See: http://www.yacy-forum.de/viewtopic.php?t=2577

thelib594ee9a5a3e
diff --git a/htroot/SettingsAck_p.html b/htroot/SettingsAck_p.html
index 2cc9c0741..0ae5e1eff 100644
--- a/htroot/SettingsAck_p.html
+++ b/htroot/SettingsAck_p.html
@@ -118,6 +118,10 @@ Seed Upload method was changed successfully.
<td>Send via header is:</td>
<td class="settingsValue">#[proxy.sendViaHeader]#</td>
</tr>
+<tr>
+ <td>Send X-Forwarded-For header is:</td>
+ <td class="settingsValue">#[proxy.sendXForwardedForHeader]#</td>
+</tr>
</table>
::<!-- 21: message forwarding -->
<p><b>Your message forwarding settings have been changed.</b></p>
diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.java
index ecd03b97d..f6c085336 100644
--- a/htroot/SettingsAck_p.java
+++ b/htroot/SettingsAck_p.java
@@ -234,6 +234,10 @@ public class SettingsAck_p {
env.setConfig("proxy.sendViaHeader", post.containsKey("proxy.sendViaHeader")?"true":"false");
prop.put("info_proxy.sendViaHeader", post.containsKey("proxy.sendViaHeader")? "on" : "off");
+ // setting X-Forwarded-for header property
+ env.setConfig("proxy.sendXForwardedForHeader", post.containsKey("proxy.sendXForwardedForHeader")?"true":"false");
+ prop.put("info_proxy.sendXForwardedForHeader", post.containsKey("proxy.sendXForwardedForHeader")? "on" : "off");
+
prop.put("info", 20);
return prop;
}
diff --git a/htroot/Settings_Http.inc b/htroot/Settings_Http.inc
index c6b3144cc..52723dc11 100644
--- a/htroot/Settings_Http.inc
+++ b/htroot/Settings_Http.inc
@@ -18,7 +18,12 @@
<td>Send&nbsp;Via&nbsp;Header:</td>
<td><input type="checkbox" name="proxy.sendViaHeader" align="top" #(proxy.sendViaHeader)#::checked#(/proxy.sendViaHeader)#></td>
<td>Specifies if the proxy should send the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.45">Via</a> http header according to RFC 2616 Sect 14.45.</td>
- </tr>
+ </tr>
+ <tr valign="top">
+ <td>Send&nbsp;X-Forwarded-For&nbsp;Header:</td>
+ <td><input type="checkbox" name="proxy.sendXForwardedForHeader" align="top" #(proxy.sendXForwardedForHeader)#::checked#(/proxy.sendXForwardedForHeader)#></td>
+ <td>Specifies if the proxy should send the X-Forwarded-For http header.</td>
+ </tr>
<tr valign="top">
<td colspan="3"><input type="submit" name="httpNetworking" value="submit">&nbsp;<i>Changes will take effect immediately.</i></td>
</tr>
diff --git a/htroot/Settings_p.java b/htroot/Settings_p.java
index fd93b6a2f..3be190403 100644
--- a/htroot/Settings_p.java
+++ b/htroot/Settings_p.java
@@ -117,6 +117,7 @@ public final class Settings_p {
prop.put("isTransparentProxy", env.getConfig("isTransparentProxy", "false").equals("true") ? 1 : 0);
prop.put("connectionKeepAliveSupport", env.getConfig("connectionKeepAliveSupport", "false").equals("true") ? 1 : 0);
prop.put("proxy.sendViaHeader", env.getConfig("proxy.sendViaHeader", "false").equals("true") ? 1 : 0);
+ prop.put("proxy.sendXForwardedForHeader", env.getConfig("proxy.sendXForwardedForHeader", "true").equals("true") ? 1 : 0);
// remote port forwarding settings
boolean portForwardingAvailable = false;
diff --git a/source/de/anomic/http/httpdProxyHandler.java b/source/de/anomic/http/httpdProxyHandler.java
index a86119e5b..40a1f7eac 100644
--- a/source/de/anomic/http/httpdProxyHandler.java
+++ b/source/de/anomic/http/httpdProxyHandler.java
@@ -406,7 +406,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
}
// setting the X-Forwarded-For Header
- requestHeader.put(httpHeader.X_FORWARDED_FOR,conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP));
+ if (switchboard.getConfigBool("proxy.sendXForwardedForHeader", true)) {
+ requestHeader.put(httpHeader.X_FORWARDED_FOR,conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP));
+ }
// decide wether to use a cache entry or connect to the network
File cacheFile = cacheManager.getCachePath(url);
@@ -927,7 +929,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
}
// setting the X-Forwarded-For Header
- requestHeader.put(httpHeader.X_FORWARDED_FOR,conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP));
+ if (switchboard.getConfigBool("proxy.sendXForwardedForHeader", true)) {
+ requestHeader.put(httpHeader.X_FORWARDED_FOR,conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP));
+ }
// resolve yacy and yacyh domains
String yAddress = yacyCore.seedDB.resolveYacyAddress(host);
@@ -1015,7 +1019,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
}
// setting the X-Forwarded-For Header
- requestHeader.put(httpHeader.X_FORWARDED_FOR,conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP));
+ if (switchboard.getConfigBool("proxy.sendXForwardedForHeader", true)) {
+ requestHeader.put(httpHeader.X_FORWARDED_FOR,conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP));
+ }
// resolve yacy and yacyh domains
String yAddress = yacyCore.seedDB.resolveYacyAddress(host);
diff --git a/yacy.init b/yacy.init
index b856bac5f..e02c76059 100644
--- a/yacy.init
+++ b/yacy.init
@@ -574,6 +574,9 @@ connectionKeepAliveSupport=true
# Specifies if the proxy should send the via header according to RFC
proxy.sendViaHeader=true
+# Specifies if the proxy should send the X-Forwarded-For header
+proxy.sendXForwardedForHeader=true
+
# Configuration options needed to configure server port forwarding
portForwardingEnabled=false
portForwardingUseProxy=false