fix NPE related 500 (Bad Request) response of UrlProxy on blacklisted urls,

by adding parameter HTTPDeamon and removing unused hostAddress lookup code in sendRespondError
pull/1/head
reger 10 years ago
parent 7e4e9f7e32
commit 1f9389396a

@ -21,6 +21,7 @@ import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.protocol.ClientIdentification;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.HeaderFramework;
import static net.yacy.cora.protocol.HeaderFramework.http1_1;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.protocol.ResponseHeader;
import net.yacy.cora.util.ConcurrentLog;
@ -156,6 +157,7 @@ public class UrlProxyServlet extends ProxyServlet implements Servlet {
prop.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_1_1);
prop.put(HeaderFramework.CONNECTION_PROP_HOST, hostwithport);
prop.put(HeaderFramework.CONNECTION_PROP_PATH, proxyurl.getPath().replaceAll(" ", "%20"));
prop.put(HeaderFramework.CONNECTION_PROP_METHOD, request.getMethod()); // only needed for HTTPDeamon errormsg in case of blacklisted url
if (proxyurl.getQuery() != null) prop.put(HeaderFramework.CONNECTION_PROP_ARGS, proxyurl.getQuery());
prop.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, Domains.LOCALHOST);
@ -278,7 +280,13 @@ public class UrlProxyServlet extends ProxyServlet implements Servlet {
} else {
if (httpStatus >= HttpServletResponse.SC_BAD_REQUEST) {
response.sendError(httpStatus,"Site " + proxyurl + " returned with status");
if (HeaderFramework.http1_1.containsKey(Integer.toString(httpStatus))) {
//http1_1 includes http1_0 messages
final String httpStatusText = HeaderFramework.http1_1.get(Integer.toString(httpStatus));
response.sendError(httpStatus, "Site " + proxyurl + " returned with status " + httpStatus + " (" + httpStatusText + ")");
} else {
response.sendError(httpStatus, "Site " + proxyurl + " returned with status " + httpStatus);
}
return;
}
if ((response.getHeader(HeaderFramework.CONTENT_LENGTH) == null) && prop.containsKey(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE)) {

@ -158,19 +158,6 @@ public final class HTTPDemon {
String clientIP = (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); if (clientIP == null) clientIP = Domains.LOCALHOST;
// check if ip is local ip address
final InetAddress hostAddress = Domains.dnsResolve(clientIP);
if (hostAddress == null) {
tp.put("host", Domains.myPublicLocalIP().getHostAddress());
tp.put("port", switchboard.getLocalPort("port", 8090));
} else if (hostAddress.isSiteLocalAddress() || hostAddress.isLoopbackAddress()) {
tp.put("host", Domains.myPublicLocalIP().getHostAddress());
tp.put("port", switchboard.getLocalPort("port", 8090));
} else {
tp.put("host", switchboard.myPublicIP());
tp.put("port", switchboard.getPublicPort("port", 8090));
}
tp.put("peerName", (switchboard.peers == null) ? "" : switchboard.peers.myName());
tp.put("errorMessageType", Integer.toString(errorcase));
tp.put("httpStatus", Integer.toString(httpStatusCode) + " " + httpStatusText);

Loading…
Cancel
Save