Disconnect HTTP Connection after using IP2C

Affects issues:
- Possibly fixes #1296, #1291, #1292
This commit is contained in:
Rsl1122 2020-01-18 11:27:05 +02:00
parent bccff17d85
commit f5809420a5

View File

@ -72,15 +72,20 @@ public class IP2CGeolocator implements Geolocator {
}
public Optional<String> readIPFromURL(String address) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL("http://ip2c.org/" + address).openConnection();
connection.setDefaultUseCaches(false);
connection.setUseCaches(false);
connection.connect();
try (
InputStream in = connection.getInputStream()
) {
String answer = readAnswer(in);
return resolveIP(answer);
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) new URL("http://ip2c.org/" + address).openConnection();
connection.setDefaultUseCaches(false);
connection.setUseCaches(false);
connection.connect();
try (
InputStream in = connection.getInputStream()
) {
String answer = readAnswer(in);
return resolveIP(answer);
}
} finally {
if (connection != null) connection.disconnect();
}
}