mirror of
https://github.com/square/okhttp.git
synced 2025-11-24 18:41:06 +03:00
Code cleanup and imports (#6822)
This commit is contained in:
@@ -88,7 +88,7 @@ class RecordedRequest {
|
|||||||
socket: Socket,
|
socket: Socket,
|
||||||
failure: IOException? = null
|
failure: IOException? = null
|
||||||
) {
|
) {
|
||||||
this.requestLine = requestLine;
|
this.requestLine = requestLine
|
||||||
this.headers = headers
|
this.headers = headers
|
||||||
this.chunkSizes = chunkSizes
|
this.chunkSizes = chunkSizes
|
||||||
this.bodySize = bodySize
|
this.bodySize = bodySize
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ package mockwebserver3.junit4
|
|||||||
|
|
||||||
import java.net.ConnectException
|
import java.net.ConnectException
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import org.assertj.core.api.Assertions
|
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.Assert.fail
|
import org.junit.Assert.fail
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.Description
|
import org.junit.runner.Description
|
||||||
|
|||||||
@@ -909,11 +909,11 @@ class MockWebServer : Closeable {
|
|||||||
override fun close() = shutdown()
|
override fun close() = shutdown()
|
||||||
|
|
||||||
/** A buffer wrapper that drops data after [bodyLimit] bytes. */
|
/** A buffer wrapper that drops data after [bodyLimit] bytes. */
|
||||||
private class TruncatingBuffer internal constructor(
|
private class TruncatingBuffer(
|
||||||
private var remainingByteCount: Long
|
private var remainingByteCount: Long
|
||||||
) : Sink {
|
) : Sink {
|
||||||
internal val buffer = Buffer()
|
val buffer = Buffer()
|
||||||
internal var receivedByteCount = 0L
|
var receivedByteCount = 0L
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun write(source: Buffer, byteCount: Long) {
|
override fun write(source: Buffer, byteCount: Long) {
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import picocli.CommandLine.Command
|
|||||||
import picocli.CommandLine.IVersionProvider
|
import picocli.CommandLine.IVersionProvider
|
||||||
import picocli.CommandLine.Option
|
import picocli.CommandLine.Option
|
||||||
import picocli.CommandLine.Parameters
|
import picocli.CommandLine.Parameters
|
||||||
import java.lang.IllegalArgumentException
|
|
||||||
|
|
||||||
@Command(name = NAME, description = ["A curl for the next-generation web."],
|
@Command(name = NAME, description = ["A curl for the next-generation web."],
|
||||||
mixinStandardHelpOptions = true, versionProvider = Main.VersionProvider::class)
|
mixinStandardHelpOptions = true, versionProvider = Main.VersionProvider::class)
|
||||||
@@ -175,7 +174,7 @@ class Main : Runnable {
|
|||||||
return builder.build()
|
return builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun createRequest(): Request {
|
fun createRequest(): Request {
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
|
|
||||||
val requestMethod = method ?: if (data != null) "POST" else "GET"
|
val requestMethod = method ?: if (data != null) "POST" else "GET"
|
||||||
@@ -291,10 +290,10 @@ class Main : Runnable {
|
|||||||
formatter = object : SimpleFormatter() {
|
formatter = object : SimpleFormatter() {
|
||||||
override fun format(record: LogRecord): String {
|
override fun format(record: LogRecord): String {
|
||||||
val parameters = record.parameters
|
val parameters = record.parameters
|
||||||
if (parameters != null) {
|
return if (parameters != null) {
|
||||||
return format("%s%n%s%n", record.message, record.parameters.first())
|
format("%s%n%s%n", record.message, record.parameters.first())
|
||||||
} else {
|
} else {
|
||||||
return format("%s%n", record.message)
|
format("%s%n", record.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,7 @@ package okhttp3.brotli
|
|||||||
|
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.ResponseBody.Companion.asResponseBody
|
|
||||||
import okhttp3.brotli.internal.uncompress
|
import okhttp3.brotli.internal.uncompress
|
||||||
import okhttp3.internal.http.promisesBody
|
|
||||||
import okio.GzipSource
|
|
||||||
import okio.buffer
|
|
||||||
import okio.source
|
|
||||||
import org.brotli.dec.BrotliInputStream
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transparent Brotli response support.
|
* Transparent Brotli response support.
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import java.io.IOException
|
|||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.net.UnknownHostException
|
import java.net.UnknownHostException
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
import okhttp3.CacheControl
|
import okhttp3.CacheControl
|
||||||
import okhttp3.Call
|
import okhttp3.Call
|
||||||
@@ -85,9 +84,7 @@ class DnsOverHttps internal constructor(
|
|||||||
|
|
||||||
executeRequests(hostname, networkRequests, results, failures)
|
executeRequests(hostname, networkRequests, results, failures)
|
||||||
|
|
||||||
return if (results.isNotEmpty()) {
|
return results.ifEmpty {
|
||||||
results
|
|
||||||
} else {
|
|
||||||
throwBestFailure(hostname, failures)
|
throwBestFailure(hostname, failures)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class FakeDns : Dns {
|
|||||||
hostname: String,
|
hostname: String,
|
||||||
index: Int
|
index: Int
|
||||||
): InetAddress {
|
): InetAddress {
|
||||||
return hostAddresses[hostname]!!.get(index)
|
return hostAddresses[hostname]!![index]
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(UnknownHostException::class)
|
@Throws(UnknownHostException::class)
|
||||||
|
|||||||
@@ -112,8 +112,7 @@ internal class DerReader(source: Source) {
|
|||||||
val tagAndClass = source.readByte().toInt() and 0xff
|
val tagAndClass = source.readByte().toInt() and 0xff
|
||||||
val tagClass = tagAndClass and 0b1100_0000
|
val tagClass = tagAndClass and 0b1100_0000
|
||||||
val constructed = (tagAndClass and 0b0010_0000) == 0b0010_0000
|
val constructed = (tagAndClass and 0b0010_0000) == 0b0010_0000
|
||||||
val tag0 = tagAndClass and 0b0001_1111
|
val tag = when (val tag0 = tagAndClass and 0b0001_1111) {
|
||||||
val tag = when (tag0) {
|
|
||||||
0b0001_1111 -> readVariableLengthLong()
|
0b0001_1111 -> readVariableLengthLong()
|
||||||
else -> tag0.toLong()
|
else -> tag0.toLong()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,8 +145,7 @@ class Handshake internal constructor(
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmName("get")
|
@JvmName("get")
|
||||||
fun SSLSession.handshake(): Handshake {
|
fun SSLSession.handshake(): Handshake {
|
||||||
val cipherSuiteString = checkNotNull(cipherSuite) { "cipherSuite == null" }
|
val cipherSuite = when (val cipherSuiteString = checkNotNull(cipherSuite) { "cipherSuite == null" }) {
|
||||||
val cipherSuite = when (cipherSuiteString) {
|
|
||||||
"TLS_NULL_WITH_NULL_NULL", "SSL_NULL_WITH_NULL_NULL" -> {
|
"TLS_NULL_WITH_NULL_NULL", "SSL_NULL_WITH_NULL_NULL" -> {
|
||||||
throw IOException("cipherSuite == $cipherSuiteString")
|
throw IOException("cipherSuite == $cipherSuiteString")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,16 +30,16 @@ fun buildCache(file: Path, maxSize: Long, fileSystem: FileSystem): Cache {
|
|||||||
return Cache(file, maxSize, fileSystem)
|
return Cache(file, maxSize, fileSystem)
|
||||||
}
|
}
|
||||||
|
|
||||||
var RealConnection.idleAtNsAccessor
|
var RealConnection.idleAtNsAccessor: Long
|
||||||
get() = idleAtNs
|
get() = idleAtNs
|
||||||
set(value) {
|
set(value) {
|
||||||
idleAtNs = value
|
idleAtNs = value
|
||||||
}
|
}
|
||||||
|
|
||||||
val Response.exchange
|
val Response.exchangeAccessor: Exchange?
|
||||||
get() = this.exchange
|
get() = this.exchange
|
||||||
|
|
||||||
val Exchange.connection
|
val Exchange.connectionAccessor: RealConnection
|
||||||
get() = this.connection
|
get() = this.connection
|
||||||
|
|
||||||
fun Dispatcher.finished(call: RealCall.AsyncCall) = this.finished(call)
|
fun Dispatcher.finishedAccessor(call: RealCall.AsyncCall) = this.finished(call)
|
||||||
|
|||||||
@@ -65,12 +65,10 @@ class StatusLine(
|
|||||||
}
|
}
|
||||||
val httpMinorVersion = statusLine[7] - '0'
|
val httpMinorVersion = statusLine[7] - '0'
|
||||||
codeStart = 9
|
codeStart = 9
|
||||||
protocol = if (httpMinorVersion == 0) {
|
protocol = when (httpMinorVersion) {
|
||||||
Protocol.HTTP_1_0
|
0 -> Protocol.HTTP_1_0
|
||||||
} else if (httpMinorVersion == 1) {
|
1 -> Protocol.HTTP_1_1
|
||||||
Protocol.HTTP_1_1
|
else -> throw ProtocolException("Unexpected status line: $statusLine")
|
||||||
} else {
|
|
||||||
throw ProtocolException("Unexpected status line: $statusLine")
|
|
||||||
}
|
}
|
||||||
} else if (statusLine.startsWith("ICY ")) {
|
} else if (statusLine.startsWith("ICY ")) {
|
||||||
// Shoutcast uses ICY instead of "HTTP/1.0".
|
// Shoutcast uses ICY instead of "HTTP/1.0".
|
||||||
|
|||||||
@@ -42,16 +42,16 @@ open class Jdk9Platform : Platform() {
|
|||||||
|
|
||||||
@SuppressSignatureCheck
|
@SuppressSignatureCheck
|
||||||
override fun getSelectedProtocol(sslSocket: SSLSocket): String? {
|
override fun getSelectedProtocol(sslSocket: SSLSocket): String? {
|
||||||
try {
|
return try {
|
||||||
// SSLSocket.getApplicationProtocol returns "" if application protocols values will not
|
// SSLSocket.getApplicationProtocol returns "" if application protocols values will not
|
||||||
// be used. Observed if you didn't specify SSLParameters.setApplicationProtocols
|
// be used. Observed if you didn't specify SSLParameters.setApplicationProtocols
|
||||||
return when (val protocol = sslSocket.applicationProtocol) {
|
when (val protocol = sslSocket.applicationProtocol) {
|
||||||
null, "" -> null
|
null, "" -> null
|
||||||
else -> protocol
|
else -> protocol
|
||||||
}
|
}
|
||||||
} catch (e: UnsupportedOperationException) {
|
} catch (e: UnsupportedOperationException) {
|
||||||
// https://docs.oracle.com/javase/9/docs/api/javax/net/ssl/SSLSocket.html#getApplicationProtocol--
|
// https://docs.oracle.com/javase/9/docs/api/javax/net/ssl/SSLSocket.html#getApplicationProtocol--
|
||||||
return null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ open class AndroidSocketAdapter(private val sslSocketClass: Class<in SSLSocket>)
|
|||||||
val alpnResult = getAlpnSelectedProtocol.invoke(sslSocket) as ByteArray?
|
val alpnResult = getAlpnSelectedProtocol.invoke(sslSocket) as ByteArray?
|
||||||
if (alpnResult != null) String(alpnResult, StandardCharsets.UTF_8) else null
|
if (alpnResult != null) String(alpnResult, StandardCharsets.UTF_8) else null
|
||||||
} catch (e: NullPointerException) {
|
} catch (e: NullPointerException) {
|
||||||
when {
|
// https://github.com/square/okhttp/issues/5587
|
||||||
// https://github.com/square/okhttp/issues/5587
|
when (e.message) {
|
||||||
e.message == "ssl == null" -> null
|
"ssl == null" -> null
|
||||||
else -> throw e
|
else -> throw e
|
||||||
}
|
}
|
||||||
} catch (e: IllegalAccessException) {
|
} catch (e: IllegalAccessException) {
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ class HeadersKotlinTest {
|
|||||||
builder["c"] = "d"
|
builder["c"] = "d"
|
||||||
builder["e"] = Date(0L)
|
builder["e"] = Date(0L)
|
||||||
builder["g"] = Instant.EPOCH
|
builder["g"] = Instant.EPOCH
|
||||||
assertThat(builder.get("a")).isEqualTo("b")
|
assertThat(builder["a"]).isEqualTo("b")
|
||||||
assertThat(builder.get("c")).isEqualTo("d")
|
assertThat(builder["c"]).isEqualTo("d")
|
||||||
assertThat(builder.get("e")).isEqualTo("Thu, 01 Jan 1970 00:00:00 GMT")
|
assertThat(builder["e"]).isEqualTo("Thu, 01 Jan 1970 00:00:00 GMT")
|
||||||
assertThat(builder.get("g")).isEqualTo("Thu, 01 Jan 1970 00:00:00 GMT")
|
assertThat(builder["g"]).isEqualTo("Thu, 01 Jan 1970 00:00:00 GMT")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ import okhttp3.tls.HandshakeCertificates
|
|||||||
import okhttp3.tls.HeldCertificate
|
import okhttp3.tls.HeldCertificate
|
||||||
import okhttp3.tls.internal.TlsUtil.localhost
|
import okhttp3.tls.internal.TlsUtil.localhost
|
||||||
import okio.Buffer
|
import okio.Buffer
|
||||||
import org.junit.Ignore
|
|
||||||
import org.junit.jupiter.api.Disabled
|
import org.junit.jupiter.api.Disabled
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
@@ -101,7 +100,7 @@ class KotlinDeprecationErrorTest {
|
|||||||
|
|
||||||
@Test @Disabled
|
@Test @Disabled
|
||||||
fun challenge() {
|
fun challenge() {
|
||||||
val challenge = Challenge("", mapOf<String?, String>("" to ""))
|
val challenge = Challenge("", mapOf("" to ""))
|
||||||
val scheme: String = challenge.scheme()
|
val scheme: String = challenge.scheme()
|
||||||
val authParams: Map<String?, String> = challenge.authParams()
|
val authParams: Map<String?, String> = challenge.authParams()
|
||||||
val realm: String? = challenge.realm()
|
val realm: String? = challenge.realm()
|
||||||
|
|||||||
@@ -119,9 +119,7 @@ class KotlinSourceModernTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun authenticator() {
|
fun authenticator() {
|
||||||
var authenticator: Authenticator = object : Authenticator {
|
var authenticator: Authenticator = Authenticator { route, response -> TODO() }
|
||||||
override fun authenticate(route: Route?, response: Response): Request? = TODO()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -402,9 +400,7 @@ class KotlinSourceModernTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun eventListenerBuilder() {
|
fun eventListenerBuilder() {
|
||||||
var builder: EventListener.Factory = object : EventListener.Factory {
|
var builder: EventListener.Factory = EventListener.Factory { TODO() }
|
||||||
override fun create(call: Call): EventListener = TODO()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -453,7 +449,7 @@ class KotlinSourceModernTest {
|
|||||||
fun headers() {
|
fun headers() {
|
||||||
var headers: Headers = headersOf("", "")
|
var headers: Headers = headersOf("", "")
|
||||||
headers = mapOf("" to "").toHeaders()
|
headers = mapOf("" to "").toHeaders()
|
||||||
val get: String? = headers.get("")
|
val get: String? = headers[""]
|
||||||
val date: Date? = headers.getDate("")
|
val date: Date? = headers.getDate("")
|
||||||
val instant: Instant? = headers.getInstant("")
|
val instant: Instant? = headers.getInstant("")
|
||||||
val size: Int = headers.size
|
val size: Int = headers.size
|
||||||
@@ -479,7 +475,7 @@ class KotlinSourceModernTest {
|
|||||||
builder = builder.set("", Date(0L))
|
builder = builder.set("", Date(0L))
|
||||||
builder = builder.set("", Instant.EPOCH)
|
builder = builder.set("", Instant.EPOCH)
|
||||||
builder = builder.removeAll("")
|
builder = builder.removeAll("")
|
||||||
val get: String? = builder.get("")
|
val get: String? = builder[""]
|
||||||
val headers: Headers = builder.build()
|
val headers: Headers = builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,9 +499,7 @@ class KotlinSourceModernTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun httpLoggingInterceptorLogger() {
|
fun httpLoggingInterceptorLogger() {
|
||||||
var logger: HttpLoggingInterceptor.Logger = object : HttpLoggingInterceptor.Logger {
|
var logger: HttpLoggingInterceptor.Logger = HttpLoggingInterceptor.Logger { TODO() }
|
||||||
override fun log(message: String) = TODO()
|
|
||||||
}
|
|
||||||
val default: HttpLoggingInterceptor.Logger = HttpLoggingInterceptor.Logger.DEFAULT
|
val default: HttpLoggingInterceptor.Logger = HttpLoggingInterceptor.Logger.DEFAULT
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,9 +574,7 @@ class KotlinSourceModernTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun interceptor() {
|
fun interceptor() {
|
||||||
var interceptor: Interceptor = object : Interceptor {
|
var interceptor: Interceptor = Interceptor { TODO() }
|
||||||
override fun intercept(chain: Interceptor.Chain): Response = TODO()
|
|
||||||
}
|
|
||||||
interceptor = Interceptor { it: Interceptor.Chain -> TODO() }
|
interceptor = Interceptor { it: Interceptor.Chain -> TODO() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -874,19 +866,13 @@ class KotlinSourceModernTest {
|
|||||||
builder = builder.protocols(listOf(Protocol.HTTP_1_1))
|
builder = builder.protocols(listOf(Protocol.HTTP_1_1))
|
||||||
builder = builder.connectionSpecs(listOf(ConnectionSpec.MODERN_TLS))
|
builder = builder.connectionSpecs(listOf(ConnectionSpec.MODERN_TLS))
|
||||||
val interceptors: List<Interceptor> = builder.interceptors()
|
val interceptors: List<Interceptor> = builder.interceptors()
|
||||||
builder = builder.addInterceptor(object : Interceptor {
|
builder = builder.addInterceptor(Interceptor { TODO() })
|
||||||
override fun intercept(chain: Interceptor.Chain): Response = TODO()
|
|
||||||
})
|
|
||||||
builder = builder.addInterceptor { it: Interceptor.Chain -> TODO() }
|
builder = builder.addInterceptor { it: Interceptor.Chain -> TODO() }
|
||||||
val networkInterceptors: List<Interceptor> = builder.networkInterceptors()
|
val networkInterceptors: List<Interceptor> = builder.networkInterceptors()
|
||||||
builder = builder.addNetworkInterceptor(object : Interceptor {
|
builder = builder.addNetworkInterceptor(Interceptor { TODO() })
|
||||||
override fun intercept(chain: Interceptor.Chain): Response = TODO()
|
|
||||||
})
|
|
||||||
builder = builder.addNetworkInterceptor { it: Interceptor.Chain -> TODO() }
|
builder = builder.addNetworkInterceptor { it: Interceptor.Chain -> TODO() }
|
||||||
builder = builder.eventListener(EventListener.NONE)
|
builder = builder.eventListener(EventListener.NONE)
|
||||||
builder = builder.eventListenerFactory(object : EventListener.Factory {
|
builder = builder.eventListenerFactory { TODO() }
|
||||||
override fun create(call: Call): EventListener = TODO()
|
|
||||||
})
|
|
||||||
val client: OkHttpClient = builder.build()
|
val client: OkHttpClient = builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ import java.net.InetAddress
|
|||||||
import mockwebserver3.MockResponse
|
import mockwebserver3.MockResponse
|
||||||
import mockwebserver3.MockWebServer
|
import mockwebserver3.MockWebServer
|
||||||
import okhttp3.TestUtil.assumeNetwork
|
import okhttp3.TestUtil.assumeNetwork
|
||||||
|
import okhttp3.internal.connectionAccessor
|
||||||
|
import okhttp3.internal.exchangeAccessor
|
||||||
import okhttp3.internal.platform.OpenJSSEPlatform
|
import okhttp3.internal.platform.OpenJSSEPlatform
|
||||||
import okhttp3.testing.PlatformRule
|
import okhttp3.testing.PlatformRule
|
||||||
import okhttp3.tls.HandshakeCertificates
|
import okhttp3.tls.HandshakeCertificates
|
||||||
@@ -31,8 +33,6 @@ import org.junit.jupiter.api.Test
|
|||||||
import org.junit.jupiter.api.extension.RegisterExtension
|
import org.junit.jupiter.api.extension.RegisterExtension
|
||||||
import org.openjsse.sun.security.ssl.SSLSocketFactoryImpl
|
import org.openjsse.sun.security.ssl.SSLSocketFactoryImpl
|
||||||
import org.openjsse.sun.security.ssl.SSLSocketImpl
|
import org.openjsse.sun.security.ssl.SSLSocketImpl
|
||||||
import okhttp3.internal.exchange
|
|
||||||
import okhttp3.internal.connection
|
|
||||||
|
|
||||||
class OpenJSSETest(
|
class OpenJSSETest(
|
||||||
val server: MockWebServer
|
val server: MockWebServer
|
||||||
@@ -62,7 +62,7 @@ class OpenJSSETest(
|
|||||||
assertEquals(TlsVersion.TLS_1_3, response.handshake?.tlsVersion)
|
assertEquals(TlsVersion.TLS_1_3, response.handshake?.tlsVersion)
|
||||||
assertEquals(Protocol.HTTP_2, response.protocol)
|
assertEquals(Protocol.HTTP_2, response.protocol)
|
||||||
|
|
||||||
assertThat(response.exchange?.connection?.socket()).isInstanceOf(SSLSocketImpl::class.java)
|
assertThat(response.exchangeAccessor?.connectionAccessor?.socket()).isInstanceOf(SSLSocketImpl::class.java)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ import java.util.concurrent.AbstractExecutorService
|
|||||||
import java.util.concurrent.RejectedExecutionException
|
import java.util.concurrent.RejectedExecutionException
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import okhttp3.internal.connection.RealCall
|
import okhttp3.internal.connection.RealCall
|
||||||
|
import okhttp3.internal.finishedAccessor
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import okhttp3.internal.finished
|
|
||||||
|
|
||||||
internal class RecordingExecutor(
|
internal class RecordingExecutor(
|
||||||
private val dispatcherTest: DispatcherTest
|
private val dispatcherTest: DispatcherTest
|
||||||
@@ -44,7 +44,7 @@ internal class RecordingExecutor(
|
|||||||
val call = i.next()
|
val call = i.next()
|
||||||
if (call.request.url.toString() == url) {
|
if (call.request.url.toString() == url) {
|
||||||
i.remove()
|
i.remove()
|
||||||
dispatcherTest.dispatcher.finished(call)
|
dispatcherTest.dispatcher.finishedAccessor(call)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,15 +25,10 @@ import okhttp3.TlsExtensionMode.DISABLED
|
|||||||
import okhttp3.TlsExtensionMode.STANDARD
|
import okhttp3.TlsExtensionMode.STANDARD
|
||||||
import okhttp3.TlsVersion.TLS_1_2
|
import okhttp3.TlsVersion.TLS_1_2
|
||||||
import okhttp3.TlsVersion.TLS_1_3
|
import okhttp3.TlsVersion.TLS_1_3
|
||||||
import okhttp3.internal.platform.ConscryptPlatform
|
|
||||||
import okhttp3.internal.platform.Platform
|
|
||||||
import okhttp3.testing.Flaky
|
|
||||||
import okhttp3.testing.PlatformRule
|
import okhttp3.testing.PlatformRule
|
||||||
import okhttp3.tls.HandshakeCertificates
|
import okhttp3.tls.HandshakeCertificates
|
||||||
import okhttp3.tls.HeldCertificate
|
import okhttp3.tls.HeldCertificate
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.conscrypt.Conscrypt
|
|
||||||
import org.junit.After
|
|
||||||
import org.junit.jupiter.api.Assumptions.assumeFalse
|
import org.junit.jupiter.api.Assumptions.assumeFalse
|
||||||
import org.junit.jupiter.api.Assumptions.assumeTrue
|
import org.junit.jupiter.api.Assumptions.assumeTrue
|
||||||
import org.junit.jupiter.api.Tag
|
import org.junit.jupiter.api.Tag
|
||||||
@@ -43,7 +38,6 @@ import org.junit.jupiter.params.ParameterizedTest
|
|||||||
import org.junit.jupiter.params.provider.MethodSource
|
import org.junit.jupiter.params.provider.MethodSource
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.security.Security
|
|
||||||
import java.util.concurrent.CompletableFuture
|
import java.util.concurrent.CompletableFuture
|
||||||
import java.util.concurrent.TimeUnit.SECONDS
|
import java.util.concurrent.TimeUnit.SECONDS
|
||||||
import javax.net.ssl.SNIHostName
|
import javax.net.ssl.SNIHostName
|
||||||
@@ -241,4 +235,4 @@ enum class Provider {
|
|||||||
enum class TlsExtensionMode {
|
enum class TlsExtensionMode {
|
||||||
DISABLED,
|
DISABLED,
|
||||||
STANDARD
|
STANDARD
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,8 +388,8 @@ class DiskLruCacheTest {
|
|||||||
|
|
||||||
cache["k1"]!!.use { snapshot1 ->
|
cache["k1"]!!.use { snapshot1 ->
|
||||||
val inV1 = snapshot1.getSource(0).buffer()
|
val inV1 = snapshot1.getSource(0).buffer()
|
||||||
assertThat(inV1.readByte()).isEqualTo('A'.toByte())
|
assertThat(inV1.readByte()).isEqualTo('A'.code.toByte())
|
||||||
assertThat(inV1.readByte()).isEqualTo('A'.toByte())
|
assertThat(inV1.readByte()).isEqualTo('A'.code.toByte())
|
||||||
|
|
||||||
val v1Updater = cache.edit("k1")!!
|
val v1Updater = cache.edit("k1")!!
|
||||||
v1Updater.setString(0, "CCcc")
|
v1Updater.setString(0, "CCcc")
|
||||||
@@ -401,8 +401,8 @@ class DiskLruCacheTest {
|
|||||||
snapshot2.assertValue(1, "DDdd")
|
snapshot2.assertValue(1, "DDdd")
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(inV1.readByte()).isEqualTo('a'.toByte())
|
assertThat(inV1.readByte()).isEqualTo('a'.code.toByte())
|
||||||
assertThat(inV1.readByte()).isEqualTo('a'.toByte())
|
assertThat(inV1.readByte()).isEqualTo('a'.code.toByte())
|
||||||
snapshot1.assertValue(1, "BBbb")
|
snapshot1.assertValue(1, "BBbb")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.assertj.core.api.Assertions.assertThat
|
|||||||
* deterministic. All tasks are executed on-demand on the test thread by calls to [runTasks] and
|
* deterministic. All tasks are executed on-demand on the test thread by calls to [runTasks] and
|
||||||
* [advanceUntil].
|
* [advanceUntil].
|
||||||
*/
|
*/
|
||||||
class TaskFaker() {
|
class TaskFaker {
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
internal inline fun Any.assertThreadHoldsLock() {
|
internal inline fun Any.assertThreadHoldsLock() {
|
||||||
if (assertionsEnabled && !Thread.holdsLock(this)) {
|
if (assertionsEnabled && !Thread.holdsLock(this)) {
|
||||||
@@ -156,7 +156,7 @@ class TaskFaker() {
|
|||||||
val runnable = futureRunnables.removeAt(0)
|
val runnable = futureRunnables.removeAt(0)
|
||||||
currentRunnables.add(runnable)
|
currentRunnables.add(runnable)
|
||||||
if (currentRunnables.size > 1) isParallel = true
|
if (currentRunnables.size > 1) isParallel = true
|
||||||
executorService.execute(Runnable {
|
executorService.execute {
|
||||||
try {
|
try {
|
||||||
runnable.run()
|
runnable.run()
|
||||||
} finally {
|
} finally {
|
||||||
@@ -165,7 +165,7 @@ class TaskFaker() {
|
|||||||
taskRunner.notify()
|
taskRunner.notify()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
taskRunner.wait() // Wait for the coordinator to stall.
|
taskRunner.wait() // Wait for the coordinator to stall.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import java.io.IOException
|
|||||||
import java.security.KeyStore
|
import java.security.KeyStore
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
import java.security.Security
|
import java.security.Security
|
||||||
import java.util.Arrays
|
|
||||||
import javax.net.ssl.KeyManagerFactory
|
import javax.net.ssl.KeyManagerFactory
|
||||||
import javax.net.ssl.KeyStoreBuilderParameters
|
import javax.net.ssl.KeyStoreBuilderParameters
|
||||||
import javax.net.ssl.SSLContext
|
import javax.net.ssl.SSLContext
|
||||||
@@ -47,7 +46,7 @@ import okhttp3.internal.platform.Platform
|
|||||||
* Install OpenSC separately. On a mac `brew cast install opensc`.
|
* Install OpenSC separately. On a mac `brew cast install opensc`.
|
||||||
*/
|
*/
|
||||||
@SuppressSignatureCheck
|
@SuppressSignatureCheck
|
||||||
class YubikeyClientAuth() {
|
class YubikeyClientAuth {
|
||||||
fun run() {
|
fun run() {
|
||||||
// The typical PKCS11 slot, may vary with different hardware.
|
// The typical PKCS11 slot, may vary with different hardware.
|
||||||
val slot = 0
|
val slot = 0
|
||||||
@@ -61,11 +60,11 @@ class YubikeyClientAuth() {
|
|||||||
|
|
||||||
val callbackHandler = ConsoleCallbackHandler
|
val callbackHandler = ConsoleCallbackHandler
|
||||||
|
|
||||||
val builderList: List<KeyStore.Builder> = Arrays.asList(
|
val builderList: List<KeyStore.Builder> = listOf(
|
||||||
KeyStore.Builder.newInstance("PKCS11", null, KeyStore.CallbackHandlerProtection(callbackHandler))
|
KeyStore.Builder.newInstance("PKCS11", null, KeyStore.CallbackHandlerProtection(callbackHandler))
|
||||||
|
|
||||||
// Example if you want to combine multiple keystore types
|
// Example if you want to combine multiple keystore types
|
||||||
// KeyStore.Builder.newInstance("PKCS12", null, File("keystore.p12"), PasswordProtection("rosebud".toCharArray()))
|
// KeyStore.Builder.newInstance("PKCS12", null, File("keystore.p12"), PasswordProtection("rosebud".toCharArray()))
|
||||||
)
|
)
|
||||||
|
|
||||||
val keyManagerFactory = KeyManagerFactory.getInstance("NewSunX509")
|
val keyManagerFactory = KeyManagerFactory.getInstance("NewSunX509")
|
||||||
|
|||||||
Reference in New Issue
Block a user