mirror of
https://github.com/square/okhttp.git
synced 2025-04-19 07:42:15 +03:00
Split okhttp core into Android and JVM (#8600)
This commit is contained in:
parent
6947be1baa
commit
5b2a1e139e
@ -23,6 +23,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import okhttp3.internal.platform.AndroidPlatform
|
||||
import okio.IOException
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
@ -31,6 +32,9 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
val client = OkHttpClient()
|
||||
|
||||
// Ensure we are compiling against the right variant
|
||||
println(AndroidPlatform.isSupported)
|
||||
|
||||
val url = "https://github.com/square/okhttp".toHttpUrl()
|
||||
println(url.topPrivateDomain())
|
||||
|
||||
|
118
build.gradle.kts
118
build.gradle.kts
@ -8,6 +8,7 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.jetbrains.dokka.gradle.DokkaTaskPartial
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension
|
||||
import java.net.URI
|
||||
@ -93,11 +94,16 @@ subprojects {
|
||||
|
||||
apply(plugin = "checkstyle")
|
||||
apply(plugin = "ru.vyarus.animalsniffer")
|
||||
apply(plugin = "biz.aQute.bnd.builder")
|
||||
apply(plugin = "io.github.usefulness.maven-sympathy")
|
||||
|
||||
// The 'java' plugin has been applied, but it is not compatible with the Android plugins.
|
||||
// These are applied inside the okhttp module for that case specifically
|
||||
if (project.name != "okhttp") {
|
||||
apply(plugin = "biz.aQute.bnd.builder")
|
||||
apply(plugin = "io.github.usefulness.maven-sympathy")
|
||||
}
|
||||
|
||||
// Skip samples parent
|
||||
if (project.buildFile.exists()) {
|
||||
if (project.buildFile.exists() && project.name != "okhttp") {
|
||||
apply(plugin = "com.android.lint")
|
||||
|
||||
dependencies {
|
||||
@ -109,9 +115,11 @@ subprojects {
|
||||
options.encoding = Charsets.UTF_8.toString()
|
||||
}
|
||||
|
||||
configure<JavaPluginExtension> {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
if (plugins.hasPlugin(JavaBasePlugin::class.java)) {
|
||||
extensions.configure<JavaPluginExtension> {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,33 +134,38 @@ subprojects {
|
||||
}
|
||||
}
|
||||
|
||||
configure<CheckstyleExtension> {
|
||||
config = resources.text.fromArchiveEntry(checkstyleConfig, "google_checks.xml")
|
||||
toolVersion = rootProject.libs.versions.checkStyle.get()
|
||||
sourceSets = listOf(project.sourceSets["main"])
|
||||
// Handled in :okhttp directly
|
||||
if (project.name != "okhttp") {
|
||||
configure<CheckstyleExtension> {
|
||||
config = resources.text.fromArchiveEntry(checkstyleConfig, "google_checks.xml")
|
||||
toolVersion = rootProject.libs.versions.checkStyle.get()
|
||||
sourceSets = listOf(project.sourceSets["main"])
|
||||
}
|
||||
|
||||
// Animal Sniffer confirms we generally don't use APIs not on Java 8.
|
||||
configure<AnimalSnifferExtension> {
|
||||
annotation = "okhttp3.internal.SuppressSignatureCheck"
|
||||
sourceSets = listOf(project.sourceSets["main"])
|
||||
}
|
||||
}
|
||||
|
||||
// Animal Sniffer confirms we generally don't use APIs not on Java 8.
|
||||
configure<AnimalSnifferExtension> {
|
||||
annotation = "okhttp3.internal.SuppressSignatureCheck"
|
||||
sourceSets = listOf(project.sourceSets["main"])
|
||||
}
|
||||
|
||||
val signature: Configuration by configurations.getting
|
||||
dependencies {
|
||||
// No dependency requirements for testing-support.
|
||||
if (project.name == "okhttp-testing-support") return@dependencies
|
||||
|
||||
// okhttp configured specifically.
|
||||
if (project.name == "okhttp") return@dependencies
|
||||
|
||||
if (project.name == "mockwebserver3-junit5") {
|
||||
// JUnit 5's APIs need java.util.function.Function and java.util.Optional from API 24.
|
||||
signature(rootProject.libs.signature.android.apilevel24) { artifact { type = "signature" } }
|
||||
"signature"(rootProject.libs.signature.android.apilevel24) { artifact { type = "signature" } }
|
||||
} else {
|
||||
// Everything else requires Android API 21+.
|
||||
signature(rootProject.libs.signature.android.apilevel21) { artifact { type = "signature" } }
|
||||
"signature"(rootProject.libs.signature.android.apilevel21) { artifact { type = "signature" } }
|
||||
}
|
||||
|
||||
// OkHttp requires Java 8+.
|
||||
signature(rootProject.libs.codehaus.signature.java18) { artifact { type = "signature" } }
|
||||
"signature"(rootProject.libs.codehaus.signature.java18) { artifact { type = "signature" } }
|
||||
}
|
||||
|
||||
val javaVersionSetting =
|
||||
@ -175,10 +188,15 @@ subprojects {
|
||||
}
|
||||
}
|
||||
|
||||
val testRuntimeOnly: Configuration by configurations.getting
|
||||
dependencies {
|
||||
testRuntimeOnly(rootProject.libs.junit.jupiter.engine)
|
||||
testRuntimeOnly(rootProject.libs.junit.vintage.engine)
|
||||
val platform = System.getProperty("okhttp.platform", "jdk9")
|
||||
val testJavaVersion = System.getProperty("test.java.version", "21").toInt()
|
||||
|
||||
if (project.name != "okhttp") {
|
||||
val testRuntimeOnly: Configuration by configurations.getting
|
||||
dependencies {
|
||||
testRuntimeOnly(rootProject.libs.junit.jupiter.engine)
|
||||
testRuntimeOnly(rootProject.libs.junit.vintage.engine)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
@ -211,25 +229,30 @@ subprojects {
|
||||
tasks.withType<Test>().configureEach {
|
||||
environment("OKHTTP_ROOT", rootDir)
|
||||
}
|
||||
tasks.withType<KotlinJvmTest>().configureEach {
|
||||
environment("OKHTTP_ROOT", rootDir)
|
||||
}
|
||||
|
||||
if (platform == "jdk8alpn") {
|
||||
// Add alpn-boot on Java 8 so we can use HTTP/2 without a stable API.
|
||||
val alpnBootVersion = alpnBootVersion()
|
||||
if (alpnBootVersion != null) {
|
||||
val alpnBootJar = configurations.detachedConfiguration(
|
||||
dependencies.create("org.mortbay.jetty.alpn:alpn-boot:$alpnBootVersion")
|
||||
).singleFile
|
||||
tasks.withType<Test> {
|
||||
jvmArgs("-Xbootclasspath/p:${alpnBootJar}")
|
||||
if (project.name != "okhttp") {
|
||||
if (platform == "jdk8alpn") {
|
||||
// Add alpn-boot on Java 8 so we can use HTTP/2 without a stable API.
|
||||
val alpnBootVersion = alpnBootVersion()
|
||||
if (alpnBootVersion != null) {
|
||||
val alpnBootJar = configurations.detachedConfiguration(
|
||||
dependencies.create("org.mortbay.jetty.alpn:alpn-boot:$alpnBootVersion")
|
||||
).singleFile
|
||||
tasks.withType<Test> {
|
||||
jvmArgs("-Xbootclasspath/p:${alpnBootJar}")
|
||||
}
|
||||
}
|
||||
} else if (platform == "conscrypt") {
|
||||
dependencies {
|
||||
// testRuntimeOnly(rootProject.libs.conscrypt.openjdk)
|
||||
}
|
||||
} else if (platform == "openjsse") {
|
||||
dependencies {
|
||||
// testRuntimeOnly(rootProject.libs.openjsse)
|
||||
}
|
||||
}
|
||||
} else if (platform == "conscrypt") {
|
||||
dependencies {
|
||||
testRuntimeOnly(rootProject.libs.conscrypt.openjdk)
|
||||
}
|
||||
} else if (platform == "openjsse") {
|
||||
dependencies {
|
||||
testRuntimeOnly(rootProject.libs.openjsse)
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,6 +269,11 @@ subprojects {
|
||||
languageSettings.optIn("okhttp3.ExperimentalOkHttpApi")
|
||||
}
|
||||
}
|
||||
plugins.withId("org.jetbrains.kotlin.multiplatform") {
|
||||
kotlinExtension.sourceSets.configureEach {
|
||||
languageSettings.optIn("okhttp3.ExperimentalOkHttpApi")
|
||||
}
|
||||
}
|
||||
plugins.withId("org.jetbrains.kotlin.android") {
|
||||
kotlinExtension.sourceSets.configureEach {
|
||||
languageSettings.optIn("okhttp3.ExperimentalOkHttpApi")
|
||||
@ -316,6 +344,14 @@ subprojects {
|
||||
}
|
||||
}
|
||||
|
||||
plugins.withId("org.jetbrains.kotlin.jvm") {
|
||||
val test = tasks.named("test")
|
||||
tasks.register("jvmTest") {
|
||||
description = "Get 'gradlew jvmTest' to run the tests of JVM-only modules"
|
||||
dependsOn(test)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.wrapper {
|
||||
distributionType = Wrapper.DistributionType.ALL
|
||||
}
|
||||
|
1
buildSrc/settings.gradle.kts
Normal file
1
buildSrc/settings.gradle.kts
Normal file
@ -0,0 +1 @@
|
||||
rootProject.name = "okhttp-buildSrc"
|
@ -2,6 +2,7 @@ org.gradle.caching=true
|
||||
org.gradle.parallel=true
|
||||
|
||||
android.useAndroidX=true
|
||||
kotlin.mpp.applyDefaultHierarchyTemplate=false
|
||||
|
||||
androidBuild=false
|
||||
graalBuild=false
|
||||
|
@ -47,7 +47,7 @@ gradlePlugin-androidJunit5 = "de.mannodermaus.gradle.plugins:android-junit5:1.11
|
||||
gradlePlugin-animalsniffer = "ru.vyarus:gradle-animalsniffer-plugin:1.7.2"
|
||||
gradlePlugin-binaryCompatibilityValidator = "org.jetbrains.kotlinx.binary-compatibility-validator:org.jetbrains.kotlinx.binary-compatibility-validator.gradle.plugin:0.17.0"
|
||||
gradlePlugin-bnd = { module = "biz.aQute.bnd:biz.aQute.bnd.gradle", version.ref = "biz-aQute-bnd" }
|
||||
gradlePlugin-dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.20"
|
||||
gradlePlugin-dokka = "org.jetbrains.dokka:dokka-gradle-plugin:2.0.0"
|
||||
gradlePlugin-errorprone = "net.ltgt.gradle:gradle-errorprone-plugin:4.1.0"
|
||||
gradlePlugin-graalvmBuildTools = "org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin:0.10.4"
|
||||
gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "org-jetbrains-kotlin" }
|
||||
@ -78,7 +78,6 @@ kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "
|
||||
kotlin-stdlib-osgi = { module = "org.jetbrains.kotlin:kotlin-osgi-bundle", version.ref = "org-jetbrains-kotlin" }
|
||||
kotlin-test-annotations = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "org-jetbrains-kotlin" }
|
||||
kotlin-test-common = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "org-jetbrains-kotlin" }
|
||||
kotlin-test-js = { module = "org.jetbrains.kotlin:kotlin-test-js", version.ref = "org-jetbrains-kotlin" }
|
||||
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "org-jetbrains-kotlin" }
|
||||
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "org-jetbrains-coroutines" }
|
||||
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "org-jetbrains-coroutines" }
|
||||
|
@ -19,6 +19,7 @@ dependencies {
|
||||
api(libs.junit)
|
||||
|
||||
testImplementation(libs.assertk)
|
||||
testImplementation(libs.junit.vintage.engine)
|
||||
}
|
||||
|
||||
mavenPublishing {
|
||||
|
@ -55,7 +55,6 @@ tasks.shadowJar {
|
||||
mergeServiceFiles()
|
||||
}
|
||||
|
||||
|
||||
if (testJavaVersion >= 11) {
|
||||
apply(plugin = "org.graalvm.buildtools.native")
|
||||
|
||||
|
@ -64,6 +64,8 @@ dependencies {
|
||||
testImplementation(libs.robolectric)
|
||||
testImplementation(libs.androidx.espresso.core)
|
||||
testImplementation(libs.squareup.okio.fakefilesystem)
|
||||
testImplementation(projects.okhttpTestingSupport)
|
||||
testImplementation(rootProject.libs.conscrypt.openjdk)
|
||||
|
||||
androidTestImplementation(projects.okhttpTls)
|
||||
androidTestImplementation(libs.assertk)
|
||||
@ -71,7 +73,10 @@ dependencies {
|
||||
androidTestImplementation(libs.androidx.test.runner)
|
||||
}
|
||||
|
||||
mavenPublishing {
|
||||
// AGP 7.2 embeds Dokka 4, which breaks publishing. Android modules are hardcoded to generate Javadoc instead of Gfm.
|
||||
configure(com.vanniktech.maven.publish.AndroidSingleVariantLibrary(publishJavadocJar=false))
|
||||
}
|
||||
// TODO remove this whole module after merging with okhttp
|
||||
// Conflicts with KMP :okhttp outputs
|
||||
|
||||
//mavenPublishing {
|
||||
// // AGP 7.2 embeds Dokka 4, which breaks publishing. Android modules are hardcoded to generate Javadoc instead of Gfm.
|
||||
// configure(com.vanniktech.maven.publish.AndroidSingleVariantLibrary(publishJavadocJar=false))
|
||||
//}
|
||||
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package okhttp3.internal.platform.android
|
||||
package okhttp3.android
|
||||
|
||||
import java.security.Provider
|
||||
import javax.net.ssl.SSLContext
|
||||
@ -22,7 +22,11 @@ import okhttp3.DelegatingSSLSocket
|
||||
import okhttp3.DelegatingSSLSocketFactory
|
||||
import okhttp3.Protocol.HTTP_1_1
|
||||
import okhttp3.Protocol.HTTP_2
|
||||
import okhttp3.testing.PlatformRule
|
||||
import okhttp3.internal.platform.android.AndroidSocketAdapter
|
||||
import okhttp3.internal.platform.android.ConscryptSocketAdapter
|
||||
import okhttp3.internal.platform.android.DeferredSocketAdapter
|
||||
import okhttp3.internal.platform.android.SocketAdapter
|
||||
import okhttp3.internal.platform.android.StandardAndroidSocketAdapter
|
||||
import org.conscrypt.Conscrypt
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
@ -30,20 +34,13 @@ import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assume.assumeFalse
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.extension.RegisterExtension
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
|
||||
class AndroidSocketAdapterTest {
|
||||
@RegisterExtension @JvmField
|
||||
val platform = PlatformRule()
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
platform.assumeConscrypt()
|
||||
}
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.ParameterizedRobolectricTestRunner
|
||||
import org.robolectric.ParameterizedRobolectricTestRunner.Parameters
|
||||
|
||||
@RunWith(ParameterizedRobolectricTestRunner::class)
|
||||
class AndroidSocketAdapterTest(val adapter: SocketAdapter) {
|
||||
val context: SSLContext by lazy {
|
||||
val provider: Provider = Conscrypt.newProviderBuilder().provideTrustManager(true).build()
|
||||
|
||||
@ -52,9 +49,8 @@ class AndroidSocketAdapterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
fun testMatchesSupportedSocket(adapter: SocketAdapter) {
|
||||
@Test
|
||||
fun testMatchesSupportedSocket() {
|
||||
val socketFactory = context.socketFactory
|
||||
|
||||
val sslSocket = socketFactory.createSocket() as SSLSocket
|
||||
@ -65,27 +61,24 @@ class AndroidSocketAdapterTest {
|
||||
assertNull(adapter.getSelectedProtocol(sslSocket))
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
fun testMatchesSupportedAndroidSocketFactory(adapter: SocketAdapter) {
|
||||
@Test
|
||||
fun testMatchesSupportedAndroidSocketFactory() {
|
||||
assumeTrue(adapter is StandardAndroidSocketAdapter)
|
||||
|
||||
assertTrue(adapter.matchesSocketFactory(context.socketFactory))
|
||||
assertNotNull(adapter.trustManager(context.socketFactory))
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
fun testDoesntMatchSupportedCustomSocketFactory(adapter: SocketAdapter) {
|
||||
@Test
|
||||
fun testDoesntMatchSupportedCustomSocketFactory() {
|
||||
assumeFalse(adapter is StandardAndroidSocketAdapter)
|
||||
|
||||
assertFalse(adapter.matchesSocketFactory(context.socketFactory))
|
||||
assertNull(adapter.trustManager(context.socketFactory))
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
fun testCustomSocket(adapter: SocketAdapter) {
|
||||
@Test
|
||||
fun testCustomSocket() {
|
||||
val socketFactory = DelegatingSSLSocketFactory(context.socketFactory)
|
||||
|
||||
assertFalse(adapter.matchesSocketFactory(socketFactory))
|
||||
@ -101,6 +94,7 @@ class AndroidSocketAdapterTest {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@Parameters(name = "{0}")
|
||||
fun data(): Collection<SocketAdapter> {
|
||||
return listOfNotNull(
|
||||
DeferredSocketAdapter(ConscryptSocketAdapter.factory),
|
@ -40,7 +40,7 @@ import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(
|
||||
sdk = [30],
|
||||
sdk = [21, 26, 30, 33, 35],
|
||||
)
|
||||
class RobolectricOkHttpClientTest {
|
||||
private lateinit var context: Context
|
||||
|
@ -9,6 +9,8 @@ dependencies {
|
||||
testImplementation(libs.assertk)
|
||||
testImplementation(libs.junit.jupiter.api)
|
||||
testImplementation(libs.junit.jupiter.params)
|
||||
|
||||
testImplementation(rootProject.libs.junit.jupiter.engine)
|
||||
}
|
||||
|
||||
animalsniffer {
|
||||
|
68
okhttp-osgi-tests/build.gradle.kts
Normal file
68
okhttp-osgi-tests/build.gradle.kts
Normal file
@ -0,0 +1,68 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.okhttp)
|
||||
implementation(projects.okhttpBrotli)
|
||||
implementation(projects.okhttpCoroutines)
|
||||
implementation(projects.okhttpDnsoverhttps)
|
||||
implementation(projects.loggingInterceptor)
|
||||
implementation(projects.okhttpSse)
|
||||
implementation(projects.okhttpTls)
|
||||
implementation(projects.okhttpUrlconnection)
|
||||
|
||||
testImplementation(projects.okhttpTestingSupport)
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.kotlin.test.common)
|
||||
testImplementation(libs.kotlin.test.junit)
|
||||
testImplementation(libs.assertk)
|
||||
|
||||
testImplementation(libs.aqute.resolve)
|
||||
}
|
||||
|
||||
normalization {
|
||||
runtimeClasspath {
|
||||
/*
|
||||
- The below two ignored files are generated during test execution
|
||||
by the test: okhttp/src/test/java/okhttp3/osgi/OsgiTest.java
|
||||
|
||||
- The compressed index.xml file contains a timestamp property which
|
||||
changes with every test execution, such that running the test
|
||||
actually changes the test classpath itself. This means that it
|
||||
can"t benefit from incremental build acceleration, because on every
|
||||
execution it sees that the classpath has changed, and so to be
|
||||
safe, it needs to re-run.
|
||||
|
||||
- This is unfortunate, because actually it would be safe to declare
|
||||
the task as up-to-date, because these two files, which are based on
|
||||
the generated index.xml, are outputs, not inputs. We can be sure of
|
||||
this because they are deleted in the @BeforeEach method of the
|
||||
OsgiTest test class.
|
||||
|
||||
- To enable the benefit of incremental builds, we can ask Gradle
|
||||
to ignore these two files when considering whether the classpath
|
||||
has changed. That is the purpose of this normalization block.
|
||||
*/
|
||||
ignore("okhttp3/osgi/workspace/cnf/repo/index.xml.gz")
|
||||
ignore("okhttp3/osgi/workspace/cnf/repo/index.xml.gz.sha")
|
||||
}
|
||||
}
|
||||
|
||||
// Expose OSGi jars to the test environment.
|
||||
val osgiTestDeploy: Configuration by configurations.creating
|
||||
|
||||
val test = tasks.named("test")
|
||||
val copyOsgiTestDeployment = tasks.register<Copy>("copyOsgiTestDeployment") {
|
||||
from(osgiTestDeploy)
|
||||
into(layout.buildDirectory.dir("resources/test/okhttp3/osgi/deployments"))
|
||||
}
|
||||
|
||||
test.configure {
|
||||
dependsOn(copyOsgiTestDeployment)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
osgiTestDeploy(libs.eclipseOsgi)
|
||||
osgiTestDeploy(libs.kotlin.stdlib.osgi)
|
||||
}
|
@ -14,6 +14,8 @@ dependencies {
|
||||
api(libs.conscrypt.openjdk)
|
||||
api(libs.openjsse)
|
||||
|
||||
api(rootProject.libs.junit.jupiter.engine)
|
||||
|
||||
api(variantOf(libs.amazonCorretto) {
|
||||
classifier("linux-x86_64")
|
||||
})
|
||||
|
@ -360,15 +360,17 @@ class TaskFaker : Closeable {
|
||||
timeout: Long,
|
||||
unit: TimeUnit,
|
||||
): T? {
|
||||
taskRunner.withLock {
|
||||
return taskRunner.withLock {
|
||||
val waitUntil = nanoTime + unit.toNanos(timeout)
|
||||
while (true) {
|
||||
val result = poll()
|
||||
if (result != null) return result
|
||||
if (nanoTime >= waitUntil) return null
|
||||
if (result != null) return@withLock result
|
||||
if (nanoTime >= waitUntil) return@withLock null
|
||||
val editCountBefore = editCount
|
||||
yieldUntil { nanoTime >= waitUntil || editCount > editCountBefore }
|
||||
}
|
||||
// TODO report compiler bug
|
||||
TODO("Can't get here")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import okhttp3.internal.platform.Jdk8WithJettyBootPlatform
|
||||
import okhttp3.internal.platform.Jdk9Platform
|
||||
import okhttp3.internal.platform.OpenJSSEPlatform
|
||||
import okhttp3.internal.platform.Platform
|
||||
import okhttp3.internal.platform.PlatformRegistry
|
||||
import okhttp3.tls.HandshakeCertificates
|
||||
import okhttp3.tls.HeldCertificate
|
||||
import okhttp3.tls.internal.TlsUtil.localhost
|
||||
@ -435,9 +436,14 @@ open class PlatformRule
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getPlatformSystemProperty(): String {
|
||||
fun getPlatformSystemProperty(): String? {
|
||||
var property: String? = System.getProperty(PROPERTY_NAME)
|
||||
|
||||
if (PlatformRegistry.isAndroid) {
|
||||
// Platforms below are unavailable on Android
|
||||
return null
|
||||
}
|
||||
|
||||
if (property == null) {
|
||||
property =
|
||||
when (Platform.get()) {
|
||||
|
1294
okhttp/api/jvm/okhttp.api
Normal file
1294
okhttp/api/jvm/okhttp.api
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,24 @@
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import aQute.bnd.gradle.BundleTaskExtension
|
||||
import com.vanniktech.maven.publish.JavadocJar
|
||||
import com.vanniktech.maven.publish.KotlinJvm
|
||||
import com.vanniktech.maven.publish.KotlinMultiplatform
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension
|
||||
import java.util.Base64
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
kotlin("multiplatform")
|
||||
id("com.android.library")
|
||||
kotlin("plugin.serialization")
|
||||
id("org.jetbrains.dokka")
|
||||
id("com.vanniktech.maven.publish.base")
|
||||
id("binary-compatibility-validator")
|
||||
}
|
||||
|
||||
val platform = System.getProperty("okhttp.platform", "jdk9")
|
||||
val testJavaVersion = System.getProperty("test.java.version", "21").toInt()
|
||||
|
||||
fun ByteArray.toByteStringExpression(): String {
|
||||
return "\"${Base64.getEncoder().encodeToString(this@toByteStringExpression)}\".decodeBase64()!!"
|
||||
}
|
||||
@ -17,15 +26,15 @@ fun ByteArray.toByteStringExpression(): String {
|
||||
val copyKotlinTemplates = tasks.register<Copy>("copyKotlinTemplates") {
|
||||
val kotlinTemplatesOutput = layout.buildDirectory.dir("generated/sources/kotlinTemplates")
|
||||
|
||||
from("src/main/kotlinTemplates")
|
||||
from("src/commonJvmAndroid/kotlinTemplates")
|
||||
into(kotlinTemplatesOutput)
|
||||
|
||||
// Tag as an input to regenerate after an update
|
||||
inputs.file("src/test/resources/okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz")
|
||||
inputs.file("src/jvmTest/resources/okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz")
|
||||
|
||||
filteringCharset = Charsets.UTF_8.toString()
|
||||
|
||||
val databaseGz = project.file("src/test/resources/okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz")
|
||||
val databaseGz = project.file("src/jvmTest/resources/okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz")
|
||||
val listBytes = databaseGz.readBytes().toByteStringExpression()
|
||||
|
||||
expand(
|
||||
@ -52,125 +61,192 @@ val generateIdnaMappingTable = tasks.register<JavaExec>("generateIdnaMappingTabl
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(8)
|
||||
|
||||
jvm {
|
||||
// withJava() /* <- cannot be used when the Android Plugin is present */
|
||||
}
|
||||
|
||||
androidTarget {
|
||||
compilerOptions {
|
||||
jvmTarget.set(JvmTarget.JVM_17)
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
getByName("main") {
|
||||
val commonJvmAndroid = create("commonJvmAndroid") {
|
||||
dependsOn(commonMain.get())
|
||||
|
||||
kotlin.srcDir(copyKotlinTemplates.map { it.outputs })
|
||||
kotlin.srcDir(generateIdnaMappingTable.map { it.outputs })
|
||||
|
||||
dependencies {
|
||||
api(libs.squareup.okio)
|
||||
api(libs.kotlin.stdlib)
|
||||
|
||||
compileOnly(libs.findbugs.jsr305)
|
||||
compileOnly(libs.animalsniffer.annotations)
|
||||
}
|
||||
}
|
||||
|
||||
androidMain {
|
||||
dependsOn(commonJvmAndroid)
|
||||
dependencies {
|
||||
compileOnly(libs.bouncycastle.bcprov)
|
||||
compileOnly(libs.bouncycastle.bctls)
|
||||
compileOnly(libs.conscrypt.openjdk)
|
||||
}
|
||||
}
|
||||
|
||||
jvmMain {
|
||||
dependsOn(commonJvmAndroid)
|
||||
|
||||
dependencies {
|
||||
// These compileOnly dependencies must also be listed in the OSGi configuration above.
|
||||
compileOnly(libs.conscrypt.openjdk)
|
||||
compileOnly(libs.bouncycastle.bcprov)
|
||||
compileOnly(libs.bouncycastle.bctls)
|
||||
|
||||
// graal build support
|
||||
compileOnly(libs.nativeImageSvm)
|
||||
compileOnly(libs.openjsse)
|
||||
}
|
||||
}
|
||||
|
||||
val jvmTest by getting {
|
||||
dependencies {
|
||||
implementation(projects.okhttpTestingSupport)
|
||||
implementation(libs.assertk)
|
||||
implementation(libs.kotlin.test.annotations)
|
||||
implementation(libs.kotlin.test.common)
|
||||
implementation(libs.kotlinx.serialization.core)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
implementation(projects.okhttpJavaNetCookiejar)
|
||||
implementation(projects.okhttpTls)
|
||||
implementation(projects.okhttpUrlconnection)
|
||||
implementation(projects.mockwebserver3)
|
||||
implementation(projects.mockwebserver3Junit4)
|
||||
implementation(projects.mockwebserver3Junit5)
|
||||
implementation(projects.mockwebserver)
|
||||
implementation(projects.loggingInterceptor)
|
||||
implementation(projects.okhttpBrotli)
|
||||
implementation(projects.okhttpDnsoverhttps)
|
||||
implementation(projects.okhttpIdnaMappingTable)
|
||||
implementation(projects.okhttpSse)
|
||||
implementation(projects.okhttpCoroutines)
|
||||
implementation(libs.kotlinx.coroutines.core)
|
||||
implementation(libs.squareup.moshi)
|
||||
implementation(libs.squareup.moshi.kotlin)
|
||||
implementation(libs.squareup.okio.fakefilesystem)
|
||||
implementation(libs.conscrypt.openjdk)
|
||||
implementation(libs.junit)
|
||||
implementation(libs.junit.jupiter.api)
|
||||
implementation(libs.junit.jupiter.params)
|
||||
implementation(libs.kotlin.test.junit)
|
||||
implementation(libs.openjsse)
|
||||
compileOnly(libs.findbugs.jsr305)
|
||||
|
||||
implementation(libs.junit.jupiter.engine)
|
||||
implementation(libs.junit.vintage.engine)
|
||||
|
||||
if (platform == "conscrypt") {
|
||||
implementation(rootProject.libs.conscrypt.openjdk)
|
||||
} else if (platform == "openjsse") {
|
||||
implementation(rootProject.libs.openjsse)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.applyOsgi(
|
||||
"Export-Package: okhttp3,okhttp3.internal.*;okhttpinternal=true;mandatory:=okhttpinternal",
|
||||
"Import-Package: " +
|
||||
"android.*;resolution:=optional," +
|
||||
"com.oracle.svm.core.annotate;resolution:=optional," +
|
||||
"com.oracle.svm.core.configure;resolution:=optional," +
|
||||
"dalvik.system;resolution:=optional," +
|
||||
"org.conscrypt;resolution:=optional," +
|
||||
"org.bouncycastle.*;resolution:=optional," +
|
||||
"org.openjsse.*;resolution:=optional," +
|
||||
"org.graalvm.nativeimage;resolution:=optional," +
|
||||
"org.graalvm.nativeimage.hosted;resolution:=optional," +
|
||||
"sun.security.ssl;resolution:=optional,*",
|
||||
"Automatic-Module-Name: okhttp3",
|
||||
"Bundle-SymbolicName: com.squareup.okhttp3"
|
||||
)
|
||||
|
||||
normalization {
|
||||
runtimeClasspath {
|
||||
/*
|
||||
- The below two ignored files are generated during test execution
|
||||
by the test: okhttp/src/test/java/okhttp3/osgi/OsgiTest.java
|
||||
|
||||
- The compressed index.xml file contains a timestamp property which
|
||||
changes with every test execution, such that running the test
|
||||
actually changes the test classpath itself. This means that it
|
||||
can"t benefit from incremental build acceleration, because on every
|
||||
execution it sees that the classpath has changed, and so to be
|
||||
safe, it needs to re-run.
|
||||
|
||||
- This is unfortunate, because actually it would be safe to declare
|
||||
the task as up-to-date, because these two files, which are based on
|
||||
the generated index.xml, are outputs, not inputs. We can be sure of
|
||||
this because they are deleted in the @BeforeEach method of the
|
||||
OsgiTest test class.
|
||||
|
||||
- To enable the benefit of incremental builds, we can ask Gradle
|
||||
to ignore these two files when considering whether the classpath
|
||||
has changed. That is the purpose of this normalization block.
|
||||
*/
|
||||
ignore("okhttp3/osgi/workspace/cnf/repo/index.xml.gz")
|
||||
ignore("okhttp3/osgi/workspace/cnf/repo/index.xml.gz.sha")
|
||||
if (platform == "jdk8alpn") {
|
||||
// Add alpn-boot on Java 8 so we can use HTTP/2 without a stable API.
|
||||
val alpnBootVersion = alpnBootVersion()
|
||||
if (alpnBootVersion != null) {
|
||||
val alpnBootJar = configurations.detachedConfiguration(
|
||||
dependencies.create("org.mortbay.jetty.alpn:alpn-boot:$alpnBootVersion")
|
||||
).singleFile
|
||||
tasks.withType<Test> {
|
||||
jvmArgs("-Xbootclasspath/p:${alpnBootJar}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Expose OSGi jars to the test environment.
|
||||
val osgiTestDeploy: Configuration by configurations.creating
|
||||
android {
|
||||
compileSdk = 34
|
||||
|
||||
val test by tasks.existing(Test::class)
|
||||
val copyOsgiTestDeployment = tasks.register<Copy>("copyOsgiTestDeployment") {
|
||||
from(osgiTestDeploy)
|
||||
into(layout.buildDirectory.dir("resources/test/okhttp3/osgi/deployments"))
|
||||
namespace = "okhttp.okhttp3"
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 21
|
||||
|
||||
consumerProguardFiles("okhttp3.pro")
|
||||
}
|
||||
}
|
||||
|
||||
test.configure {
|
||||
dependsOn(copyOsgiTestDeployment)
|
||||
// Hack to make BundleTaskExtension pass briefly
|
||||
project.extensions
|
||||
.getByType(JavaPluginExtension::class.java)
|
||||
.sourceSets.create("main")
|
||||
|
||||
// Call the convention when the task has finished, to modify the jar to contain OSGi metadata.
|
||||
tasks.named<Jar>("jvmJar").configure {
|
||||
val bundleExtension = extensions.create(
|
||||
BundleTaskExtension.NAME,
|
||||
BundleTaskExtension::class.java,
|
||||
this,
|
||||
).apply {
|
||||
classpath(libs.kotlin.stdlib.osgi.map { it.artifacts }, tasks.named("jvmMainClasses").map { it.outputs })
|
||||
bnd(
|
||||
"Export-Package: okhttp3,okhttp3.internal.*;okhttpinternal=true;mandatory:=okhttpinternal",
|
||||
"Import-Package: " +
|
||||
"com.oracle.svm.core.annotate;resolution:=optional," +
|
||||
"com.oracle.svm.core.configure;resolution:=optional," +
|
||||
"dalvik.system;resolution:=optional," +
|
||||
"org.conscrypt;resolution:=optional," +
|
||||
"org.bouncycastle.*;resolution:=optional," +
|
||||
"org.openjsse.*;resolution:=optional," +
|
||||
"org.graalvm.nativeimage;resolution:=optional," +
|
||||
"org.graalvm.nativeimage.hosted;resolution:=optional," +
|
||||
"sun.security.ssl;resolution:=optional,*",
|
||||
"Automatic-Module-Name: okhttp3",
|
||||
"Bundle-SymbolicName: com.squareup.okhttp3"
|
||||
)
|
||||
}
|
||||
|
||||
doLast {
|
||||
bundleExtension.buildAction().execute(this)
|
||||
}
|
||||
}
|
||||
|
||||
val checkstyleConfig: Configuration by configurations.named("checkstyleConfig")
|
||||
dependencies {
|
||||
api(libs.squareup.okio)
|
||||
api(libs.kotlin.stdlib)
|
||||
// Everything else requires Android API 21+.
|
||||
"signature"(rootProject.libs.signature.android.apilevel21) { artifact { type = "signature" } }
|
||||
|
||||
// These compileOnly dependencies must also be listed in the OSGi configuration above.
|
||||
compileOnly(libs.robolectric.android)
|
||||
compileOnly(libs.bouncycastle.bcprov)
|
||||
compileOnly(libs.bouncycastle.bctls)
|
||||
compileOnly(libs.conscrypt.openjdk)
|
||||
compileOnly(libs.openjsse)
|
||||
compileOnly(libs.findbugs.jsr305)
|
||||
compileOnly(libs.animalsniffer.annotations)
|
||||
// OkHttp requires Java 8+.
|
||||
"signature"(rootProject.libs.codehaus.signature.java18) { artifact { type = "signature" } }
|
||||
|
||||
// graal build support
|
||||
compileOnly(libs.nativeImageSvm)
|
||||
|
||||
testCompileOnly(libs.bouncycastle.bctls)
|
||||
testImplementation(projects.okhttpTestingSupport)
|
||||
testImplementation(libs.assertk)
|
||||
testImplementation(libs.kotlin.test.annotations)
|
||||
testImplementation(libs.kotlin.test.common)
|
||||
testImplementation(libs.kotlinx.serialization.core)
|
||||
testImplementation(libs.kotlinx.serialization.json)
|
||||
testImplementation(projects.okhttpJavaNetCookiejar)
|
||||
testImplementation(projects.okhttpTls)
|
||||
testImplementation(projects.okhttpUrlconnection)
|
||||
testImplementation(projects.mockwebserver3)
|
||||
testImplementation(projects.mockwebserver3Junit4)
|
||||
testImplementation(projects.mockwebserver3Junit5)
|
||||
testImplementation(projects.mockwebserver)
|
||||
testImplementation(projects.loggingInterceptor)
|
||||
testImplementation(projects.okhttpBrotli)
|
||||
testImplementation(projects.okhttpDnsoverhttps)
|
||||
testImplementation(projects.okhttpIdnaMappingTable)
|
||||
testImplementation(projects.okhttpSse)
|
||||
testImplementation(projects.okhttpCoroutines)
|
||||
testImplementation(libs.kotlinx.coroutines.core)
|
||||
testImplementation(libs.squareup.moshi)
|
||||
testImplementation(libs.squareup.moshi.kotlin)
|
||||
testImplementation(libs.squareup.okio.fakefilesystem)
|
||||
testImplementation(libs.conscrypt.openjdk)
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.junit.jupiter.api)
|
||||
testImplementation(libs.junit.jupiter.params)
|
||||
testImplementation(libs.kotlin.test.junit)
|
||||
testImplementation(libs.openjsse)
|
||||
testImplementation(libs.aqute.resolve)
|
||||
testCompileOnly(libs.findbugs.jsr305)
|
||||
|
||||
osgiTestDeploy(libs.eclipseOsgi)
|
||||
osgiTestDeploy(libs.kotlin.stdlib.osgi)
|
||||
checkstyleConfig(rootProject.libs.checkStyle) {
|
||||
isTransitive = false
|
||||
}
|
||||
}
|
||||
|
||||
// Animal Sniffer confirms we generally don't use APIs not on Java 8.
|
||||
configure<AnimalSnifferExtension> {
|
||||
annotation = "okhttp3.internal.SuppressSignatureCheck"
|
||||
sourceSets = listOf(project.sourceSets["main"])
|
||||
}
|
||||
|
||||
configure<CheckstyleExtension> {
|
||||
config = resources.text.fromArchiveEntry(checkstyleConfig, "google_checks.xml")
|
||||
toolVersion = rootProject.libs.versions.checkStyle.get()
|
||||
// TODO switch out checkstyle to use something supporting KMP
|
||||
sourceSets = listOf(project.sourceSets["main"])
|
||||
}
|
||||
|
||||
apply(plugin = "io.github.usefulness.maven-sympathy")
|
||||
|
||||
mavenPublishing {
|
||||
configure(KotlinJvm(javadocJar = JavadocJar.Empty()))
|
||||
configure(KotlinMultiplatform(javadocJar = JavadocJar.Empty(), androidVariantsToPublish = listOf("release")))
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
-dontwarn org.codehaus.mojo.animal_sniffer.*
|
||||
|
||||
# OkHttp platform used only on JVM and when Conscrypt and other security providers are available.
|
||||
# May be used with robolectric or deliberate use of Bouncy Castle on Android
|
||||
-dontwarn okhttp3.internal.platform.**
|
||||
-dontwarn org.conscrypt.**
|
||||
-dontwarn org.bouncycastle.**
|
4
okhttp/src/androidMain/AndroidManifest.xml
Normal file
4
okhttp/src/androidMain/AndroidManifest.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="okhttp.okhttp3">
|
||||
|
||||
</manifest>
|
@ -0,0 +1,13 @@
|
||||
package okhttp3.internal.platform
|
||||
|
||||
import okhttp3.internal.platform.android.AndroidLog
|
||||
|
||||
actual object PlatformRegistry {
|
||||
actual fun findPlatform(): Platform {
|
||||
AndroidLog.enable()
|
||||
return Android10Platform.buildIfSupported() ?: AndroidPlatform.buildIfSupported()!!
|
||||
}
|
||||
|
||||
actual val isAndroid: Boolean
|
||||
get() = true
|
||||
}
|
@ -17,7 +17,6 @@ package okhttp3.internal.platform.android
|
||||
|
||||
import javax.net.ssl.SSLSocket
|
||||
import okhttp3.Protocol
|
||||
import okhttp3.internal.platform.BouncyCastlePlatform
|
||||
import okhttp3.internal.platform.Platform
|
||||
import org.bouncycastle.jsse.BCSSLSocket
|
||||
|
||||
@ -27,7 +26,7 @@ import org.bouncycastle.jsse.BCSSLSocket
|
||||
class BouncyCastleSocketAdapter : SocketAdapter {
|
||||
override fun matchesSocket(sslSocket: SSLSocket): Boolean = sslSocket is BCSSLSocket
|
||||
|
||||
override fun isSupported(): Boolean = BouncyCastlePlatform.isSupported
|
||||
override fun isSupported(): Boolean = isSupported
|
||||
|
||||
override fun getSelectedProtocol(sslSocket: SSLSocket): String? {
|
||||
val s = sslSocket as BCSSLSocket
|
||||
@ -60,10 +59,20 @@ class BouncyCastleSocketAdapter : SocketAdapter {
|
||||
val factory =
|
||||
object : DeferredSocketAdapter.Factory {
|
||||
override fun matchesSocket(sslSocket: SSLSocket): Boolean {
|
||||
return BouncyCastlePlatform.isSupported && sslSocket is BCSSLSocket
|
||||
return isSupported && sslSocket is BCSSLSocket
|
||||
}
|
||||
|
||||
override fun create(sslSocket: SSLSocket): SocketAdapter = BouncyCastleSocketAdapter()
|
||||
}
|
||||
|
||||
val isSupported: Boolean =
|
||||
try {
|
||||
// Trigger an early exception over a fatal error, prefer a RuntimeException over Error.
|
||||
Class.forName("org.bouncycastle.jsse.provider.BouncyCastleJsseProvider", false, javaClass.classLoader)
|
||||
|
||||
true
|
||||
} catch (_: ClassNotFoundException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@ package okhttp3.internal.platform.android
|
||||
|
||||
import javax.net.ssl.SSLSocket
|
||||
import okhttp3.Protocol
|
||||
import okhttp3.internal.platform.ConscryptPlatform
|
||||
import okhttp3.internal.platform.Platform
|
||||
import org.conscrypt.Conscrypt
|
||||
|
||||
@ -28,7 +27,7 @@ import org.conscrypt.Conscrypt
|
||||
class ConscryptSocketAdapter : SocketAdapter {
|
||||
override fun matchesSocket(sslSocket: SSLSocket): Boolean = Conscrypt.isConscrypt(sslSocket)
|
||||
|
||||
override fun isSupported(): Boolean = ConscryptPlatform.isSupported
|
||||
override fun isSupported(): Boolean = isSupported
|
||||
|
||||
override fun getSelectedProtocol(sslSocket: SSLSocket): String? =
|
||||
when {
|
||||
@ -56,10 +55,44 @@ class ConscryptSocketAdapter : SocketAdapter {
|
||||
val factory =
|
||||
object : DeferredSocketAdapter.Factory {
|
||||
override fun matchesSocket(sslSocket: SSLSocket): Boolean {
|
||||
return ConscryptPlatform.isSupported && Conscrypt.isConscrypt(sslSocket)
|
||||
return isSupported && Conscrypt.isConscrypt(sslSocket)
|
||||
}
|
||||
|
||||
override fun create(sslSocket: SSLSocket): SocketAdapter = ConscryptSocketAdapter()
|
||||
}
|
||||
|
||||
val isSupported: Boolean =
|
||||
try {
|
||||
// Trigger an early exception over a fatal error, prefer a RuntimeException over Error.
|
||||
Class.forName("org.conscrypt.Conscrypt\$Version", false, javaClass.classLoader)
|
||||
|
||||
when {
|
||||
// Bump this version if we ever have a binary incompatibility
|
||||
Conscrypt.isAvailable() && atLeastVersion(2, 1, 0) -> true
|
||||
else -> false
|
||||
}
|
||||
} catch (e: NoClassDefFoundError) {
|
||||
false
|
||||
} catch (e: ClassNotFoundException) {
|
||||
false
|
||||
}
|
||||
|
||||
fun atLeastVersion(
|
||||
major: Int,
|
||||
minor: Int = 0,
|
||||
patch: Int = 0,
|
||||
): Boolean {
|
||||
val conscryptVersion = Conscrypt.version() ?: return false
|
||||
|
||||
if (conscryptVersion.major() != major) {
|
||||
return conscryptVersion.major() > major
|
||||
}
|
||||
|
||||
if (conscryptVersion.minor() != minor) {
|
||||
return conscryptVersion.minor() > minor
|
||||
}
|
||||
|
||||
return conscryptVersion.patch() >= patch
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package okhttp3
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import java.net.Proxy
|
||||
import java.net.ProxySelector
|
||||
import java.net.Socket
|
||||
@ -1113,7 +1112,6 @@ open class OkHttpClient internal constructor(
|
||||
*
|
||||
* The default value is 0 which imposes no timeout.
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
@IgnoreJRERequirement
|
||||
fun callTimeout(duration: Duration) =
|
||||
apply {
|
||||
@ -1156,7 +1154,6 @@ open class OkHttpClient internal constructor(
|
||||
* The connect timeout is applied when connecting a TCP socket to the target host. The default
|
||||
* value is 10 seconds.
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
@IgnoreJRERequirement
|
||||
fun connectTimeout(duration: Duration) =
|
||||
apply {
|
||||
@ -1202,7 +1199,6 @@ open class OkHttpClient internal constructor(
|
||||
* @see Socket.setSoTimeout
|
||||
* @see Source.timeout
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
@IgnoreJRERequirement
|
||||
fun readTimeout(duration: Duration) =
|
||||
apply {
|
||||
@ -1249,7 +1245,6 @@ open class OkHttpClient internal constructor(
|
||||
*
|
||||
* @see Sink.timeout
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
@IgnoreJRERequirement
|
||||
fun writeTimeout(duration: Duration) =
|
||||
apply {
|
||||
@ -1303,7 +1298,6 @@ open class OkHttpClient internal constructor(
|
||||
*
|
||||
* The default value of 0 disables client-initiated pings.
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
@IgnoreJRERequirement
|
||||
fun pingInterval(duration: Duration) =
|
||||
apply {
|
||||
@ -1351,7 +1345,6 @@ open class OkHttpClient internal constructor(
|
||||
* wait for a graceful shutdown. If the server doesn't respond the web socket will be canceled.
|
||||
* The default value is 60 seconds.
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
@IgnoreJRERequirement
|
||||
fun webSocketCloseTimeout(duration: Duration) =
|
||||
apply {
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user