I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 1acd5caa authored by zzz's avatar zzz
Browse files

* HTTP client: Fix 'connection reset' browser messages

   after an error in the first line (ticket #1277)
   - A SocketException is an IOE
   - out can't be null
parent f69b7573
No related branches found
No related tags found
No related merge requests found
...@@ -457,10 +457,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -457,10 +457,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
if(_log.shouldLog(Log.WARN)) { if(_log.shouldLog(Log.WARN)) {
_log.warn(getPrefix(requestId) + "Bad request [" + request + "]", use); _log.warn(getPrefix(requestId) + "Bad request [" + request + "]", use);
} }
if(out != null) { out.write(getErrorPage("baduri", ERR_BAD_URI));
out.write(getErrorPage("baduri", ERR_BAD_URI)); writeFooter(out);
writeFooter(out); reader.drain();
}
s.close(); s.close();
return; return;
} }
...@@ -638,7 +637,6 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -638,7 +637,6 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
// Did addresshelper key conflict? // Did addresshelper key conflict?
if(ahelperConflict) { if(ahelperConflict) {
if(out != null) {
// convert ahelperKey to b32 // convert ahelperKey to b32
String alias = getHostName(ahelperKey); String alias = getHostName(ahelperKey);
if(alias.equals("i2p")) { if(alias.equals("i2p")) {
...@@ -662,8 +660,8 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -662,8 +660,8 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
out.write(_("To visit the destination in your host database, click <a href=\"{0}\">here</a>. To visit the conflicting addresshelper destination, click <a href=\"{1}\">here</a>.", trustedURL, conflictURL).getBytes("UTF-8")); out.write(_("To visit the destination in your host database, click <a href=\"{0}\">here</a>. To visit the conflicting addresshelper destination, click <a href=\"{1}\">here</a>.", trustedURL, conflictURL).getBytes("UTF-8"));
out.write(("</p></div>").getBytes()); out.write(("</p></div>").getBytes());
writeFooter(out); writeFooter(out);
}
} }
reader.drain();
s.close(); s.close();
return; return;
} }
...@@ -694,10 +692,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -694,10 +692,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
} else if(hostLowerCase.equals("localhost") || host.equals("127.0.0.1") || } else if(hostLowerCase.equals("localhost") || host.equals("127.0.0.1") ||
host.startsWith("192.168.") || host.equals("[::1]")) { host.startsWith("192.168.") || host.equals("[::1]")) {
// if somebody is trying to get to 192.168.example.com, oh well // if somebody is trying to get to 192.168.example.com, oh well
if(out != null) { out.write(getErrorPage("localhost", ERR_LOCALHOST));
out.write(getErrorPage("localhost", ERR_LOCALHOST)); writeFooter(out);
writeFooter(out); reader.drain();
}
s.close(); s.close();
return; return;
} else if(host.contains(".") || host.startsWith("[")) { } else if(host.contains(".") || host.startsWith("[")) {
...@@ -743,10 +740,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -743,10 +740,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
_log.warn(getPrefix(requestId) + "Host wants to be outproxied, but we dont have any!"); _log.warn(getPrefix(requestId) + "Host wants to be outproxied, but we dont have any!");
} }
l.log("No outproxy found for the request."); l.log("No outproxy found for the request.");
if(out != null) { out.write(getErrorPage("noproxy", _ERR_NO_OUTPROXY));
out.write(getErrorPage("noproxy", _ERR_NO_OUTPROXY)); writeFooter(out);
writeFooter(out); reader.drain();
}
s.close(); s.close();
return; return;
} }
...@@ -765,10 +761,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -765,10 +761,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
if(_log.shouldLog(Log.WARN)) { if(_log.shouldLog(Log.WARN)) {
_log.warn("NODOTS, NOI2P: " + request); _log.warn("NODOTS, NOI2P: " + request);
} }
if(out != null) { out.write(getErrorPage("denied", ERR_REQUEST_DENIED));
out.write(getErrorPage("denied", ERR_REQUEST_DENIED)); writeFooter(out);
writeFooter(out); reader.drain();
}
s.close(); s.close();
return; return;
} // end host name processing } // end host name processing
...@@ -909,14 +904,12 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -909,14 +904,12 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
if(method == null || (destination == null && !usingInternalOutproxy)) { if(method == null || (destination == null && !usingInternalOutproxy)) {
//l.log("No HTTP method found in the request."); //l.log("No HTTP method found in the request.");
if(out != null) { if (protocol != null && "http".equals(protocol.toLowerCase(Locale.US))) {
if(protocol != null && "http".equals(protocol.toLowerCase(Locale.US))) { out.write(getErrorPage("denied", ERR_REQUEST_DENIED));
out.write(getErrorPage("denied", ERR_REQUEST_DENIED)); } else {
} else { out.write(getErrorPage("protocol", ERR_BAD_PROTOCOL));
out.write(getErrorPage("protocol", ERR_BAD_PROTOCOL));
}
writeFooter(out);
} }
writeFooter(out);
s.close(); s.close();
return; return;
} }
...@@ -1090,13 +1083,6 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -1090,13 +1083,6 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
byte[] data = newRequest.toString().getBytes("ISO-8859-1"); byte[] data = newRequest.toString().getBytes("ISO-8859-1");
new I2PTunnelHTTPClientRunner(s, i2ps, sockLock, data, mySockets, onTimeout); new I2PTunnelHTTPClientRunner(s, i2ps, sockLock, data, mySockets, onTimeout);
} }
} catch (SocketException ex) {
if (_log.shouldLog(Log.INFO)) {
_log.info(getPrefix(requestId) + "Error trying to connect", ex);
}
//l.log("Error connecting: " + ex.getMessage());
handleHTTPClientException(ex, out, targetRequest, usingWWWProxy, currentProxy, requestId);
closeSocket(s);
} catch(IOException ex) { } catch(IOException ex) {
if(_log.shouldLog(Log.INFO)) { if(_log.shouldLog(Log.INFO)) {
_log.info(getPrefix(requestId) + "Error trying to connect", ex); _log.info(getPrefix(requestId) + "Error trying to connect", ex);
...@@ -1207,6 +1193,22 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -1207,6 +1193,22 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
// _br = new BufferedReader(new InputStreamReader(_s, "ISO-8859-1")); // _br = new BufferedReader(new InputStreamReader(_s, "ISO-8859-1"));
//return _br.readLine(); //return _br.readLine();
} }
/**
* Read the rest of the headers, which keeps firefox
* from complaining about connection reset after
* an error on the first line.
* @since 0.9.14
*/
public void drain() {
try {
String line;
do {
line = DataHelper.readLine(_s);
// \r not stripped so length == 1 is empty
} while (line != null && line.length() > 1);
} catch (IOException ioe) {}
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment