Bimba.git

commit 3a934a88570d42bb62e7a3164e0d7c6f4cc80d1a

Author: Adam Pioterek <adam.pioterek@protonmail.ch>

retry http when https fails

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt b/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
index 91c9cb88d3acc22103c40c3c18880e557db2b309..0d25892bceb5cd43b1abad09f06f60e4f5680bb8 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
@@ -9,7 +9,7 @@ import android.os.Build
 import ml.adamsprogs.bimba.*
 import java.net.*
 import java.util.zip.GZIPInputStream
-import javax.net.ssl.HttpsURLConnection
+import javax.net.ssl.*
 
 class TimetableDownloader : IntentService("TimetableDownloader") {
     companion object {
@@ -37,12 +37,19 @@             }
 
             val localETag = prefs.getString("etag", "")
 
-            val httpCon: HttpsURLConnection
+            var httpCon: HttpURLConnection
             try {
-                val url = URL("https://adamsprogs.ml/gtfs") //todo if https fails -> http
-                httpCon = url.openConnection() as HttpsURLConnection
-                httpCon.addRequestProperty("ETag", localETag)
-                httpCon.connect()
+                try {
+                    val url = URL("https://adamsprogs.ml/gtfs")
+                    httpCon = url.openConnection() as HttpsURLConnection
+                    httpCon.addRequestProperty("ETag", localETag)
+                    httpCon.connect()
+                } catch (e:SSLException) {
+                    val url = URL("http://adamsprogs.ml/gtfs")
+                    httpCon = url.openConnection() as HttpURLConnection
+                    httpCon.addRequestProperty("ETag", localETag)
+                    httpCon.connect()
+                }
                 if (httpCon.responseCode == HttpsURLConnection.HTTP_NOT_MODIFIED) {
                     sendResult(RESULT_UP_TO_DATE)
                     return