1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-12 10:23:16 +03:00

Declare types & Cleanup (#6842)

* Declare types

* Code cleanup

* Declare types
This commit is contained in:
Goooler
2021-08-31 11:32:43 +08:00
committed by GitHub
parent 98fae58d03
commit e1af67f082
45 changed files with 153 additions and 152 deletions

View File

@@ -45,16 +45,16 @@ class MockResponse : Cloneable {
private var body: Buffer? = null
var throttleBytesPerPeriod = Long.MAX_VALUE
var throttleBytesPerPeriod: Long = Long.MAX_VALUE
private set
private var throttlePeriodAmount = 1L
private var throttlePeriodUnit = TimeUnit.SECONDS
@set:JvmName("socketPolicy")
var socketPolicy = SocketPolicy.KEEP_OPEN
var socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN
@set:JvmName("http2ErrorCode")
var http2ErrorCode = -1
var http2ErrorCode: Int = -1
private var bodyDelayAmount = 0L
private var bodyDelayUnit = TimeUnit.MILLISECONDS
@@ -182,7 +182,7 @@ class MockResponse : Cloneable {
message = "moved to var",
replaceWith = ReplaceWith(expression = "socketPolicy"),
level = DeprecationLevel.ERROR)
fun getSocketPolicy() = socketPolicy
fun getSocketPolicy(): SocketPolicy = socketPolicy
fun setSocketPolicy(socketPolicy: SocketPolicy) = apply {
this.socketPolicy = socketPolicy
@@ -193,7 +193,7 @@ class MockResponse : Cloneable {
message = "moved to var",
replaceWith = ReplaceWith(expression = "http2ErrorCode"),
level = DeprecationLevel.ERROR)
fun getHttp2ErrorCode() = http2ErrorCode
fun getHttp2ErrorCode(): Int = http2ErrorCode
fun setHttp2ErrorCode(http2ErrorCode: Int) = apply {
this.http2ErrorCode = http2ErrorCode
@@ -240,7 +240,7 @@ class MockResponse : Cloneable {
webSocketListener = listener
}
override fun toString() = status
override fun toString(): String = status
companion object {
private const val CHUNKED_BODY_HEADER = "Transfer-encoding: chunked"

View File

@@ -29,26 +29,26 @@ class PushPromise(
message = "moved to val",
replaceWith = ReplaceWith(expression = "method"),
level = DeprecationLevel.ERROR)
fun method() = method
fun method(): String = method
@JvmName("-deprecated_path")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "path"),
level = DeprecationLevel.ERROR)
fun path() = path
fun path(): String = path
@JvmName("-deprecated_headers")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "headers"),
level = DeprecationLevel.ERROR)
fun headers() = headers
fun headers(): Headers = headers
@JvmName("-deprecated_response")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "response"),
level = DeprecationLevel.ERROR)
fun response() = response
fun response(): MockResponse = response
}

View File

@@ -49,13 +49,13 @@ class MockResponse : Cloneable {
private var body: Buffer? = null
var throttleBytesPerPeriod = Long.MAX_VALUE
var throttleBytesPerPeriod: Long = Long.MAX_VALUE
private set
private var throttlePeriodAmount = 1L
private var throttlePeriodUnit = TimeUnit.SECONDS
@set:JvmName("socketPolicy")
var socketPolicy = SocketPolicy.KEEP_OPEN
var socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN
/**
* Sets the [HTTP/2 error code](https://tools.ietf.org/html/rfc7540#section-7) to be
@@ -64,7 +64,7 @@ class MockResponse : Cloneable {
* [SocketPolicy.DO_NOT_READ_REQUEST_BODY].
*/
@set:JvmName("http2ErrorCode")
var http2ErrorCode = -1
var http2ErrorCode: Int = -1
private var bodyDelayAmount = 0L
private var bodyDelayUnit = TimeUnit.MILLISECONDS
@@ -253,7 +253,7 @@ class MockResponse : Cloneable {
message = "moved to var",
replaceWith = ReplaceWith(expression = "socketPolicy"),
level = DeprecationLevel.ERROR)
fun getSocketPolicy() = socketPolicy
fun getSocketPolicy(): SocketPolicy = socketPolicy
/**
* Sets the socket policy and returns this.
@@ -271,7 +271,7 @@ class MockResponse : Cloneable {
message = "moved to var",
replaceWith = ReplaceWith(expression = "http2ErrorCode"),
level = DeprecationLevel.ERROR)
fun getHttp2ErrorCode() = http2ErrorCode
fun getHttp2ErrorCode(): Int = http2ErrorCode
/**
* Sets the HTTP/2 error code and returns this.
@@ -345,7 +345,7 @@ class MockResponse : Cloneable {
webSocketListener = listener
}
override fun toString() = status
override fun toString(): String = status
companion object {
private const val CHUNKED_BODY_HEADER = "Transfer-encoding: chunked"

View File

@@ -117,7 +117,7 @@ class MockWebServer : Closeable {
get() = atomicRequestCount.get()
/** The number of bytes of the POST body to keep in memory to the given limit. */
var bodyLimit = Long.MAX_VALUE
var bodyLimit: Long = Long.MAX_VALUE
var serverSocketFactory: ServerSocketFactory? = null
@Synchronized get() {
@@ -165,7 +165,7 @@ class MockWebServer : Closeable {
* HTTP/2. This is true by default; set to false to disable negotiation and restrict connections
* to HTTP/1.1.
*/
var protocolNegotiationEnabled = true
var protocolNegotiationEnabled: Boolean = true
/**
* The protocols supported by ALPN on incoming HTTPS connections in order of preference. The list

View File

@@ -30,26 +30,26 @@ class PushPromise(
message = "moved to val",
replaceWith = ReplaceWith(expression = "method"),
level = DeprecationLevel.ERROR)
fun method() = method
fun method(): String = method
@JvmName("-deprecated_path")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "path"),
level = DeprecationLevel.ERROR)
fun path() = path
fun path(): String = path
@JvmName("-deprecated_headers")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "headers"),
level = DeprecationLevel.ERROR)
fun headers() = headers
fun headers(): Headers = headers
@JvmName("-deprecated_response")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "response"),
level = DeprecationLevel.ERROR)
fun response() = response
fun response(): MockResponse = response
}

View File

@@ -291,7 +291,7 @@ class Main : Runnable {
override fun format(record: LogRecord): String {
val parameters = record.parameters
return if (parameters != null) {
format("%s%n%s%n", record.message, record.parameters.first())
format("%s%n%s%n", record.message, parameters.first())
} else {
format("%s%n", record.message)
}

View File

@@ -58,7 +58,7 @@ sealed class CallEvent {
val domainName: String,
val inetAddressList: List<InetAddress>
) : CallEvent() {
override fun closes(timestampNs: Long) = DnsStart(timestampNs, call, domainName)
override fun closes(timestampNs: Long): CallEvent = DnsStart(timestampNs, call, domainName)
}
data class ConnectStart(
@@ -75,7 +75,7 @@ sealed class CallEvent {
val proxy: Proxy?,
val protocol: Protocol?
) : CallEvent() {
override fun closes(timestampNs: Long) =
override fun closes(timestampNs: Long): CallEvent =
ConnectStart(timestampNs, call, inetSocketAddress, proxy)
}
@@ -87,7 +87,7 @@ sealed class CallEvent {
val protocol: Protocol?,
val ioe: IOException
) : CallEvent() {
override fun closes(timestampNs: Long) =
override fun closes(timestampNs: Long): CallEvent =
ConnectStart(timestampNs, call, inetSocketAddress, proxy)
}
@@ -101,7 +101,7 @@ sealed class CallEvent {
override val call: Call,
val handshake: Handshake?
) : CallEvent() {
override fun closes(timestampNs: Long) = SecureConnectStart(timestampNs, call)
override fun closes(timestampNs: Long): CallEvent = SecureConnectStart(timestampNs, call)
}
data class ConnectionAcquired(
@@ -115,7 +115,7 @@ sealed class CallEvent {
override val call: Call,
val connection: Connection
) : CallEvent() {
override fun closes(timestampNs: Long) = ConnectionAcquired(timestampNs, call, connection)
override fun closes(timestampNs: Long): CallEvent = ConnectionAcquired(timestampNs, call, connection)
}
data class CallStart(
@@ -127,7 +127,7 @@ sealed class CallEvent {
override val timestampNs: Long,
override val call: Call
) : CallEvent() {
override fun closes(timestampNs: Long) = CallStart(timestampNs, call)
override fun closes(timestampNs: Long): CallEvent = CallStart(timestampNs, call)
}
data class CallFailed(
@@ -151,7 +151,7 @@ sealed class CallEvent {
override val call: Call,
val headerLength: Long
) : CallEvent() {
override fun closes(timestampNs: Long) = RequestHeadersStart(timestampNs, call)
override fun closes(timestampNs: Long): CallEvent = RequestHeadersStart(timestampNs, call)
}
data class RequestBodyStart(
@@ -164,7 +164,7 @@ sealed class CallEvent {
override val call: Call,
val bytesWritten: Long
) : CallEvent() {
override fun closes(timestampNs: Long) = RequestBodyStart(timestampNs, call)
override fun closes(timestampNs: Long): CallEvent = RequestBodyStart(timestampNs, call)
}
data class RequestFailed(
@@ -183,7 +183,7 @@ sealed class CallEvent {
override val call: Call,
val headerLength: Long
) : CallEvent() {
override fun closes(timestampNs: Long) = RequestHeadersStart(timestampNs, call)
override fun closes(timestampNs: Long): CallEvent = RequestHeadersStart(timestampNs, call)
}
data class ResponseBodyStart(
@@ -196,7 +196,7 @@ sealed class CallEvent {
override val call: Call,
val bytesRead: Long
) : CallEvent() {
override fun closes(timestampNs: Long) = ResponseBodyStart(timestampNs, call)
override fun closes(timestampNs: Long): CallEvent = ResponseBodyStart(timestampNs, call)
}
data class ResponseFailed(

View File

@@ -15,7 +15,6 @@
*/
package okhttp3
import java.net.InetAddress
import java.util.concurrent.TimeUnit
import java.util.logging.Handler
import java.util.logging.Level

View File

@@ -33,7 +33,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 1L,
codec = object : BasicDerAdapter.Codec<Boolean> {
override fun decode(reader: DerReader) = reader.readBoolean()
override fun decode(reader: DerReader): Boolean = reader.readBoolean()
override fun encode(writer: DerWriter, value: Boolean) = writer.writeBoolean(value)
}
)
@@ -43,7 +43,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 2L,
codec = object : BasicDerAdapter.Codec<Long> {
override fun decode(reader: DerReader) = reader.readLong()
override fun decode(reader: DerReader): Long = reader.readLong()
override fun encode(writer: DerWriter, value: Long) = writer.writeLong(value)
}
)
@@ -53,7 +53,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 2L,
codec = object : BasicDerAdapter.Codec<BigInteger> {
override fun decode(reader: DerReader) = reader.readBigInteger()
override fun decode(reader: DerReader): BigInteger = reader.readBigInteger()
override fun encode(writer: DerWriter, value: BigInteger) = writer.writeBigInteger(value)
}
)
@@ -63,7 +63,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 3L,
codec = object : BasicDerAdapter.Codec<BitString> {
override fun decode(reader: DerReader) = reader.readBitString()
override fun decode(reader: DerReader): BitString = reader.readBitString()
override fun encode(writer: DerWriter, value: BitString) = writer.writeBitString(value)
}
)
@@ -73,7 +73,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 4L,
codec = object : BasicDerAdapter.Codec<ByteString> {
override fun decode(reader: DerReader) = reader.readOctetString()
override fun decode(reader: DerReader): ByteString = reader.readOctetString()
override fun encode(writer: DerWriter, value: ByteString) = writer.writeOctetString(value)
}
)
@@ -94,7 +94,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 6L,
codec = object : BasicDerAdapter.Codec<String> {
override fun decode(reader: DerReader) = reader.readObjectIdentifier()
override fun decode(reader: DerReader): String = reader.readObjectIdentifier()
override fun encode(writer: DerWriter, value: String) = writer.writeObjectIdentifier(value)
}
)
@@ -104,7 +104,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 12L,
codec = object : BasicDerAdapter.Codec<String> {
override fun decode(reader: DerReader) = reader.readUtf8String()
override fun decode(reader: DerReader): String = reader.readUtf8String()
override fun encode(writer: DerWriter, value: String) = writer.writeUtf8(value)
}
)
@@ -122,7 +122,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 19L,
codec = object : BasicDerAdapter.Codec<String> {
override fun decode(reader: DerReader) = reader.readUtf8String()
override fun decode(reader: DerReader): String = reader.readUtf8String()
override fun encode(writer: DerWriter, value: String) = writer.writeUtf8(value)
}
)
@@ -137,7 +137,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 22L,
codec = object : BasicDerAdapter.Codec<String> {
override fun decode(reader: DerReader) = reader.readUtf8String()
override fun decode(reader: DerReader): String = reader.readUtf8String()
override fun encode(writer: DerWriter, value: String) = writer.writeUtf8(value)
}
)
@@ -209,7 +209,7 @@ internal object Adapters {
/** Decodes any value without interpretation as [AnyValue]. */
val ANY_VALUE = object : DerAdapter<AnyValue> {
override fun matches(header: DerHeader) = true
override fun matches(header: DerHeader): Boolean = true
override fun fromDer(reader: DerReader): AnyValue {
reader.read("ANY") { header ->
@@ -329,7 +329,7 @@ internal object Adapters {
(adapter as DerAdapter<Any?>).toDer(writer, v)
}
override fun toString() = choices.joinToString(separator = " OR ")
override fun toString(): String = choices.joinToString(separator = " OR ")
}
}
@@ -346,7 +346,7 @@ internal object Adapters {
chooser: (Any?) -> DerAdapter<*>?
): DerAdapter<Any?> {
return object : DerAdapter<Any?> {
override fun matches(header: DerHeader) = true
override fun matches(header: DerHeader): Boolean = true
override fun toDer(writer: DerWriter, value: Any?) {
// If we don't understand this hint, encode the body as a byte string. The byte string

View File

@@ -50,7 +50,7 @@ internal data class BasicDerAdapter<T>(
require(tag >= 0)
}
override fun matches(header: DerHeader) = header.tagClass == tagClass && header.tag == tag
override fun matches(header: DerHeader): Boolean = header.tagClass == tagClass && header.tag == tag
override fun fromDer(reader: DerReader): T {
val peekedHeader = reader.peekHeader()
@@ -109,16 +109,16 @@ internal data class BasicDerAdapter<T>(
fun withTag(
tagClass: Int = DerHeader.TAG_CLASS_CONTEXT_SPECIFIC,
tag: Long
) = copy(tagClass = tagClass, tag = tag)
): BasicDerAdapter<T> = copy(tagClass = tagClass, tag = tag)
/** Returns a copy of this adapter that doesn't encode values equal to [defaultValue]. */
fun optional(defaultValue: T? = null) = copy(isOptional = true, defaultValue = defaultValue)
fun optional(defaultValue: T? = null): BasicDerAdapter<T> = copy(isOptional = true, defaultValue = defaultValue)
/**
* Returns a copy of this adapter that sets the encoded or decoded value as the type hint for the
* other adapters on this SEQUENCE to interrogate.
*/
fun asTypeHint() = copy(typeHint = true)
fun asTypeHint(): BasicDerAdapter<T> = copy(typeHint = true)
// Avoid Long.hashCode(long) which isn't available on Android 5.
override fun hashCode(): Int {
@@ -133,7 +133,7 @@ internal data class BasicDerAdapter<T>(
return result
}
override fun toString() = "$name [$tagClass/$tag]"
override fun toString(): String = "$name [$tagClass/$tag]"
/** Reads and writes values without knowledge of the enclosing tag, length, or defaults. */
interface Codec<T> {

View File

@@ -80,7 +80,7 @@ internal interface DerAdapter<T> {
forceConstructed: Boolean? = null
): BasicDerAdapter<T> {
val codec = object : BasicDerAdapter.Codec<T> {
override fun decode(reader: DerReader) = fromDer(reader)
override fun decode(reader: DerReader): T = fromDer(reader)
override fun encode(writer: DerWriter, value: T) {
toDer(writer, value)
if (forceConstructed != null) {

View File

@@ -65,7 +65,7 @@ internal data class DerHeader(
return result
}
override fun toString() = "$tagClass/$tag"
override fun toString(): String = "$tagClass/$tag"
companion object {
const val TAG_CLASS_UNIVERSAL = 0b0000_0000

View File

@@ -311,7 +311,7 @@ internal class DerReader(source: Source) {
return source.readByteString(bytesLeft)
}
override fun toString() = path.joinToString(separator = " / ")
override fun toString(): String = path.joinToString(separator = " / ")
companion object {
/**

View File

@@ -182,5 +182,5 @@ internal class DerWriter(sink: BufferedSink) {
}
}
override fun toString() = path.joinToString(separator = " / ")
override fun toString(): String = path.joinToString(separator = " / ")
}

View File

@@ -91,77 +91,77 @@ class Address(
message = "moved to val",
replaceWith = ReplaceWith(expression = "url"),
level = DeprecationLevel.ERROR)
fun url() = url
fun url(): HttpUrl = url
@JvmName("-deprecated_dns")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "dns"),
level = DeprecationLevel.ERROR)
fun dns() = dns
fun dns(): Dns = dns
@JvmName("-deprecated_socketFactory")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "socketFactory"),
level = DeprecationLevel.ERROR)
fun socketFactory() = socketFactory
fun socketFactory(): SocketFactory = socketFactory
@JvmName("-deprecated_proxyAuthenticator")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "proxyAuthenticator"),
level = DeprecationLevel.ERROR)
fun proxyAuthenticator() = proxyAuthenticator
fun proxyAuthenticator(): Authenticator = proxyAuthenticator
@JvmName("-deprecated_protocols")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "protocols"),
level = DeprecationLevel.ERROR)
fun protocols() = protocols
fun protocols(): List<Protocol> = protocols
@JvmName("-deprecated_connectionSpecs")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "connectionSpecs"),
level = DeprecationLevel.ERROR)
fun connectionSpecs() = connectionSpecs
fun connectionSpecs(): List<ConnectionSpec> = connectionSpecs
@JvmName("-deprecated_proxySelector")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "proxySelector"),
level = DeprecationLevel.ERROR)
fun proxySelector() = proxySelector
fun proxySelector(): ProxySelector = proxySelector
@JvmName("-deprecated_proxy")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "proxy"),
level = DeprecationLevel.ERROR)
fun proxy() = proxy
fun proxy(): Proxy? = proxy
@JvmName("-deprecated_sslSocketFactory")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "sslSocketFactory"),
level = DeprecationLevel.ERROR)
fun sslSocketFactory() = sslSocketFactory
fun sslSocketFactory(): SSLSocketFactory? = sslSocketFactory
@JvmName("-deprecated_hostnameVerifier")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "hostnameVerifier"),
level = DeprecationLevel.ERROR)
fun hostnameVerifier() = hostnameVerifier
fun hostnameVerifier(): HostnameVerifier? = hostnameVerifier
@JvmName("-deprecated_certificatePinner")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "certificatePinner"),
level = DeprecationLevel.ERROR)
fun certificatePinner() = certificatePinner
fun certificatePinner(): CertificatePinner? = certificatePinner
override fun equals(other: Any?): Boolean {
return other is Address &&

View File

@@ -741,7 +741,7 @@ class Cache(
}
/** Returns true if a Vary header contains an asterisk. Such responses cannot be cached. */
fun Response.hasVaryAll() = "*" in headers.varyFields()
fun Response.hasVaryAll(): Boolean = "*" in headers.varyFields()
/**
* Returns the names of the request headers that need to be checked for equality when caching.

View File

@@ -75,70 +75,70 @@ class CacheControl private constructor(
message = "moved to val",
replaceWith = ReplaceWith(expression = "noCache"),
level = DeprecationLevel.ERROR)
fun noCache() = noCache
fun noCache(): Boolean = noCache
@JvmName("-deprecated_noStore")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "noStore"),
level = DeprecationLevel.ERROR)
fun noStore() = noStore
fun noStore(): Boolean = noStore
@JvmName("-deprecated_maxAgeSeconds")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "maxAgeSeconds"),
level = DeprecationLevel.ERROR)
fun maxAgeSeconds() = maxAgeSeconds
fun maxAgeSeconds(): Int = maxAgeSeconds
@JvmName("-deprecated_sMaxAgeSeconds")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "sMaxAgeSeconds"),
level = DeprecationLevel.ERROR)
fun sMaxAgeSeconds() = sMaxAgeSeconds
fun sMaxAgeSeconds(): Int = sMaxAgeSeconds
@JvmName("-deprecated_mustRevalidate")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "mustRevalidate"),
level = DeprecationLevel.ERROR)
fun mustRevalidate() = mustRevalidate
fun mustRevalidate(): Boolean = mustRevalidate
@JvmName("-deprecated_maxStaleSeconds")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "maxStaleSeconds"),
level = DeprecationLevel.ERROR)
fun maxStaleSeconds() = maxStaleSeconds
fun maxStaleSeconds(): Int = maxStaleSeconds
@JvmName("-deprecated_minFreshSeconds")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "minFreshSeconds"),
level = DeprecationLevel.ERROR)
fun minFreshSeconds() = minFreshSeconds
fun minFreshSeconds(): Int = minFreshSeconds
@JvmName("-deprecated_onlyIfCached")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "onlyIfCached"),
level = DeprecationLevel.ERROR)
fun onlyIfCached() = onlyIfCached
fun onlyIfCached(): Boolean = onlyIfCached
@JvmName("-deprecated_noTransform")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "noTransform"),
level = DeprecationLevel.ERROR)
fun noTransform() = noTransform
fun noTransform(): Boolean = noTransform
@JvmName("-deprecated_immutable")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "immutable"),
level = DeprecationLevel.ERROR)
fun immutable() = immutable
fun immutable(): Boolean = immutable
override fun toString(): String {
var result = headerValue

View File

@@ -78,14 +78,14 @@ class Challenge(
message = "moved to val",
replaceWith = ReplaceWith(expression = "scheme"),
level = DeprecationLevel.ERROR)
fun scheme() = scheme
fun scheme(): String = scheme
@JvmName("-deprecated_authParams")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "authParams"),
level = DeprecationLevel.ERROR)
fun authParams() = authParams
fun authParams(): Map<String?, String> = authParams
@JvmName("-deprecated_realm")
@Deprecated(
@@ -114,5 +114,5 @@ class Challenge(
return result
}
override fun toString() = "$scheme authParams=$authParams"
override fun toString(): String = "$scheme authParams=$authParams"
}

View File

@@ -43,17 +43,17 @@ class FormBody internal constructor(
level = DeprecationLevel.ERROR)
fun size(): Int = size
fun encodedName(index: Int) = encodedNames[index]
fun encodedName(index: Int): String = encodedNames[index]
fun name(index: Int) = encodedName(index).percentDecode(plusIsSpace = true)
fun name(index: Int): String = encodedName(index).percentDecode(plusIsSpace = true)
fun encodedValue(index: Int) = encodedValues[index]
fun encodedValue(index: Int): String = encodedValues[index]
fun value(index: Int) = encodedValue(index).percentDecode(plusIsSpace = true)
fun value(index: Int): String = encodedValue(index).percentDecode(plusIsSpace = true)
override fun contentType() = CONTENT_TYPE
override fun contentType(): MediaType = CONTENT_TYPE
override fun contentLength() = writeOrCountBytes(null, true)
override fun contentLength(): Long = writeOrCountBytes(null, true)
@Throws(IOException::class)
override fun writeTo(sink: BufferedSink) {

View File

@@ -61,21 +61,21 @@ class Handshake internal constructor(
message = "moved to val",
replaceWith = ReplaceWith(expression = "tlsVersion"),
level = DeprecationLevel.ERROR)
fun tlsVersion() = tlsVersion
fun tlsVersion(): TlsVersion = tlsVersion
@JvmName("-deprecated_cipherSuite")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "cipherSuite"),
level = DeprecationLevel.ERROR)
fun cipherSuite() = cipherSuite
fun cipherSuite(): CipherSuite = cipherSuite
@JvmName("-deprecated_peerCertificates")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "peerCertificates"),
level = DeprecationLevel.ERROR)
fun peerCertificates() = peerCertificates
fun peerCertificates(): List<Certificate> = peerCertificates
/** Returns the remote peer's principle, or null if that peer is anonymous. */
@get:JvmName("peerPrincipal")
@@ -87,14 +87,14 @@ class Handshake internal constructor(
message = "moved to val",
replaceWith = ReplaceWith(expression = "peerPrincipal"),
level = DeprecationLevel.ERROR)
fun peerPrincipal() = peerPrincipal
fun peerPrincipal(): Principal? = peerPrincipal
@JvmName("-deprecated_localCertificates")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "localCertificates"),
level = DeprecationLevel.ERROR)
fun localCertificates() = localCertificates
fun localCertificates(): List<Certificate> = localCertificates
/** Returns the local principle, or null if this peer is anonymous. */
@get:JvmName("localPrincipal")
@@ -106,7 +106,7 @@ class Handshake internal constructor(
message = "moved to val",
replaceWith = ReplaceWith(expression = "localPrincipal"),
level = DeprecationLevel.ERROR)
fun localPrincipal() = localPrincipal
fun localPrincipal(): Principal? = localPrincipal
override fun equals(other: Any?): Boolean {
return other is Handshake &&

View File

@@ -778,14 +778,14 @@ class HttpUrl internal constructor(
message = "moved to toUrl()",
replaceWith = ReplaceWith(expression = "toUrl()"),
level = DeprecationLevel.ERROR)
fun url() = toUrl()
fun url(): URL = toUrl()
@JvmName("-deprecated_uri")
@Deprecated(
message = "moved to toUri()",
replaceWith = ReplaceWith(expression = "toUri()"),
level = DeprecationLevel.ERROR)
fun uri() = toUri()
fun uri(): URI = toUri()
@JvmName("-deprecated_scheme")
@Deprecated(

View File

@@ -74,24 +74,24 @@ class MediaType private constructor(
message = "moved to val",
replaceWith = ReplaceWith(expression = "type"),
level = DeprecationLevel.ERROR)
fun type() = type
fun type(): String = type
@JvmName("-deprecated_subtype")
@Deprecated(
message = "moved to val",
replaceWith = ReplaceWith(expression = "subtype"),
level = DeprecationLevel.ERROR)
fun subtype() = subtype
fun subtype(): String = subtype
/**
* Returns the encoded media type, like "text/plain; charset=utf-8", appropriate for use in a
* Content-Type header.
*/
override fun toString() = mediaType
override fun toString(): String = mediaType
override fun equals(other: Any?) = other is MediaType && other.mediaType == mediaType
override fun equals(other: Any?): Boolean = other is MediaType && other.mediaType == mediaType
override fun hashCode() = mediaType.hashCode()
override fun hashCode(): Int = mediaType.hashCode()
companion object {
private const val TOKEN = "([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)"

View File

@@ -166,7 +166,7 @@ class MultipartReader @Throws(IOException::class) constructor(
error("unreachable") // TODO(jwilson): fix intersectWith() to return T.
}
override fun timeout() = timeout
override fun timeout(): Timeout = timeout
}
/**

View File

@@ -91,7 +91,7 @@ enum class Protocol(private val protocol: String) {
*
* [iana]: https://www.iana.org/assignments/tls-extensiontype-values
*/
override fun toString() = protocol
override fun toString(): String = protocol
companion object {
/**

View File

@@ -109,7 +109,7 @@ class Request internal constructor(
level = DeprecationLevel.ERROR)
fun cacheControl(): CacheControl = cacheControl
override fun toString() = buildString {
override fun toString(): String = buildString {
append("Request{method=")
append(method)
append(", url=")
@@ -233,18 +233,18 @@ class Request internal constructor(
}
}
open fun get() = method("GET", null)
open fun get(): Builder = method("GET", null)
open fun head() = method("HEAD", null)
open fun head(): Builder = method("HEAD", null)
open fun post(body: RequestBody) = method("POST", body)
open fun post(body: RequestBody): Builder = method("POST", body)
@JvmOverloads
open fun delete(body: RequestBody? = EMPTY_REQUEST) = method("DELETE", body)
open fun delete(body: RequestBody? = EMPTY_REQUEST): Builder = method("DELETE", body)
open fun put(body: RequestBody) = method("PUT", body)
open fun put(body: RequestBody): Builder = method("PUT", body)
open fun patch(body: RequestBody) = method("PATCH", body)
open fun patch(body: RequestBody): Builder = method("PATCH", body)
open fun method(method: String, body: RequestBody?): Builder = apply {
require(method.isNotEmpty()) {

View File

@@ -196,7 +196,7 @@ abstract class RequestBody {
imports = ["okhttp3.RequestBody.Companion.toRequestBody"]
),
level = DeprecationLevel.WARNING)
fun create(contentType: MediaType?, content: String) = content.toRequestBody(contentType)
fun create(contentType: MediaType?, content: String): RequestBody = content.toRequestBody(contentType)
@JvmStatic
@Deprecated(
@@ -225,7 +225,7 @@ abstract class RequestBody {
content: ByteArray,
offset: Int = 0,
byteCount: Int = content.size
) = content.toRequestBody(contentType, offset, byteCount)
): RequestBody = content.toRequestBody(contentType, offset, byteCount)
@JvmStatic
@Deprecated(
@@ -235,6 +235,6 @@ abstract class RequestBody {
imports = ["okhttp3.RequestBody.Companion.asRequestBody"]
),
level = DeprecationLevel.WARNING)
fun create(contentType: MediaType?, file: File) = file.asRequestBody(contentType)
fun create(contentType: MediaType?, file: File): RequestBody= file.asRequestBody(contentType)
}
}

View File

@@ -302,7 +302,7 @@ class Response internal constructor(
checkNotNull(body) { "response is not eligible for a body and must not be closed" }.close()
}
override fun toString() =
override fun toString(): String =
"Response{protocol=$protocol, code=$code, message=$message, url=${request.url}}"
open class Builder {

View File

@@ -266,11 +266,11 @@ abstract class ResponseBody : Closeable {
contentType: MediaType? = null,
contentLength: Long = -1L
): ResponseBody = object : ResponseBody() {
override fun contentType() = contentType
override fun contentType(): MediaType? = contentType
override fun contentLength() = contentLength
override fun contentLength(): Long = contentLength
override fun source() = this@asResponseBody
override fun source(): BufferedSource = this@asResponseBody
}
@JvmStatic
@@ -281,7 +281,7 @@ abstract class ResponseBody : Closeable {
imports = ["okhttp3.ResponseBody.Companion.toResponseBody"]
),
level = DeprecationLevel.WARNING)
fun create(contentType: MediaType?, content: String) = content.toResponseBody(contentType)
fun create(contentType: MediaType?, content: String): ResponseBody = content.toResponseBody(contentType)
@JvmStatic
@Deprecated(
@@ -291,7 +291,7 @@ abstract class ResponseBody : Closeable {
imports = ["okhttp3.ResponseBody.Companion.toResponseBody"]
),
level = DeprecationLevel.WARNING)
fun create(contentType: MediaType?, content: ByteArray) = content.toResponseBody(contentType)
fun create(contentType: MediaType?, content: ByteArray): ResponseBody = content.toResponseBody(contentType)
@JvmStatic
@Deprecated(
@@ -301,7 +301,7 @@ abstract class ResponseBody : Closeable {
imports = ["okhttp3.ResponseBody.Companion.toResponseBody"]
),
level = DeprecationLevel.WARNING)
fun create(contentType: MediaType?, content: ByteString) = content.toResponseBody(contentType)
fun create(contentType: MediaType?, content: ByteString): ResponseBody = content.toResponseBody(contentType)
@JvmStatic
@Deprecated(
@@ -315,6 +315,6 @@ abstract class ResponseBody : Closeable {
contentType: MediaType?,
contentLength: Long,
content: BufferedSource
) = content.asResponseBody(contentType, contentLength)
): ResponseBody = content.asResponseBody(contentType, contentLength)
}
}

View File

@@ -70,7 +70,7 @@ class Route(
*
* [rfc_2817]: http://www.ietf.org/rfc/rfc2817.txt
*/
fun requiresTunnel() = address.sslSocketFactory != null && proxy.type() == Proxy.Type.HTTP
fun requiresTunnel(): Boolean = address.sslSocketFactory != null && proxy.type() == Proxy.Type.HTTP
override fun equals(other: Any?): Boolean {
return other is Route &&

View File

@@ -33,7 +33,7 @@ enum class TlsVersion(
message = "moved to val",
replaceWith = ReplaceWith(expression = "javaName"),
level = DeprecationLevel.ERROR)
fun javaName() = javaName
fun javaName(): String = javaName
companion object {
@JvmStatic

View File

@@ -44,8 +44,10 @@ import okhttp3.Headers.Companion.headersOf
import okhttp3.HttpUrl
import okhttp3.OkHttp
import okhttp3.OkHttpClient
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import okhttp3.internal.http2.Header
import okio.Buffer
@@ -59,14 +61,14 @@ import okio.Path
import okio.Source
@JvmField
val EMPTY_BYTE_ARRAY = ByteArray(0)
val EMPTY_BYTE_ARRAY: ByteArray = ByteArray(0)
@JvmField
val EMPTY_HEADERS = headersOf()
val EMPTY_HEADERS: Headers = headersOf()
@JvmField
val EMPTY_RESPONSE = EMPTY_BYTE_ARRAY.toResponseBody()
val EMPTY_RESPONSE: ResponseBody = EMPTY_BYTE_ARRAY.toResponseBody()
@JvmField
val EMPTY_REQUEST = EMPTY_BYTE_ARRAY.toRequestBody()
val EMPTY_REQUEST: RequestBody = EMPTY_BYTE_ARRAY.toRequestBody()
/** Byte order marks. */
private val UNICODE_BOMS = Options.of(
@@ -79,7 +81,7 @@ private val UNICODE_BOMS = Options.of(
/** GMT and UTC are equivalent for our purposes. */
@JvmField
val UTC = TimeZone.getTimeZone("GMT")!!
val UTC: TimeZone = TimeZone.getTimeZone("GMT")!!
/**
* Quick and dirty pattern to differentiate IP addresses from hostnames. This is an approximation
@@ -633,7 +635,7 @@ internal fun <E> MutableList<E>.addIfAbsent(element: E) {
}
@JvmField
val assertionsEnabled = OkHttpClient::class.java.desiredAssertionStatus()
val assertionsEnabled: Boolean = OkHttpClient::class.java.desiredAssertionStatus()
/**
* Returns the string "OkHttp" unless the library has been shaded for inclusion in another library,
@@ -642,7 +644,7 @@ val assertionsEnabled = OkHttpClient::class.java.desiredAssertionStatus()
* instances; this makes it clear which is which.
*/
@JvmField
internal val okHttpName =
internal val okHttpName: String =
OkHttpClient::class.java.name.removePrefix("okhttp3.").removeSuffix("Client")
@Suppress("NOTHING_TO_INLINE")
@@ -674,4 +676,4 @@ internal inline fun <T> Iterable<T>.filterList(predicate: T.() -> Boolean): List
return result
}
const val userAgent = "okhttp/${OkHttp.VERSION}"
const val userAgent: String = "okhttp/${OkHttp.VERSION}"

View File

@@ -36,6 +36,7 @@ import okhttp3.internal.http.RealResponseBody
import okhttp3.internal.http.promisesBody
import okio.Buffer
import okio.Source
import okio.Timeout
import okio.buffer
/** Serves requests from the cache and writes responses to the cache. */
@@ -197,7 +198,7 @@ class CacheInterceptor(internal val cache: Cache?) : Interceptor {
return bytesRead
}
override fun timeout() = source.timeout()
override fun timeout(): Timeout = source.timeout()
@Throws(IOException::class)
override fun close() {

View File

@@ -66,5 +66,5 @@ abstract class Task(
this.queue = queue
}
override fun toString() = name
override fun toString(): String = name
}

View File

@@ -215,5 +215,5 @@ class TaskQueue internal constructor(
return tasksCanceled
}
override fun toString() = name
override fun toString(): String = name
}

View File

@@ -47,6 +47,7 @@ import okhttp3.internal.http.RetryAndFollowUpInterceptor
import okhttp3.internal.platform.Platform
import okhttp3.internal.threadName
import okio.AsyncTimeout
import okio.Timeout
/**
* Bridge between OkHttp's application and network layers. This class exposes high-level application
@@ -116,10 +117,10 @@ class RealCall(
@Volatile private var exchange: Exchange? = null
@Volatile var connectionToCancel: RealConnection? = null
override fun timeout() = timeout
override fun timeout(): Timeout = timeout
@SuppressWarnings("CloneDoesntCallSuperClone") // We are a final type & this saves clearing state.
override fun clone() = RealCall(client, originalRequest, forWebSocket)
override fun clone(): Call = RealCall(client, originalRequest, forWebSocket)
override fun request(): Request = originalRequest
@@ -142,7 +143,7 @@ class RealCall(
eventListener.canceled(this)
}
override fun isCanceled() = canceled
override fun isCanceled(): Boolean = canceled
override fun execute(): Response {
check(executed.compareAndSet(false, true)) { "Already Executed" }
@@ -453,7 +454,7 @@ class RealCall(
)
}
fun retryAfterFailure() = exchangeFinder!!.retryAfterFailure()
fun retryAfterFailure(): Boolean = exchangeFinder!!.retryAfterFailure()
/**
* Returns a string that describes this call. Doesn't include a full URL as that might contain

View File

@@ -41,7 +41,7 @@ class RealConnectionPool(
private val cleanupQueue: TaskQueue = taskRunner.newQueue()
private val cleanupTask = object : Task("$okHttpName ConnectionPool") {
override fun runOnce() = cleanup(System.nanoTime())
override fun runOnce(): Long = cleanup(System.nanoTime())
}
/**
@@ -162,9 +162,7 @@ class RealConnectionPool(
if (idleDurationNs > longestIdleDurationNs) {
longestIdleDurationNs = idleDurationNs
longestIdleConnection = connection
} else {
Unit
}
} else Unit
}
}
}

View File

@@ -135,7 +135,7 @@ class CallServerInterceptor(private val forWebSocket: Boolean) : Interceptor {
"close".equals(response.header("Connection"), ignoreCase = true)) {
exchange.noNewExchangesOnConnection()
}
if ((code == 204 || code == 205) && response.body?.contentLength() ?: -1L > 0L) {
if ((code == 204 || code == 205) && (response.body?.contentLength() ?: -1L) > 0L) {
throw ProtocolException(
"HTTP $code had non-zero Content-Length: ${response.body?.contentLength()}")
}

View File

@@ -154,7 +154,7 @@ private fun Buffer.skipCommasAndWhitespace(): Boolean {
return commaFound
}
private fun Buffer.startsWith(prefix: Byte) = !exhausted() && this[0] == prefix
private fun Buffer.startsWith(prefix: Byte): Boolean = !exhausted() && this[0] == prefix
/**
* Reads a double-quoted string, unescaping quoted pairs like `\"` to the 2nd character in each

View File

@@ -27,7 +27,7 @@ object RequestLine {
* [HttpURLConnection.getHeaderFields], so it needs to be set even if the transport is
* HTTP/2.
*/
fun get(request: Request, proxyType: Proxy.Type) = buildString {
fun get(request: Request, proxyType: Proxy.Type): String = buildString {
append(request.method)
append(' ')
if (includeAuthorityInRequestLine(request, proxyType)) {

View File

@@ -119,7 +119,7 @@ object Http2 {
direction, streamId, length, formattedType, formattedFlags)
}
internal fun formattedType(type: Int) =
internal fun formattedType(type: Int): String =
if (type < FRAME_NAMES.size) FRAME_NAMES[type] else format("0x%02x", type)
/**

View File

@@ -33,16 +33,16 @@ import okhttp3.internal.connection.RealConnection
fun parseCookie(currentTimeMillis: Long, url: HttpUrl, setCookie: String): Cookie? =
Cookie.parse(currentTimeMillis, url, setCookie)
fun cookieToString(cookie: Cookie, forObsoleteRfc2965: Boolean) =
fun cookieToString(cookie: Cookie, forObsoleteRfc2965: Boolean): String =
cookie.toString(forObsoleteRfc2965)
fun addHeaderLenient(builder: Headers.Builder, line: String) =
fun addHeaderLenient(builder: Headers.Builder, line: String): Headers.Builder =
builder.addLenient(line)
fun addHeaderLenient(builder: Headers.Builder, name: String, value: String) =
fun addHeaderLenient(builder: Headers.Builder, name: String, value: String): Headers.Builder =
builder.addLenient(name, value)
fun cacheGet(cache: Cache, request: Request) = cache.get(request)
fun cacheGet(cache: Cache, request: Request): Response? = cache.get(request)
fun applyConnectionSpec(connectionSpec: ConnectionSpec, sslSocket: SSLSocket, isFallback: Boolean) =
connectionSpec.apply(sslSocket, isFallback)

View File

@@ -53,7 +53,7 @@ class Android10Platform : Platform() {
?.configureTlsExtensions(sslSocket, hostname, protocols)
}
override fun getSelectedProtocol(sslSocket: SSLSocket) =
override fun getSelectedProtocol(sslSocket: SSLSocket): String? =
// No TLS extensions if the socket class is custom.
socketAdapters.find { it.matchesSocket(sslSocket) }?.getSelectedProtocol(sslSocket)

View File

@@ -83,7 +83,7 @@ class AndroidPlatform : Platform() {
?.configureTlsExtensions(sslSocket, hostname, protocols)
}
override fun getSelectedProtocol(sslSocket: SSLSocket) =
override fun getSelectedProtocol(sslSocket: SSLSocket): String? =
// No TLS extensions if the socket class is custom.
socketAdapters.find { it.matchesSocket(sslSocket) }?.getSelectedProtocol(sslSocket)

View File

@@ -61,5 +61,5 @@ class MessageDeflater(
@Throws(IOException::class)
override fun close() = deflaterSink.close()
private fun Buffer.endsWith(suffix: ByteString) = rangeEquals(size - suffix.size, suffix)
private fun Buffer.endsWith(suffix: ByteString): Boolean = rangeEquals(size - suffix.size, suffix)
}