mirror of
https://github.com/square/okhttp.git
synced 2025-07-31 05:04:26 +03:00
Spotless code formatter
This commit is contained in:
10
build.gradle
10
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
|
||||
|
||||
@ -105,6 +108,13 @@ subprojects { project ->
|
||||
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")
|
||||
|
||||
test {
|
||||
|
@ -111,8 +111,11 @@ class DnsOverHttps internal constructor(builder: Builder) : Dns {
|
||||
}
|
||||
|
||||
private fun buildRequest(
|
||||
hostname: String, networkRequests: MutableList<Call>, results: MutableList<InetAddress>,
|
||||
failures: MutableList<Exception>, type: Int
|
||||
hostname: String,
|
||||
networkRequests: MutableList<Call>,
|
||||
results: MutableList<InetAddress>,
|
||||
failures: MutableList<Exception>,
|
||||
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<Call>,
|
||||
responses: MutableList<InetAddress>, failures: MutableList<Exception>
|
||||
hostname: String,
|
||||
networkRequests: List<Call>,
|
||||
responses: MutableList<InetAddress>,
|
||||
failures: MutableList<Exception>
|
||||
) {
|
||||
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<InetAddress>,
|
||||
response: Response,
|
||||
hostname: String,
|
||||
results: MutableList<InetAddress>,
|
||||
failures: MutableList<Exception>
|
||||
) {
|
||||
try {
|
||||
@ -244,7 +251,6 @@ class DnsOverHttps internal constructor(builder: Builder) : Dns {
|
||||
|
||||
url(requestUrl)
|
||||
}
|
||||
|
||||
}.build()
|
||||
|
||||
class Builder {
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -53,8 +53,8 @@ class JavaNetCookieJar(private val cookieHandler: CookieHandler) : CookieJar {
|
||||
|
||||
var cookies: MutableList<Cookie>? = 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))
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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,7 +1297,10 @@ 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(
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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.
|
||||
|
@ -75,7 +75,8 @@ class AndroidPlatform(
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun connectSocket(
|
||||
socket: Socket, address: InetSocketAddress,
|
||||
socket: Socket,
|
||||
address: InetSocketAddress,
|
||||
connectTimeout: Int
|
||||
) {
|
||||
try {
|
||||
@ -118,7 +119,9 @@ class AndroidPlatform(
|
||||
}
|
||||
|
||||
override fun configureTlsExtensions(
|
||||
sslSocket: SSLSocket, hostname: String?, protocols: List<Protocol>
|
||||
sslSocket: SSLSocket,
|
||||
hostname: String?,
|
||||
protocols: List<Protocol>
|
||||
) {
|
||||
if (!sslSocketClass.isInstance(sslSocket)) {
|
||||
return // No TLS extensions if the socket class is custom.
|
||||
@ -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
|
||||
|
@ -66,7 +66,9 @@ class ConscryptPlatform private constructor() : Platform() {
|
||||
}
|
||||
|
||||
override fun configureTlsExtensions(
|
||||
sslSocket: SSLSocket, hostname: String?, protocols: List<Protocol>
|
||||
sslSocket: SSLSocket,
|
||||
hostname: String?,
|
||||
protocols: List<Protocol>
|
||||
) {
|
||||
if (Conscrypt.isConscrypt(sslSocket)) {
|
||||
// Enable SNI and session tickets.
|
||||
|
@ -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<Protocol>
|
||||
sslSocket: SSLSocket,
|
||||
hostname: String?,
|
||||
protocols: List<Protocol>
|
||||
) {
|
||||
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) {
|
||||
|
@ -29,7 +29,8 @@ class Jdk9Platform(
|
||||
@JvmField val getProtocolMethod: Method
|
||||
) : Platform() {
|
||||
override fun configureTlsExtensions(
|
||||
sslSocket: SSLSocket, hostname: String?,
|
||||
sslSocket: SSLSocket,
|
||||
hostname: String?,
|
||||
protocols: List<Protocol>
|
||||
) {
|
||||
try {
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user