HTTPDownloader: Fix user agent sending on Windows/Android

This commit is contained in:
Connor McLaughlin
2021-04-04 12:55:03 +10:00
parent 251043f11a
commit d41b5be908
10 changed files with 40 additions and 33 deletions

View File

@ -15,17 +15,21 @@ import java.net.URL;
public class URLDownloader {
private int statusCode = -1;
private byte[] data = null;
private final String userAgent;
public URLDownloader() {
public URLDownloader(String userAgent) {
this.userAgent = userAgent;
}
static private HttpURLConnection getConnection(String url) {
private HttpURLConnection getConnection(String url) {
try {
final URL parsedUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) parsedUrl.openConnection();
if (connection == null)
throw new RuntimeException(String.format("openConnection(%s) returned null", url));
if (userAgent != null)
connection.addRequestProperty("User-Agent", userAgent);
return connection;
} catch (Exception e) {
e.printStackTrace();