Commit 302d0541 authored by Ricki Hirner's avatar Ricki Hirner

Send Accept header; update Kotlin/gradle

parent edb77e7f
Pipeline #21171281 passed with stage
in 1 minute and 27 seconds
......@@ -9,6 +9,9 @@
package at.bitfire.icsdroid
import android.util.Log
import java.net.HttpURLConnection
import java.net.URL
import java.net.URLConnection
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
import java.util.regex.Pattern
......@@ -35,4 +38,21 @@ object MiscUtils {
return charset
}
/**
* Opens a connection from an URL and prepares some settings like timoues and
* request headers (User-Agent, Accept, etc.).
*/
fun prepareConnection(url: URL): URLConnection {
val conn = url.openConnection()
conn.connectTimeout = 7000
conn.readTimeout = 20000
if (conn is HttpURLConnection) {
conn.setRequestProperty("User-Agent", Constants.USER_AGENT)
conn.setRequestProperty("Accept", "text/calendar")
}
return conn
}
}
......@@ -144,7 +144,7 @@ class SyncAdapter(
throw IOException(context.getString(R.string.sync_permission_required))
Log.i(Constants.TAG, "Fetching calendar $url")
conn = url.openConnection()
conn = MiscUtils.prepareConnection(url)
if (calendar.lastModified != 0L)
conn.ifModifiedSince = calendar.lastModified
......@@ -155,7 +155,6 @@ class SyncAdapter(
}
if (conn is HttpURLConnection) {
conn.setRequestProperty("User-Agent", Constants.USER_AGENT)
conn.setRequestProperty("Connection", "close") // workaround for AndroidHttpClient bug, which causes "Unexpected Status Line" exceptions
conn.instanceFollowRedirects = false
......
......@@ -112,15 +112,13 @@ class AddCalendarValidationFragment: DialogFragment(), LoaderManager.LoaderCallb
var conn: URLConnection? = null
var certManager: CustomCertManager? = null
try {
var url = info.url
var url = info.url!!
var followRedirect: Boolean
var redirect = 0
do {
followRedirect = false
try {
conn = url!!.openConnection()
conn.connectTimeout = 7000
conn.readTimeout = 20000
conn = MiscUtils.prepareConnection(url)
if (conn is HttpsURLConnection) {
certManager = CustomCertificates.certManager(context, true)
......@@ -128,7 +126,6 @@ class AddCalendarValidationFragment: DialogFragment(), LoaderManager.LoaderCallb
}
if (conn is HttpURLConnection) {
conn.setRequestProperty("User-Agent", Constants.USER_AGENT)
conn.instanceFollowRedirects = false
if (info.username != null && info.password != null) {
......
......@@ -7,14 +7,14 @@
*/
buildscript {
ext.kotlin_version = '1.2.31'
ext.kotlin_version = '1.2.40'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
......
Subproject commit 7851ea3a8b54193d757d4c084eb7794e602de60a
Subproject commit a0d592c7f0afa4f31ff7088cd4c60de6fc8782d8
lombok.addGeneratedAnnotation = false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment