diff --git a/build.gradle b/build.gradle index bb5e415f3..2d2d816ef 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ buildscript { 'kotlin': '1.3.20', 'moshi': '1.8.0', 'okio': '2.2.2', + 'ktlint': '0.31.0' ] ext.deps = [ @@ -43,6 +44,7 @@ buildscript { classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.7.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.18" + classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.21.1' } repositories { @@ -84,6 +86,7 @@ subprojects { project -> apply plugin: 'ru.vyarus.animalsniffer' apply plugin: 'net.ltgt.errorprone' apply plugin: 'org.jetbrains.dokka' + apply plugin: 'com.diffplug.gradle.spotless' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -104,6 +107,13 @@ subprojects { project -> signature 'net.sf.androidscents.signature:android-api-level-21:5.0.1_r2@signature' signature 'org.codehaus.mojo.signature:java18:1.0@signature' } + + spotless { + kotlin { + target "**/*.kt" + ktlint(versions.ktlint).userData(['indent_size': '2', 'continuation_indent_size' : '2']) + } + } def platform = System.getProperty("okhttp.platform", "jdk8") diff --git a/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.kt b/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.kt index 9b97d4b4a..5f088fa71 100644 --- a/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.kt +++ b/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.kt @@ -111,8 +111,11 @@ class DnsOverHttps internal constructor(builder: Builder) : Dns { } private fun buildRequest( - hostname: String, networkRequests: MutableList, results: MutableList, - failures: MutableList, type: Int + hostname: String, + networkRequests: MutableList, + results: MutableList, + failures: MutableList, + type: Int ) { val request = buildRequest(hostname, type) val response = getCacheOnlyResponse(request) @@ -122,8 +125,10 @@ class DnsOverHttps internal constructor(builder: Builder) : Dns { } private fun executeRequests( - hostname: String, networkRequests: List, - responses: MutableList, failures: MutableList + hostname: String, + networkRequests: List, + responses: MutableList, + failures: MutableList ) { val latch = CountDownLatch(networkRequests.size) @@ -151,7 +156,9 @@ class DnsOverHttps internal constructor(builder: Builder) : Dns { } private fun processResponse( - response: Response, hostname: String, results: MutableList, + response: Response, + hostname: String, + results: MutableList, failures: MutableList ) { try { @@ -244,7 +251,6 @@ class DnsOverHttps internal constructor(builder: Builder) : Dns { url(requestUrl) } - }.build() class Builder { diff --git a/okhttp-logging-interceptor/src/main/java/okhttp3/logging/HttpLoggingInterceptor.kt b/okhttp-logging-interceptor/src/main/java/okhttp3/logging/HttpLoggingInterceptor.kt index 2bc3364f0..f31b005a8 100644 --- a/okhttp-logging-interceptor/src/main/java/okhttp3/logging/HttpLoggingInterceptor.kt +++ b/okhttp-logging-interceptor/src/main/java/okhttp3/logging/HttpLoggingInterceptor.kt @@ -156,7 +156,8 @@ class HttpLoggingInterceptor @JvmOverloads constructor( val requestBody = request.body() val connection = chain.connection() - var requestStartMessage = ("--> ${request.method()} ${request.url()}${if (connection != null) " " + connection.protocol() else ""}") + var requestStartMessage = + ("--> ${request.method()} ${request.url()}${if (connection != null) " " + connection.protocol() else ""}") if (!logHeaders && requestBody != null) { requestStartMessage += " (${requestBody.contentLength()}-byte body)" } @@ -312,9 +313,9 @@ class HttpLoggingInterceptor @JvmOverloads constructor( private fun bodyHasUnknownEncoding(headers: Headers): Boolean { val contentEncoding = headers["Content-Encoding"] - return (contentEncoding != null - && !contentEncoding.equals("identity", ignoreCase = true) - && !contentEncoding.equals("gzip", ignoreCase = true)) + return (contentEncoding != null && + !contentEncoding.equals("identity", ignoreCase = true) && + !contentEncoding.equals("gzip", ignoreCase = true)) } } } diff --git a/okhttp-logging-interceptor/src/main/java/okhttp3/logging/LoggingEventListener.kt b/okhttp-logging-interceptor/src/main/java/okhttp3/logging/LoggingEventListener.kt index 0538f6d19..3e4725099 100644 --- a/okhttp-logging-interceptor/src/main/java/okhttp3/logging/LoggingEventListener.kt +++ b/okhttp-logging-interceptor/src/main/java/okhttp3/logging/LoggingEventListener.kt @@ -68,7 +68,10 @@ class LoggingEventListener private constructor( } override fun connectEnd( - call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy, protocol: Protocol? + call: Call, + inetSocketAddress: InetSocketAddress, + proxy: Proxy, + protocol: Protocol? ) { logWithTime("connectEnd: $protocol") } diff --git a/okhttp-testing-support/src/main/java/okhttp3/PlatformRule.kt b/okhttp-testing-support/src/main/java/okhttp3/PlatformRule.kt index 0319bb843..359de2c68 100644 --- a/okhttp-testing-support/src/main/java/okhttp3/PlatformRule.kt +++ b/okhttp-testing-support/src/main/java/okhttp3/PlatformRule.kt @@ -22,7 +22,8 @@ import okhttp3.internal.platform.Platform import org.conscrypt.Conscrypt import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.CoreMatchers.not -import org.junit.Assume.* +import org.junit.Assume.assumeThat +import org.junit.Assume.assumeTrue import org.junit.rules.ExternalResource import java.security.Security diff --git a/okhttp-urlconnection/src/main/java/okhttp3/JavaNetCookieJar.kt b/okhttp-urlconnection/src/main/java/okhttp3/JavaNetCookieJar.kt index c9b2cd50f..dbed55acb 100644 --- a/okhttp-urlconnection/src/main/java/okhttp3/JavaNetCookieJar.kt +++ b/okhttp-urlconnection/src/main/java/okhttp3/JavaNetCookieJar.kt @@ -53,8 +53,8 @@ class JavaNetCookieJar(private val cookieHandler: CookieHandler) : CookieJar { var cookies: MutableList? = null for ((key, value) in cookieHeaders) { - if (("Cookie".equals(key, ignoreCase = true) || "Cookie2".equals(key, ignoreCase = true)) - && value.isNotEmpty()) { + if (("Cookie".equals(key, ignoreCase = true) || "Cookie2".equals(key, ignoreCase = true)) && + value.isNotEmpty()) { for (header in value) { if (cookies == null) cookies = ArrayList() cookies.addAll(decodeHeaderAsJavaNetCookies(url, header)) diff --git a/okhttp/src/main/java/okhttp3/Address.kt b/okhttp/src/main/java/okhttp3/Address.kt index 62139b0b9..8d2478975 100644 --- a/okhttp/src/main/java/okhttp3/Address.kt +++ b/okhttp/src/main/java/okhttp3/Address.kt @@ -32,18 +32,18 @@ import okhttp3.internal.Util * HTTP requests that share the same `Address` may also share the same [Connection]. */ class Address( - uriHost: String, - uriPort: Int, - private val dns: Dns, - private val socketFactory: SocketFactory, - private val sslSocketFactory: SSLSocketFactory?, - private val hostnameVerifier: HostnameVerifier?, - private val certificatePinner: CertificatePinner?, - private val proxyAuthenticator: Authenticator, - private val proxy: Proxy?, - protocols: List, - connectionSpecs: List, - private val proxySelector: ProxySelector + uriHost: String, + uriPort: Int, + private val dns: Dns, + private val socketFactory: SocketFactory, + private val sslSocketFactory: SSLSocketFactory?, + private val hostnameVerifier: HostnameVerifier?, + private val certificatePinner: CertificatePinner?, + private val proxyAuthenticator: Authenticator, + private val proxy: Proxy?, + protocols: List, + connectionSpecs: List, + private val proxySelector: ProxySelector ) { private val url: HttpUrl = HttpUrl.Builder() .scheme(if (sslSocketFactory != null) "https" else "http") @@ -104,9 +104,9 @@ class Address( fun certificatePinner() = certificatePinner override fun equals(other: Any?): Boolean { - return other is Address - && url == other.url - && equalsNonHost(other) + return other is Address && + url == other.url && + equalsNonHost(other) } override fun hashCode(): Int { @@ -125,16 +125,16 @@ class Address( } internal fun equalsNonHost(that: Address): Boolean { - return this.dns == that.dns - && this.proxyAuthenticator == that.proxyAuthenticator - && this.protocols == that.protocols - && this.connectionSpecs == that.connectionSpecs - && this.proxySelector == that.proxySelector - && this.proxy == that.proxy - && this.sslSocketFactory == that.sslSocketFactory - && this.hostnameVerifier == that.hostnameVerifier - && this.certificatePinner == that.certificatePinner - && this.url().port() == that.url().port() + return this.dns == that.dns && + this.proxyAuthenticator == that.proxyAuthenticator && + this.protocols == that.protocols && + this.connectionSpecs == that.connectionSpecs && + this.proxySelector == that.proxySelector && + this.proxy == that.proxy && + this.sslSocketFactory == that.sslSocketFactory && + this.hostnameVerifier == that.hostnameVerifier && + this.certificatePinner == that.certificatePinner && + this.url().port() == that.url().port() } override fun toString(): String { diff --git a/okhttp/src/main/java/okhttp3/Authenticator.kt b/okhttp/src/main/java/okhttp3/Authenticator.kt index c8fa055c6..31031f387 100644 --- a/okhttp/src/main/java/okhttp3/Authenticator.kt +++ b/okhttp/src/main/java/okhttp3/Authenticator.kt @@ -118,7 +118,7 @@ interface Authenticator { @JvmName("-deprecated_Authenticator") inline operator fun invoke( crossinline block: (route: Route?, response: Response) -> Request? - ): Authenticator = object: Authenticator { + ): Authenticator = object : Authenticator { override fun authenticate(route: Route?, response: Response) = block(route, response) } } diff --git a/okhttp/src/main/java/okhttp3/Cache.kt b/okhttp/src/main/java/okhttp3/Cache.kt index 094f81f23..df0554313 100644 --- a/okhttp/src/main/java/okhttp3/Cache.kt +++ b/okhttp/src/main/java/okhttp3/Cache.kt @@ -642,13 +642,12 @@ class Cache internal constructor( } catch (e: CertificateEncodingException) { throw IOException(e.message) } - } fun matches(request: Request, response: Response): Boolean { - return url == request.url().toString() - && requestMethod == request.method() - && HttpHeaders.varyMatches(response, varyHeaders, request) + return url == request.url().toString() && + requestMethod == request.method() && + HttpHeaders.varyMatches(response, varyHeaders, request) } fun response(snapshot: DiskLruCache.Snapshot): Response { diff --git a/okhttp/src/main/java/okhttp3/CacheControl.kt b/okhttp/src/main/java/okhttp3/CacheControl.kt index 17d5972b1..cb13511a9 100644 --- a/okhttp/src/main/java/okhttp3/CacheControl.kt +++ b/okhttp/src/main/java/okhttp3/CacheControl.kt @@ -279,7 +279,6 @@ class CacheControl private constructor( pos = HttpHeaders.skipUntil(value, pos, "\"") parameter = value.substring(parameterStart, pos) pos++ // Consume '"' close quote (if necessary). - } else { // Unquoted string. val parameterStart = pos diff --git a/okhttp/src/main/java/okhttp3/CertificatePinner.kt b/okhttp/src/main/java/okhttp3/CertificatePinner.kt index 292489ed8..ec4e07f61 100644 --- a/okhttp/src/main/java/okhttp3/CertificatePinner.kt +++ b/okhttp/src/main/java/okhttp3/CertificatePinner.kt @@ -154,11 +154,11 @@ data class CertificatePinner internal constructor( when (pin.hashAlgorithm) { "sha256/" -> { if (sha256 == null) sha256 = sha256(x509Certificate) - if (pin.hash == sha256) return // Success! + if (pin.hash == sha256) return // Success! } "sha1/" -> { if (sha1 == null) sha1 = sha1(x509Certificate) - if (pin.hash == sha1) return // Success! + if (pin.hash == sha1) return // Success! } else -> throw AssertionError("unsupported hashAlgorithm: ${pin.hashAlgorithm}") } @@ -235,8 +235,8 @@ data class CertificatePinner internal constructor( fun matches(hostname: String): Boolean { if (pattern.startsWith(WILDCARD)) { val firstDot = hostname.indexOf('.') - return hostname.length - firstDot - 1 == canonicalHostname.length - && hostname.regionMatches(firstDot + 1, canonicalHostname, 0, canonicalHostname.length, + return hostname.length - firstDot - 1 == canonicalHostname.length && + hostname.regionMatches(firstDot + 1, canonicalHostname, 0, canonicalHostname.length, ignoreCase = false) } return hostname == canonicalHostname diff --git a/okhttp/src/main/java/okhttp3/Challenge.kt b/okhttp/src/main/java/okhttp3/Challenge.kt index a425cfe59..c69b7950d 100644 --- a/okhttp/src/main/java/okhttp3/Challenge.kt +++ b/okhttp/src/main/java/okhttp3/Challenge.kt @@ -71,9 +71,9 @@ class Challenge( } override fun equals(other: Any?): Boolean { - return other is Challenge - && other.scheme == scheme - && other.authParams == authParams + return other is Challenge && + other.scheme == scheme && + other.authParams == authParams } override fun hashCode(): Int { @@ -86,5 +86,4 @@ class Challenge( override fun toString(): String { return "$scheme authParams=$authParams" } - } \ No newline at end of file diff --git a/okhttp/src/main/java/okhttp3/CipherSuite.kt b/okhttp/src/main/java/okhttp3/CipherSuite.kt index 124636e4f..877bbfd73 100644 --- a/okhttp/src/main/java/okhttp3/CipherSuite.kt +++ b/okhttp/src/main/java/okhttp3/CipherSuite.kt @@ -54,7 +54,7 @@ class CipherSuite private constructor( * ignoring the "TLS_" or "SSL_" prefix which is not consistent across platforms. In particular * some IBM JVMs use the "SSL_" prefix everywhere whereas Oracle JVMs mix "TLS_" and "SSL_". */ - internal val ORDER_BY_NAME = object: Comparator { + internal val ORDER_BY_NAME = object : Comparator { override fun compare(a: String, b: String): Int { var i = 4 val limit = Math.min(a.length, b.length) diff --git a/okhttp/src/main/java/okhttp3/ConnectionSpec.kt b/okhttp/src/main/java/okhttp3/ConnectionSpec.kt index f6c0a197b..1f8e4816a 100644 --- a/okhttp/src/main/java/okhttp3/ConnectionSpec.kt +++ b/okhttp/src/main/java/okhttp3/ConnectionSpec.kt @@ -125,13 +125,13 @@ class ConnectionSpec internal constructor(builder: Builder) { return false } - if (tlsVersions != null - && !nonEmptyIntersection(Util.NATURAL_ORDER, tlsVersions, socket.enabledProtocols)) { + if (tlsVersions != null && + !nonEmptyIntersection(Util.NATURAL_ORDER, tlsVersions, socket.enabledProtocols)) { return false } - if (cipherSuites != null - && !nonEmptyIntersection( + if (cipherSuites != null && + !nonEmptyIntersection( CipherSuite.ORDER_BY_NAME, cipherSuites, socket.enabledCipherSuites)) { return false } diff --git a/okhttp/src/main/java/okhttp3/Cookie.kt b/okhttp/src/main/java/okhttp3/Cookie.kt index 1ff6d8b45..020b64b19 100644 --- a/okhttp/src/main/java/okhttp3/Cookie.kt +++ b/okhttp/src/main/java/okhttp3/Cookie.kt @@ -254,9 +254,9 @@ data class Cookie private constructor( return true // As in 'example.com' matching 'example.com'. } - return urlHost.endsWith(domain) - && urlHost[urlHost.length - domain.length - 1] == '.' - && !verifyAsIpAddress(urlHost) + return urlHost.endsWith(domain) && + urlHost[urlHost.length - domain.length - 1] == '.' && + !verifyAsIpAddress(urlHost) } private fun pathMatch(url: HttpUrl, path: String): Boolean { @@ -381,8 +381,8 @@ data class Cookie private constructor( } // If the domain is a suffix of the url host, it must not be a public suffix. - if (urlHost.length != domain.length - && PublicSuffixDatabase.get().getEffectiveTldPlusOne(domain) == null) { + if (urlHost.length != domain.length && + PublicSuffixDatabase.get().getEffectiveTldPlusOne(domain) == null) { return null } @@ -469,11 +469,11 @@ data class Cookie private constructor( private fun dateCharacterOffset(input: String, pos: Int, limit: Int, invert: Boolean): Int { for (i in pos until limit) { val c = input[i].toInt() - val dateCharacter = (c < ' '.toInt() && c != '\t'.toInt() || c >= '\u007f'.toInt() - || c in '0'.toInt()..'9'.toInt() - || c in 'a'.toInt()..'z'.toInt() - || c in 'A'.toInt()..'Z'.toInt() - || c == ':'.toInt()) + val dateCharacter = (c < ' '.toInt() && c != '\t'.toInt() || c >= '\u007f'.toInt() || + c in '0'.toInt()..'9'.toInt() || + c in 'a'.toInt()..'z'.toInt() || + c in 'A'.toInt()..'Z'.toInt() || + c == ':'.toInt()) if (dateCharacter == !invert) return i } return limit diff --git a/okhttp/src/main/java/okhttp3/HttpUrl.kt b/okhttp/src/main/java/okhttp3/HttpUrl.kt index 006e3d355..e3fecf870 100644 --- a/okhttp/src/main/java/okhttp3/HttpUrl.kt +++ b/okhttp/src/main/java/okhttp3/HttpUrl.kt @@ -1151,8 +1151,8 @@ class HttpUrl internal constructor(builder: Builder) { this.scheme = "http" pos += "http:".length } else { - throw IllegalArgumentException("Expected URL scheme 'http' or 'https' but was '" - + input.substring(0, schemeDelimiterOffset) + "'") + throw IllegalArgumentException("Expected URL scheme 'http' or 'https' but was '" + + input.substring(0, schemeDelimiterOffset) + "'") } } else if (base != null) { this.scheme = base.scheme @@ -1297,13 +1297,16 @@ class HttpUrl internal constructor(builder: Builder) { /** Adds a path segment. If the input is ".." or equivalent, this pops a path segment. */ private fun push( - input: String, pos: Int, limit: Int, addTrailingSlash: Boolean, + input: String, + pos: Int, + limit: Int, + addTrailingSlash: Boolean, alreadyEncoded: Boolean ) { val segment = canonicalize( input, pos, limit, PATH_SEGMENT_ENCODE_SET, alreadyEncoded, false, false, true, null) if (isDot(segment)) { - return // Skip '.' path segments. + return // Skip '.' path segments. } if (isDotDot(segment)) { pop() @@ -1324,10 +1327,10 @@ class HttpUrl internal constructor(builder: Builder) { } private fun isDotDot(input: String): Boolean { - return (input == ".." - || input.equals("%2e.", ignoreCase = true) - || input.equals(".%2e", ignoreCase = true) - || input.equals("%2e%2e", ignoreCase = true)) + return (input == ".." || + input.equals("%2e.", ignoreCase = true) || + input.equals(".%2e", ignoreCase = true) || + input.equals("%2e%2e", ignoreCase = true)) } /** @@ -1368,12 +1371,12 @@ class HttpUrl internal constructor(builder: Builder) { for (i in pos + 1 until limit) { val c = input[i] - if (c >= 'a' && c <= 'z' - || c >= 'A' && c <= 'Z' - || c >= '0' && c <= '9' - || c == '+' - || c == '-' - || c == '.') { + if (c >= 'a' && c <= 'z' || + c >= 'A' && c <= 'Z' || + c >= '0' && c <= '9' || + c == '+' || + c == '-' || + c == '.') { continue // Scheme character. Keep going. } else if (c == ':') { return i // Scheme prefix! @@ -1436,7 +1439,6 @@ class HttpUrl internal constructor(builder: Builder) { } catch (e: NumberFormatException) { return -1 // Invalid port. } - } } } @@ -1615,10 +1617,10 @@ class HttpUrl internal constructor(builder: Builder) { @JvmStatic internal fun percentEncoded(encoded: String, pos: Int, limit: Int): Boolean { - return (pos + 2 < limit - && encoded[pos] == '%' - && decodeHexDigit(encoded[pos + 1]) != -1 - && decodeHexDigit(encoded[pos + 2]) != -1) + return (pos + 2 < limit && + encoded[pos] == '%' && + decodeHexDigit(encoded[pos + 1]) != -1 && + decodeHexDigit(encoded[pos + 2]) != -1) } /** @@ -1643,21 +1645,27 @@ class HttpUrl internal constructor(builder: Builder) { */ @JvmStatic internal fun canonicalize( - input: String, pos: Int, limit: Int, encodeSet: String, - alreadyEncoded: Boolean, strict: Boolean, plusIsSpace: Boolean, asciiOnly: Boolean, + input: String, + pos: Int, + limit: Int, + encodeSet: String, + alreadyEncoded: Boolean, + strict: Boolean, + plusIsSpace: Boolean, + asciiOnly: Boolean, charset: Charset? ): String { var codePoint: Int var i = pos while (i < limit) { codePoint = input.codePointAt(i) - if (codePoint < 0x20 - || codePoint == 0x7f - || codePoint >= 0x80 && asciiOnly - || encodeSet.indexOf(codePoint.toChar()) != -1 - || codePoint == '%'.toInt() && (!alreadyEncoded || strict && !percentEncoded(input, i, - limit)) - || codePoint == '+'.toInt() && plusIsSpace) { + if (codePoint < 0x20 || + codePoint == 0x7f || + codePoint >= 0x80 && asciiOnly || + encodeSet.indexOf(codePoint.toChar()) != -1 || + codePoint == '%'.toInt() && (!alreadyEncoded || strict && !percentEncoded(input, i, + limit)) || + codePoint == '+'.toInt() && plusIsSpace) { // Slow path: the character at i requires encoding! val out = Buffer() out.writeUtf8(input, pos, i) @@ -1674,8 +1682,15 @@ class HttpUrl internal constructor(builder: Builder) { @JvmStatic internal fun canonicalize( - out: Buffer, input: String, pos: Int, limit: Int, encodeSet: String, - alreadyEncoded: Boolean, strict: Boolean, plusIsSpace: Boolean, asciiOnly: Boolean, + out: Buffer, + input: String, + pos: Int, + limit: Int, + encodeSet: String, + alreadyEncoded: Boolean, + strict: Boolean, + plusIsSpace: Boolean, + asciiOnly: Boolean, charset: Charset? ) { var encodedCharBuffer: Buffer? = null // Lazily allocated. @@ -1688,11 +1703,11 @@ class HttpUrl internal constructor(builder: Builder) { } else if (codePoint == '+'.toInt() && plusIsSpace) { // Encode '+' as '%2B' since we permit ' ' to be encoded as either '+' or '%20'. out.writeUtf8(if (alreadyEncoded) "+" else "%2B") - } else if (codePoint < 0x20 - || codePoint == 0x7f - || codePoint >= 0x80 && asciiOnly - || encodeSet.indexOf(codePoint.toChar()) != -1 - || codePoint == '%'.toInt() && (!alreadyEncoded || strict && !percentEncoded(input, i, + } else if (codePoint < 0x20 || + codePoint == 0x7f || + codePoint >= 0x80 && asciiOnly || + encodeSet.indexOf(codePoint.toChar()) != -1 || + codePoint == '%'.toInt() && (!alreadyEncoded || strict && !percentEncoded(input, i, limit))) { // Percent encode this character. if (encodedCharBuffer == null) { @@ -1721,15 +1736,24 @@ class HttpUrl internal constructor(builder: Builder) { @JvmStatic internal fun canonicalize( - input: String, encodeSet: String, alreadyEncoded: Boolean, strict: Boolean, - plusIsSpace: Boolean, asciiOnly: Boolean, charset: Charset? + input: String, + encodeSet: String, + alreadyEncoded: Boolean, + strict: Boolean, + plusIsSpace: Boolean, + asciiOnly: Boolean, + charset: Charset? ): String = canonicalize(input, 0, input.length, encodeSet, alreadyEncoded, strict, plusIsSpace, asciiOnly, charset) @JvmStatic internal fun canonicalize( - input: String, encodeSet: String, alreadyEncoded: Boolean, strict: Boolean, - plusIsSpace: Boolean, asciiOnly: Boolean + input: String, + encodeSet: String, + alreadyEncoded: Boolean, + strict: Boolean, + plusIsSpace: Boolean, + asciiOnly: Boolean ): String = canonicalize( input, 0, input.length, encodeSet, alreadyEncoded, strict, plusIsSpace, asciiOnly, null) } diff --git a/okhttp/src/main/java/okhttp3/Interceptor.kt b/okhttp/src/main/java/okhttp3/Interceptor.kt index f8c723cfc..43739a90b 100644 --- a/okhttp/src/main/java/okhttp3/Interceptor.kt +++ b/okhttp/src/main/java/okhttp3/Interceptor.kt @@ -32,7 +32,7 @@ interface Interceptor { @JvmName("-deprecated_Interceptor") inline operator fun invoke( crossinline block: (chain: Chain) -> Response - ): Interceptor = object: Interceptor { + ): Interceptor = object : Interceptor { override fun intercept(chain: Chain) = block(chain) } } diff --git a/okhttp/src/main/java/okhttp3/MultipartBody.kt b/okhttp/src/main/java/okhttp3/MultipartBody.kt index c0eb795f5..9ff3cfbe9 100644 --- a/okhttp/src/main/java/okhttp3/MultipartBody.kt +++ b/okhttp/src/main/java/okhttp3/MultipartBody.kt @@ -74,7 +74,8 @@ class MultipartBody internal constructor( */ @Throws(IOException::class) private fun writeOrCountBytes( - sink: BufferedSink?, countBytes: Boolean + sink: BufferedSink?, + countBytes: Boolean ): Long { var sink = sink var byteCount = 0L diff --git a/okhttp/src/main/java/okhttp3/OkHttpClient.kt b/okhttp/src/main/java/okhttp3/OkHttpClient.kt index e1eef75ea..c927a47fd 100644 --- a/okhttp/src/main/java/okhttp3/OkHttpClient.kt +++ b/okhttp/src/main/java/okhttp3/OkHttpClient.kt @@ -586,7 +586,8 @@ open class OkHttpClient internal constructor( * ``` */ fun sslSocketFactory( - sslSocketFactory: SSLSocketFactory, trustManager: X509TrustManager + sslSocketFactory: SSLSocketFactory, + trustManager: X509TrustManager ) = apply { this.sslSocketFactory = sslSocketFactory this.certificateChainCleaner = CertificateChainCleaner.get(trustManager) diff --git a/okhttp/src/main/java/okhttp3/RealCall.kt b/okhttp/src/main/java/okhttp3/RealCall.kt index 1775b38c7..7950927a6 100644 --- a/okhttp/src/main/java/okhttp3/RealCall.kt +++ b/okhttp/src/main/java/okhttp3/RealCall.kt @@ -154,9 +154,9 @@ internal class RealCall private constructor( * sensitive information. */ fun toLoggableString(): String { - return ((if (isCanceled()) "canceled " else "") - + (if (forWebSocket) "web socket" else "call") - + " to " + redactedUrl()) + return ((if (isCanceled()) "canceled " else "") + + (if (forWebSocket) "web socket" else "call") + + " to " + redactedUrl()) } fun redactedUrl(): String = originalRequest.url().redact() diff --git a/okhttp/src/main/java/okhttp3/Response.kt b/okhttp/src/main/java/okhttp3/Response.kt index 4844a8707..710e82fd0 100644 --- a/okhttp/src/main/java/okhttp3/Response.kt +++ b/okhttp/src/main/java/okhttp3/Response.kt @@ -90,7 +90,7 @@ class Response internal constructor( */ fun handshake(): Handshake? = handshake - fun headers(name: String): List = headers.values(name) + fun headers(name: String): List = headers.values(name) @JvmOverloads fun header(name: String, defaultValue: String? = null): String? = headers[name] ?: defaultValue diff --git a/okhttp/src/main/java/okhttp3/TlsVersion.kt b/okhttp/src/main/java/okhttp3/TlsVersion.kt index 6213a4feb..7f583cec6 100644 --- a/okhttp/src/main/java/okhttp3/TlsVersion.kt +++ b/okhttp/src/main/java/okhttp3/TlsVersion.kt @@ -23,8 +23,8 @@ enum class TlsVersion(private val javaName: String) { TLS_1_3("TLSv1.3"), // 2016. TLS_1_2("TLSv1.2"), // 2008. TLS_1_1("TLSv1.1"), // 2006. - TLS_1_0("TLSv1"), // 1999. - SSL_3_0("SSLv3"); // 1996. + TLS_1_0("TLSv1"), // 1999. + SSL_3_0("SSLv3"); // 1996. fun javaName() = javaName diff --git a/okhttp/src/main/java/okhttp3/internal/cache/FaultHidingSink.kt b/okhttp/src/main/java/okhttp3/internal/cache/FaultHidingSink.kt index fdd75cc24..3e9ae8144 100644 --- a/okhttp/src/main/java/okhttp3/internal/cache/FaultHidingSink.kt +++ b/okhttp/src/main/java/okhttp3/internal/cache/FaultHidingSink.kt @@ -21,7 +21,7 @@ import okio.Sink import java.io.IOException /** A sink that never throws IOExceptions, even if the underlying sink does. */ -internal open class FaultHidingSink(delegate: Sink): ForwardingSink(delegate) { +internal open class FaultHidingSink(delegate: Sink) : ForwardingSink(delegate) { private var hasErrors = false override fun write(source: Buffer, byteCount: Long) { diff --git a/okhttp/src/main/java/okhttp3/internal/connection/RouteException.kt b/okhttp/src/main/java/okhttp3/internal/connection/RouteException.kt index 7859d8bd2..d10c76c5a 100644 --- a/okhttp/src/main/java/okhttp3/internal/connection/RouteException.kt +++ b/okhttp/src/main/java/okhttp3/internal/connection/RouteException.kt @@ -15,7 +15,7 @@ */ package okhttp3.internal.connection -import java.io.IOException; +import java.io.IOException /** * An exception thrown to indicate a problem connecting via a single Route. Multiple attempts may diff --git a/okhttp/src/main/java/okhttp3/internal/http/HttpMethod.kt b/okhttp/src/main/java/okhttp3/internal/http/HttpMethod.kt index 2e62a0cd4..b4516822f 100644 --- a/okhttp/src/main/java/okhttp3/internal/http/HttpMethod.kt +++ b/okhttp/src/main/java/okhttp3/internal/http/HttpMethod.kt @@ -17,18 +17,18 @@ package okhttp3.internal.http object HttpMethod { @JvmStatic - fun invalidatesCache(method: String): Boolean = (method == "POST" - || method == "PATCH" - || method == "PUT" - || method == "DELETE" - || method == "MOVE") // WebDAV + fun invalidatesCache(method: String): Boolean = (method == "POST" || + method == "PATCH" || + method == "PUT" || + method == "DELETE" || + method == "MOVE") // WebDAV @JvmStatic - fun requiresRequestBody(method: String): Boolean = (method == "POST" - || method == "PUT" - || method == "PATCH" - || method == "PROPPATCH" // WebDAV - || method == "REPORT") // CalDAV/CardDAV (defined in WebDAV Versioning) + fun requiresRequestBody(method: String): Boolean = (method == "POST" || + method == "PUT" || + method == "PATCH" || + method == "PROPPATCH" || // WebDAV + method == "REPORT") // CalDAV/CardDAV (defined in WebDAV Versioning) @JvmStatic fun permitsRequestBody(method: String): Boolean = !(method == "GET" || method == "HEAD") diff --git a/okhttp/src/main/java/okhttp3/internal/http/RealInterceptorChain.kt b/okhttp/src/main/java/okhttp3/internal/http/RealInterceptorChain.kt index 81a82dcde..825da5858 100644 --- a/okhttp/src/main/java/okhttp3/internal/http/RealInterceptorChain.kt +++ b/okhttp/src/main/java/okhttp3/internal/http/RealInterceptorChain.kt @@ -43,7 +43,7 @@ class RealInterceptorChain( private val connectTimeout: Int, private val readTimeout: Int, private val writeTimeout: Int -): Interceptor.Chain { +) : Interceptor.Chain { private var calls: Int = 0 @@ -98,14 +98,14 @@ class RealInterceptorChain( // If we already have a stream, confirm that the incoming request will use it. if (this.exchange != null && !this.exchange.connection().supportsUrl(request.url())) { - throw IllegalStateException("network interceptor " + interceptors[index - 1] - + " must retain the same host and port") + throw IllegalStateException("network interceptor " + interceptors[index - 1] + + " must retain the same host and port") } // If we already have a stream, confirm that this is the only call to chain.proceed(). if (this.exchange != null && calls > 1) { - throw IllegalStateException("network interceptor " + interceptors[index - 1] - + " must call proceed() exactly once") + throw IllegalStateException("network interceptor " + interceptors[index - 1] + + " must call proceed() exactly once") } // Call the next interceptor in the chain. @@ -116,8 +116,8 @@ class RealInterceptorChain( // Confirm that the next interceptor made its required call to chain.proceed(). if (exchange != null && index + 1 < interceptors.size && next.calls != 1) { - throw IllegalStateException("network interceptor " + interceptor - + " must call proceed() exactly once") + throw IllegalStateException("network interceptor " + interceptor + + " must call proceed() exactly once") } // Confirm that the intercepted response isn't null. diff --git a/okhttp/src/main/java/okhttp3/internal/platform/AndroidPlatform.kt b/okhttp/src/main/java/okhttp3/internal/platform/AndroidPlatform.kt index 2a0faad82..789822797 100644 --- a/okhttp/src/main/java/okhttp3/internal/platform/AndroidPlatform.kt +++ b/okhttp/src/main/java/okhttp3/internal/platform/AndroidPlatform.kt @@ -75,7 +75,8 @@ class AndroidPlatform( @Throws(IOException::class) override fun connectSocket( - socket: Socket, address: InetSocketAddress, + socket: Socket, + address: InetSocketAddress, connectTimeout: Int ) { try { @@ -118,10 +119,12 @@ class AndroidPlatform( } override fun configureTlsExtensions( - sslSocket: SSLSocket, hostname: String?, protocols: List + sslSocket: SSLSocket, + hostname: String?, + protocols: List ) { if (!sslSocketClass.isInstance(sslSocket)) { - return // No TLS extensions if the socket class is custom. + return // No TLS extensions if the socket class is custom. } try { // Enable SNI and session tickets. @@ -206,7 +209,8 @@ class AndroidPlatform( @Throws(InvocationTargetException::class, IllegalAccessException::class) private fun api24IsCleartextTrafficPermitted( - hostname: String, networkPolicyClass: Class<*>, + hostname: String, + networkPolicyClass: Class<*>, networkSecurityPolicy: Any ): Boolean = try { val isCleartextTrafficPermittedMethod = networkPolicyClass @@ -218,7 +222,8 @@ class AndroidPlatform( @Throws(InvocationTargetException::class, IllegalAccessException::class) private fun api23IsCleartextTrafficPermitted( - hostname: String, networkPolicyClass: Class<*>, + hostname: String, + networkPolicyClass: Class<*>, networkSecurityPolicy: Any ): Boolean = try { val isCleartextTrafficPermittedMethod = networkPolicyClass @@ -264,7 +269,7 @@ class AndroidPlatform( @Suppress("UNCHECKED_CAST") @Throws(SSLPeerUnverifiedException::class) - override// Reflection on List. + override // Reflection on List. fun clean(chain: List, hostname: String): List = try { val certificates = (chain as List).toTypedArray() checkServerTrusted.invoke( diff --git a/okhttp/src/main/java/okhttp3/internal/platform/ConscryptPlatform.kt b/okhttp/src/main/java/okhttp3/internal/platform/ConscryptPlatform.kt index 3bf3168fd..6442c90d4 100644 --- a/okhttp/src/main/java/okhttp3/internal/platform/ConscryptPlatform.kt +++ b/okhttp/src/main/java/okhttp3/internal/platform/ConscryptPlatform.kt @@ -66,7 +66,9 @@ class ConscryptPlatform private constructor() : Platform() { } override fun configureTlsExtensions( - sslSocket: SSLSocket, hostname: String?, protocols: List + sslSocket: SSLSocket, + hostname: String?, + protocols: List ) { if (Conscrypt.isConscrypt(sslSocket)) { // Enable SNI and session tickets. diff --git a/okhttp/src/main/java/okhttp3/internal/platform/Jdk8WithJettyBootPlatform.kt b/okhttp/src/main/java/okhttp3/internal/platform/Jdk8WithJettyBootPlatform.kt index b425d9b2c..249f8b80d 100644 --- a/okhttp/src/main/java/okhttp3/internal/platform/Jdk8WithJettyBootPlatform.kt +++ b/okhttp/src/main/java/okhttp3/internal/platform/Jdk8WithJettyBootPlatform.kt @@ -24,11 +24,16 @@ import javax.net.ssl.SSLSocket /** OpenJDK 8 with `org.mortbay.jetty.alpn:alpn-boot` in the boot class path. */ class Jdk8WithJettyBootPlatform( - private val putMethod: Method, private val getMethod: Method, private val removeMethod: Method, - private val clientProviderClass: Class<*>, private val serverProviderClass: Class<*> + private val putMethod: Method, + private val getMethod: Method, + private val removeMethod: Method, + private val clientProviderClass: Class<*>, + private val serverProviderClass: Class<*> ) : Platform() { override fun configureTlsExtensions( - sslSocket: SSLSocket, hostname: String?, protocols: List + sslSocket: SSLSocket, + hostname: String?, + protocols: List ) { val names = alpnProtocolNames(protocols) @@ -51,7 +56,6 @@ class Jdk8WithJettyBootPlatform( } catch (e: InvocationTargetException) { throw AssertionError("failed to remove ALPN", e) } - } override fun getSelectedProtocol(socket: SSLSocket): String? { @@ -96,8 +100,8 @@ class Jdk8WithJettyBootPlatform( return null } else if (methodName == "protocols" && callArgs.isEmpty()) { return protocols // Client advertises these protocols. - } else if ((methodName == "selectProtocol" || methodName == "select") - && String::class.java == returnType && callArgs.size == 1 && callArgs[0] is List<*>) { + } else if ((methodName == "selectProtocol" || methodName == "select") && + String::class.java == returnType && callArgs.size == 1 && callArgs[0] is List<*>) { val peerProtocols = callArgs[0] as List<*> // Pick the first known protocol the peer advertises. for (i in 0..peerProtocols.size) { diff --git a/okhttp/src/main/java/okhttp3/internal/platform/Jdk9Platform.kt b/okhttp/src/main/java/okhttp3/internal/platform/Jdk9Platform.kt index 7d42f627b..7305b90fb 100644 --- a/okhttp/src/main/java/okhttp3/internal/platform/Jdk9Platform.kt +++ b/okhttp/src/main/java/okhttp3/internal/platform/Jdk9Platform.kt @@ -29,7 +29,8 @@ class Jdk9Platform( @JvmField val getProtocolMethod: Method ) : Platform() { override fun configureTlsExtensions( - sslSocket: SSLSocket, hostname: String?, + sslSocket: SSLSocket, + hostname: String?, protocols: List ) { try { diff --git a/okhttp/src/main/java/okhttp3/internal/platform/Platform.kt b/okhttp/src/main/java/okhttp3/internal/platform/Platform.kt index 785d972af..2cfb99d9d 100644 --- a/okhttp/src/main/java/okhttp3/internal/platform/Platform.kt +++ b/okhttp/src/main/java/okhttp3/internal/platform/Platform.kt @@ -176,7 +176,7 @@ open class Platform { override fun toString(): String = javaClass.simpleName companion object { - private @Volatile var platform = findPlatform() + @Volatile private var platform = findPlatform() const val INFO = 4 const val WARN = 5 diff --git a/okhttp/src/main/java/okhttp3/internal/tls/BasicCertificateChainCleaner.kt b/okhttp/src/main/java/okhttp3/internal/tls/BasicCertificateChainCleaner.kt index b89d7ff37..3ebe3551f 100644 --- a/okhttp/src/main/java/okhttp3/internal/tls/BasicCertificateChainCleaner.kt +++ b/okhttp/src/main/java/okhttp3/internal/tls/BasicCertificateChainCleaner.kt @@ -33,7 +33,7 @@ import javax.net.ssl.SSLPeerUnverifiedException */ class BasicCertificateChainCleaner( private val trustRootIndex: TrustRootIndex -): CertificateChainCleaner() { +) : CertificateChainCleaner() { /** * Returns a cleaned chain for [chain].