summaryrefslogtreecommitdiffstats
path: root/app/src
diff options
context:
space:
mode:
authortom79 <tschneider.ac@gmail.com>2020-03-27 18:31:46 +0100
committertom79 <tschneider.ac@gmail.com>2020-03-27 18:31:46 +0100
commit2a68fa01dd77d45b0c459de71c621dd60dd2334d (patch)
tree4c14e88cb9890af2e23f65e31ebcb4ef73120911 /app/src
parenta3f4d8e6d52fe5d1721804aede4f16a78d60ca87 (diff)
Fix issue #415
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/app/fedilab/android/client/HttpsConnection.java123
1 files changed, 84 insertions, 39 deletions
diff --git a/app/src/main/java/app/fedilab/android/client/HttpsConnection.java b/app/src/main/java/app/fedilab/android/client/HttpsConnection.java
index 142aa86d0..cd21db463 100644
--- a/app/src/main/java/app/fedilab/android/client/HttpsConnection.java
+++ b/app/src/main/java/app/fedilab/android/client/HttpsConnection.java
@@ -267,50 +267,95 @@ public class HttpsConnection {
URL url = new URL(urlConnection);
-
- if (proxy != null)
- httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
- else
- httpsURLConnection = (HttpsURLConnection) url.openConnection();
- httpsURLConnection.setConnectTimeout(30 * 1000);
- httpsURLConnection.setRequestProperty("http.keepAlive", "false");
- httpsURLConnection.setRequestProperty("Content-Type", "application/json");
- httpsURLConnection.setRequestProperty("Accept", "application/json");
- httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
- httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
- httpsURLConnection.setRequestMethod("GET");
- httpsURLConnection.setDefaultUseCaches(true);
- httpsURLConnection.setUseCaches(true);
- String response;
- if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
- getSinceMaxId();
- response = converToString(httpsURLConnection.getInputStream());
- } else {
- String error = null;
- if (httpsURLConnection.getErrorStream() != null) {
- InputStream stream = httpsURLConnection.getErrorStream();
- if (stream == null) {
- stream = httpsURLConnection.getInputStream();
- }
- try (Scanner scanner = new Scanner(stream)) {
- scanner.useDelimiter("\\Z");
- if (scanner.hasNext()) {
- error = scanner.next();
+ if (urlConnection.startsWith("https://")) {
+ if (proxy != null)
+ httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy);
+ else
+ httpsURLConnection = (HttpsURLConnection) url.openConnection();
+ httpsURLConnection.setConnectTimeout(30 * 1000);
+ httpsURLConnection.setRequestProperty("http.keepAlive", "false");
+ httpsURLConnection.setRequestProperty("Content-Type", "application/json");
+ httpsURLConnection.setRequestProperty("Accept", "application/json");
+ httpsURLConnection.setRequestProperty("User-Agent", USER_AGENT);
+ httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory(this.instance));
+ httpsURLConnection.setRequestMethod("GET");
+ httpsURLConnection.setDefaultUseCaches(true);
+ httpsURLConnection.setUseCaches(true);
+ String response;
+ if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
+ getSinceMaxId();
+ response = converToString(httpsURLConnection.getInputStream());
+ } else {
+ String error = null;
+ if (httpsURLConnection.getErrorStream() != null) {
+ InputStream stream = httpsURLConnection.getErrorStream();
+ if (stream == null) {
+ stream = httpsURLConnection.getInputStream();
}
- } catch (Exception e) {
- e.printStackTrace();
+ try (Scanner scanner = new Scanner(stream)) {
+ scanner.useDelimiter("\\Z");
+ if (scanner.hasNext()) {
+ error = scanner.next();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ int responseCode = httpsURLConnection.getResponseCode();
+ try {
+ httpsURLConnection.getInputStream().close();
+ } catch (Exception ignored) {
}
+ throw new HttpsConnectionException(responseCode, error);
}
- int responseCode = httpsURLConnection.getResponseCode();
- try {
- httpsURLConnection.getInputStream().close();
- } catch (Exception ignored) {
+ getSinceMaxId();
+ httpsURLConnection.getInputStream().close();
+ return response;
+ }else{
+ if (proxy != null)
+ httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
+ else
+ httpURLConnection = (HttpURLConnection) url.openConnection();
+ httpURLConnection.setConnectTimeout(30 * 1000);
+ httpURLConnection.setRequestProperty("http.keepAlive", "false");
+ httpURLConnection.setRequestProperty("Content-Type", "application/json");
+ httpURLConnection.setRequestProperty("Accept", "application/json");
+ httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
+ httpURLConnection.setRequestMethod("GET");
+ httpURLConnection.setDefaultUseCaches(true);
+ httpURLConnection.setUseCaches(true);
+ String response;
+ if (httpURLConnection.getResponseCode() >= 200 && httpURLConnection.getResponseCode() < 400) {
+ getSinceMaxId();
+ response = converToString(httpURLConnection.getInputStream());
+ } else {
+ String error = null;
+ if (httpURLConnection.getErrorStream() != null) {
+ InputStream stream = httpURLConnection.getErrorStream();
+ if (stream == null) {
+ stream = httpURLConnection.getInputStream();
+ }
+ try (Scanner scanner = new Scanner(stream)) {
+ scanner.useDelimiter("\\Z");
+ if (scanner.hasNext()) {
+ error = scanner.next();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ int responseCode = httpURLConnection.getResponseCode();
+ try {
+ httpURLConnection.getInputStream().close();
+ } catch (Exception ignored) {
+ }
+ throw new HttpsConnectionException(responseCode, error);
}
- throw new HttpsConnectionException(responseCode, error);
+ getSinceMaxId();
+ httpURLConnection.getInputStream().close();
+ return response;
}
- getSinceMaxId();
- httpsURLConnection.getInputStream().close();
- return response;
+
}