*) Setting via header according to rfc

- can be disabled via settings dialog

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1662 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
theli 2006-02-16 09:20:57 +00:00
parent 7a5af1e4df
commit 8fcb25f9f9
9 changed files with 179 additions and 56 deletions

View File

@ -30,8 +30,8 @@ Your new administration account name is #[user]#. The password has been accepted
::<!-- 6 -->
<b>Your proxy access setting has been changed.<br>
Your proxy account check has been disabled, since you did not supply a password.</b><p>
The new proxy IP filter is set to <font color="#556699">#[filter]#</font><br>
The proxy port is: <font color="#556699">#[port]#</font><p>
The new proxy IP filter is set to <div class="settingsValue">#[filter]#</div><br>
The proxy port is: <div class="settingsValue">#[port]#</div><p>
#(restart)#
::
Port rebinding will be done in a view seconds.<br>
@ -39,10 +39,10 @@ Your new administration account name is #[user]#. The password has been accepted
#(/restart)#
::<!-- 7 -->
<b>Your proxy access setting has been changed.</b><br>
Your new proxy account name is <font color="#556699">#[user]#</font>. The password has been accepted.<br>
Your new proxy account name is <div class="settingsValue">#[user]#</div>. The password has been accepted.<br>
If you open any public web page through the proxy, you must log-in then.<p>
The new proxy IP filter is set to <font color="#556699">#[filter]#</font>.<br>
The proxy port is: <font color="#556699">#[port]#</font><p>
The new proxy IP filter is set to <dif class="settingsValue">#[filter]#</div>.<br>
The proxy port is: <div class="settingsValue">#[port]#</div><p>
#(restart)#
::
Port rebinding will be done in a view seconds.<br>
@ -59,8 +59,8 @@ Auto pop-up of the Status page is now <b>enabled</b><br>
::<!-- 11 -->
You are now permanently <b>online</b>. After a short while you should see the effect on the <a href="Status.html">status</a> page.<br>
::<!-- 12 -->
<b>The Peer Name is: <font color="#556699">#[peerName]#</font><br>
<b>Your static Ip(or DynDns) is: <font color="#556699">#[staticIP]#</font><br>
<b>The Peer Name is: <div class="settingsValue">#[peerName]#</div><br>
<b>Your static Ip(or DynDns) is: <div class="settingsValue">#[staticIP]#</div><br>
::<!-- 13 -->
<b>Seed Settings changed.#(success)#::You are now a principal peer.#(/success)#<br>
::<!-- 14 -->
@ -73,11 +73,11 @@ Please return to the settings page and modify the data.<br>
The new setting is effective immediately, you don't need to re-start.
::<!-- 16 -->
<b>The submitted peer name is already used by another peer. Please choose a different name.</b> The Peer name has not been changed.<br>
Your Peer Language is: <font color="#556699">#[peerLang]#</font><br>
Your Peer Language is: <div class="settingsValue">#[peerLang]#</div><br>
::<!-- 17 -->
<b>The submitted peer name is not well-formed. Please choose a different name.</b> The Peer name has not been changed.<br>
Peer names must not contain characters other than (a-z, A-Z, 0-9, '-', '_') and must not be longer than 80 characters.
Your Peer Language is: <font color="#556699">#[peerLang]#</font><br>
Your Peer Language is: <div class="settingsValue">#[peerLang]#</div><br>
::<!-- 18 -->
<p>
The new parser settings where changed successfully.<br>
@ -85,7 +85,10 @@ Parsing of the following mime-types was enabled:
</p>
<table>
#{parser}#
<tr><td><font color="#556699">#[parserMode]#</font></td><td><font color="#556699">#[enabledMime]#</font></td></tr>
<tr>
<td class="settingsValue">#[parserMode]#</td>
<td class="settingsValue">#[enabledMime]#</td>
</tr>
#{/parser}#
</table>
::<!-- 19 -->
@ -93,19 +96,28 @@ Seed Upload method was changed successfully.
#(success)#::<br>You are now a principal peer.#(/success)#
<p>
<table>
<tr><td>Seed Upload Method:</td><td><font color="#556699">#[seedUploadMethod]#</font></td></tr>
<tr><td>Seed File URL:</td><td><a href="#[seedURL]#"><font color="#556699">#[seedURL]#</font></a></td></tr>
<tr>
<td>Seed Upload Method:</td>
<td class="settingsValue">#[seedUploadMethod]#</td>
</tr>
<tr>
<td>Seed File URL:</td>
<td class="settingsValue"><a href="#[seedURL]#">#[seedURL]#</a></td></tr>
</table>
::<!-- 20 -->
::<!-- 20: HTTP-Networking -->
<p><b>Your proxy networking settings have been changed.</b></p>
<table>
<tr>
<td>Transparent Proxy Support is:</td>
<td><font color="#556699"><b>#[isTransparentProxy]#</b></font></td>
<td class="settingsValue">#[isTransparentProxy]#</td>
</tr>
<tr>
<td>Connection Keep-Alive Support is:</td>
<td><font color="#556699"><b>#[connectionKeepAliveSupport]#</b></font></td>
<td class="settingsValue">#[connectionKeepAliveSupport]#</td>
</tr>
<tr>
<td>Send via header is:</td>
<td class="settingsValue">#[proxy.sendViaHeader]#</td>
</tr>
</table>
::<!-- 21: message forwarding -->
@ -113,15 +125,15 @@ Seed Upload method was changed successfully.
<table>
<tr>
<td>Message Forwarding Support is:</td>
<td><font color="#556699"><b>#[msgForwardingEnabled]#</b></font></td>
<td class="settingsValue">#[msgForwardingEnabled]#</td>
</tr>
<tr>
<td>Message Forwarding Command:</td>
<td><font color="#556699"><b>#[msgForwardingCmd]#</b></font></td>
<td class="settingsValue">#[msgForwardingCmd]#</td>
</tr>
<tr>
<td>Recipient Address:</td>
<td><font color="#556699"><b>#[msgForwardingTo]#</b></font></td>
<td class="settingsValue">#[msgForwardingTo]#</td>
</tr>
</table>
::<!-- 22 -->
@ -129,19 +141,19 @@ Seed Upload method was changed successfully.
<table>
<tr>
<td>Port Forwarding Support is:</td>
<td><font color="#556699"><b>#[portForwardingEnabled]#</b></font></td>
<td class="settingsValue">#[portForwardingEnabled]#</td>
</tr>
<tr>
<td>Port Forwarding Port:</td>
<td><font color="#556699"><b>#[portForwardingPort]#</b></font></td>
<td class="settingsValue">#[portForwardingPort]#</td>
</tr>
<tr>
<td>Port Forwarding Host:</td>
<td><font color="#556699"><b>#[portForwardingHostUser]#@#[portForwardingHost]#:#[portForwardingHostPort]#</b></font></td>
<td class="settingsValue">#[portForwardingHostUser]#@#[portForwardingHost]#:#[portForwardingHostPort]#</td>
</tr>
<tr>
<td>Port Forwarding uses proxy:</td>
<td><font color="#556699"><b>#[portForwardingUseProxy]#</b></font></td>
<td class="settingsValue">#[portForwardingUseProxy]#</td>
</tr>
</table>
::<!-- 23 : Port forwarding - error -->
@ -154,7 +166,7 @@ You are now <b>event-based online</b>. After a short while you should see the ef
::<!-- 25 -->
You are now in <b>Cache Mode</b>. Only Proxy-cache ist available in this mode. After a short while you should see the effect on the <a href="Status.html">status</a> page.<br>
::<!-- 26 -->
<p><font color="red">Unable to bild the server to the new Port: <font color="#556699">#[port]#</font></font><br>
<p><font color="red">Unable to bild the server to the new Port: <div class="settingsValue">#[port]#</div></font><br>
This values seems not to be a valid port configuration.
#(/info)#
</p>

View File

@ -205,6 +205,10 @@ public class SettingsAck_p {
env.setConfig("connectionKeepAliveSupport", httpd.keepAliveSupport ? "true" : "false");
prop.put("info_connectionKeepAliveSupport", httpd.keepAliveSupport ? "on" : "off");
// setting via header property
env.setConfig("proxy.sendViaHeader", post.containsKey("proxy.sendViaHeader")?"true":"false");
prop.put("info_proxy.sendViaHeader", post.containsKey("proxy.sendViaHeader")? "on" : "off");
prop.put("info", 20);
return prop;
}

View File

@ -14,6 +14,11 @@
<td><input type="checkbox" name="connectionKeepAliveSupport" align="top" #(connectionKeepAliveSupport)#::checked#(/connectionKeepAliveSupport)#></td>
<td>With this you can specify if YaCy should support the HTTP connection keep-alive feature.</td>
</tr>
<tr valign="top">
<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 valign="top">
<td colspan="3"><input type="submit" name="httpNetworking" value="submit">&nbsp;<i>Changes will take effect immediately.</i></td>
</tr>

View File

@ -116,6 +116,7 @@ public final class Settings_p {
// http networking settings
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);
// remote port forwarding settings
prop.put("portForwardingEnabled",env.getConfig("portForwardingEnabled","false").equals("true")? 1 : 0);

11
htroot/env/style.css vendored
View File

@ -199,7 +199,14 @@ width: 16px;
.ResultDescription {
color:#4070a0;
font-style:bold;}
font-weight:bold;
}
.ResultDateYBR {
color:#007050}
color:#007050
}
.settingsValue {
color:#556699;
font-weight:bold;
}

View File

@ -62,6 +62,7 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.Collator;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
@ -69,6 +70,7 @@ import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.Vector;
@ -94,35 +96,52 @@ public final class httpHeader extends TreeMap implements Map {
public static final String ACCEPT = "Accept";
public static final String ACCEPT_CHARSET = "Accept-Charset";
public static final String ACCEPT_LANGUAGE = "Accept-Language";
public static final String KEEP_ALIVE = "Keep-Alive";
public static final String USER_AGENT = "User-Agent";
public static final String HOST = "Host";
public static final String CONNECTION = "Connection";
public static final String PROXY_CONNECTION = "Proxy-Connection";
public static final String KEEP_ALIVE = "Keep-Alive";
public static final String REFERER = "Referer";
public static final String ACCEPT_ENCODING = "Accept-Encoding";
public static final String CONTENT_LENGTH = "Content-Length";
public static final String CONTENT_TYPE = "Content-Type";
public static final String USER_AGENT = "User-Agent";
public static final String AUTHORIZATION = "Authorization";
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
public static final String PROXY_AUTHORIZATION = "Proxy-Authorization";
public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate";
public static final String PROXY_CONNECTION = "Proxy-Connection";
public static final String DATE = "Date";
public static final String SERVER = "Server";
public static final String LAST_MODIFIED = "Last-modified";
public static final String PRAGMA = "Pragma";
public static final String CONTENT_LENGTH = "Content-Length";
public static final String CONTENT_TYPE = "Content-Type";
public static final String CONTENT_MD5 = "Content-MD5";
public static final String SET_COOKIE = "Set-Cookie";
public static final String SET_COOKIE2 = "Set-Cookie2";
public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
public static final String COOKIE = "Cookie";
public static final String EXPIRES = "Expires";
public static final String ACCEPT_ENCODING = "Accept-Encoding";
public static final String CONTENT_ENCODING = "Content-Encoding";
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
public static final String ACCEPT_RANGES = "Accept-Ranges";
public static final String CONTENT_RANGE = "Content-Range";
public static final String RANGE = "Range";
public static final String IF_RANGE = "If-Range";
public static final String PRAGMA = "Pragma";
public static final String CACHE_CONTROL = "Cache-Control";
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
public static final String LAST_MODIFIED = "Last-modified";
public static final String LOCATION = "Location";
public static final String ETAG = "ETag";
public static final String VIA = "Via";
public static final String X_CACHE = "X-Cache";
public static final String X_CACHE_LOOKUP = "X-Cache-Lookup";
@ -360,29 +379,47 @@ public final class httpHeader extends TreeMap implements Map {
private static SimpleDateFormat EMLFormatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss", Locale.US);
public static Date parseHTTPDate(String s) {
if ((s == null) || (s.length() < 9)) return new Date();
try {
return parseHTTPDate(s,true);
} catch (ParseException e) {
//System.out.println("ERROR long version parse: " + e.getMessage() + " at position " + e.getErrorOffset());
serverLog.logSevere("HTTPC-header", "DATE ERROR (Parse): " + s);
return null;
} catch (java.lang.NumberFormatException e) {
//System.out.println("ERROR long version parse: " + e.getMessage() + " at position " + e.getErrorOffset());
serverLog.logSevere("HTTPC-header", "DATE ERROR (NumberFormat): " + s);
return null;
}
}
public static Date parseHTTPDate(String s,boolean ignoreTimezone) throws ParseException, NumberFormatException {
SimpleDateFormat formatter = EMLFormatter;
if ((s == null) || (s.length() < 9)) return null;
s = s.trim();
if (s.charAt(3) == ',') s = s.substring(5).trim(); // we skip the name of the day
if (s.charAt(9) == ' ') s = s.substring(0, 7) + "20" + s.substring(7); // short year version
if (s.charAt(2) == ',') s = s.substring(0, 2) + s.substring(3); // ommit comma after day of week
if ((s.charAt(0) > '9') && (s.length() > 20) && (s.charAt(2) == ' ')) s = s.substring(3);
if (s.length() > 20) s = s.substring(0, 20).trim(); // truncate remaining, since that must be wrong
if (s.indexOf("Mrz") > 0) s = s.replaceAll("Mrz", "March");
try {
return EMLFormatter.parse(s);
} catch (java.text.ParseException e) {
//System.out.println("ERROR long version parse: " + e.getMessage() + " at position " + e.getErrorOffset());
serverLog.logSevere("HTTPC-header", "DATE ERROR (Parse): " + s);
return new Date();
} catch (java.lang.NumberFormatException e) {
//System.out.println("ERROR long version parse: " + e.getMessage() + " at position " + e.getErrorOffset());
serverLog.logSevere("HTTPC-header", "DATE ERROR (NumberFormat): " + s);
return new Date();
if (s.length() > 20) {
if (!ignoreTimezone) {
formatter = (SimpleDateFormat) formatter.clone();
formatter.setTimeZone(TimeZone.getTimeZone(s.substring(20)));
}
s = s.substring(0, 20).trim(); // truncate remaining, since that must be wrong
}
if (s.indexOf("Mrz") > 0) s = s.replaceAll("Mrz", "March");
// parsing the date string
return formatter.parse(s);
}
private Date headerDate(String kind) {
if (containsKey(kind)) return new Date(parseHTTPDate((String) get(kind)).getTime());
if (containsKey(kind)) {
Date parsedDate = parseHTTPDate((String) get(kind));
if (parsedDate == null) parsedDate = new Date();
return new Date(parsedDate.getTime());
}
return null;
}
@ -406,6 +443,17 @@ public final class httpHeader extends TreeMap implements Map {
return headerDate(httpHeader.IF_MODIFIED_SINCE);
}
public Object ifRange() {
if (containsKey(httpHeader.IF_RANGE)) {
try {
Date rangeDate = parseHTTPDate((String) get(httpHeader.IF_RANGE),false);
if (rangeDate != null) return new Date(rangeDate.getTime());
} catch (Exception e) {}
return get(httpHeader.IF_RANGE);
}
return null;
}
public long age() {
Date lm = lastModified();
Date sd = date();

View File

@ -529,6 +529,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
// removing hop by hop headers
this.removeHopByHopHeaders(requestHeader);
// adding additional headers
setViaHeader(requestHeader, httpVer);
// send request
res = remote.GET(remotePath, requestHeader);
conProp.put(httpHeader.CONNECTION_PROP_CLIENT_REQUEST_HEADER,requestHeader);
@ -606,6 +609,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
// remove hop by hop headers
this.removeHopByHopHeaders(res.responseHeader);
// adding additional headers
setViaHeader(res.responseHeader, res.httpVer);
// sending the respond header back to the client
if (chunkedOut != null) {
res.responseHeader.put(httpHeader.TRANSFER_ENCODING, "chunked");
@ -731,6 +737,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
// remove hop by hop headers
this.removeHopByHopHeaders(cachedResponseHeader);
// adding additional headers
setViaHeader(cachedResponseHeader, httpVer);
// replace date field in old header by actual date, this is according to RFC
cachedResponseHeader.put(httpHeader.DATE, httpc.dateString(httpc.nowDate()));
@ -910,6 +919,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
// removing hop by hop headers
this.removeHopByHopHeaders(requestHeader);
// adding outgoing headers
setViaHeader(requestHeader, httpVer);
// open the connection: second is needed for [AS] patch
remote = (yAddress == null) ? newhttpc(host, port, timeout): newhttpc(yAddress, timeout);
@ -924,6 +936,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
// removing hop by hop headers
this.removeHopByHopHeaders(res.responseHeader);
// adding outgoing headers
setViaHeader(res.responseHeader, res.httpVer);
// sending the server respond back to the client
httpd.sendRespondHeader(conProp,respond,httpVer,res.statusCode,res.statusText,res.responseHeader);
} catch (Exception e) {
@ -995,6 +1010,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
// removing hop by hop headers
this.removeHopByHopHeaders(requestHeader);
// adding additional headers
setViaHeader(requestHeader, httpVer);
// sending the request
remote = (yAddress == null) ? newhttpc(host, port, timeout) : newhttpc(yAddress, timeout);
httpc.response res = remote.POST(remotePath, requestHeader, body);
@ -1027,6 +1045,9 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
// remove hop by hop headers
this.removeHopByHopHeaders(res.responseHeader);
// adding additional headers
setViaHeader(res.responseHeader, res.httpVer);
// sending the respond header back to the client
if (chunked != null) {
res.responseHeader.put(httpHeader.TRANSFER_ENCODING, "chunked");
@ -1485,6 +1506,24 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
return this.userAgentStr.toString();
}
private void setViaHeader(httpHeader header, String httpVer) {
if (!switchboard.getConfigBool("proxy.sendViaHeader", true)) return;
// getting header set by other proxies in the chain
StringBuffer viaValue = new StringBuffer();
if (header.containsKey(httpHeader.VIA)) viaValue.append((String)header.get(httpHeader.VIA));
if (viaValue.length() > 0) viaValue.append(", ");
// appending info about this peer
viaValue
.append(httpVer).append(" ")
.append(yacyCore.seedDB.mySeed.getName()).append(".yacy ")
.append("(YaCy ").append(switchboard.getConfig("vString", "0.0")).append(")");
// storing header back
header.put(httpHeader.VIA, viaValue.toString());
}
/**
* This function is used to generate a logging message according to the
* <a href="http://www.squid-cache.org/Doc/FAQ/FAQ-6.html">squid logging format</a>.<p>

View File

@ -218,6 +218,10 @@ public abstract class serverAbstractSwitch implements serverSwitch {
}
}
public boolean getConfigBool(String key, boolean dflt) {
return Boolean.valueOf(getConfig(key, Boolean.toString(dflt))).booleanValue();
}
public Iterator configKeys() {
return configProps.keySet().iterator();
}

View File

@ -534,6 +534,9 @@ isTransparentProxy=false
# Specifies if yacy should use the http connection keep-alive feature
connectionKeepAliveSupport=true
# Specifies if the proxy should send the via header according to RFC
proxy.sendViaHeader=true
# Configuration options needed to configure server port forwarding
portForwardingEnabled=false
portForwardingUseProxy=false