From 595e0c7e564d423bd2be4260eeabf173ac03d7c2 Mon Sep 17 00:00:00 2001 From: theli Date: Fri, 30 Sep 2005 06:15:22 +0000 Subject: [PATCH] *) Bugfix for ProxyErrormsg: Wrong base URL See: http://www.yacy-forum.de/viewtopic.php?p=9905#9905 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@815 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/http/httpd.java | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java index 06bcc58c1..941a11508 100644 --- a/source/de/anomic/http/httpd.java +++ b/source/de/anomic/http/httpd.java @@ -49,10 +49,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; +import java.io.PushbackInputStream; import java.lang.reflect.Constructor; import java.net.InetAddress; import java.net.MalformedURLException; import java.net.URL; +import java.net.UnknownHostException; import java.util.Arrays; import java.util.Date; import java.util.HashMap; @@ -977,10 +979,29 @@ public final class httpd implements serverHandler { serverObjects tp = new serverObjects(); // tp.put("host", serverCore.publicIP().getHostAddress()); -// tp.put("port", switchboard.getConfig("port", "8080")); +// tp.put("port", switchboard.getConfig("port", "8080")); + + String clientIP = conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP,"127.0.0.1"); + + // check if ip is local ip address + try { + InetAddress hostAddress = InetAddress.getByName(clientIP); + if (hostAddress.isSiteLocalAddress() || hostAddress.isLoopbackAddress()) { + tp.put("host", serverCore.publicLocalIP().getHostAddress()); + tp.put("port", switchboard.getConfig("port", "8080")); + } else { + tp.put("host", serverCore.publicIP()); + tp.put("port", (serverCore.portForwardingEnabled && (serverCore.portForwarding != null)) + ? Integer.toString(serverCore.portForwarding.getPort()) + : switchboard.getConfig("port", "8080")); + } + } catch (UnknownHostException e) { + tp.put("host", serverCore.publicLocalIP().getHostAddress()); + tp.put("port", switchboard.getConfig("port", "8080")); + } + + tp.put("peerName", yacyCore.seedDB.mySeed.getName()); - tp.put("host", host); - tp.put("port", Integer.toString(port)); tp.put("errorMessageType", errorcase); tp.put("httpStatus", Integer.toString(httpStatusCode) + " " + httpStatusText); tp.put("requestMethod", conProp.getProperty(httpHeader.CONNECTION_PROP_METHOD));