From 6b7b611308c49ba0182441700da613da09a1f883 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Tue, 19 Dec 2023 07:37:45 -0500 Subject: [PATCH] Remove expect/actuals (#8147) * Remove expect/actuals from okcurl * Remove expect/actuals from okhttp-coroutines * Remove expect/actuals from okhttp * Remove expect/actuals from okhttp-testing-support * Fixup build scripts --- okcurl/build.gradle.kts | 12 +- .../commonMain/kotlin/okhttp3/curl/Main.kt | 46 -- .../src/jvmMain/kotlin/okhttp3/curl/Main.kt | 26 +- .../okhttp3/curl/internal/-MainCommon.kt | 0 .../kotlin/okhttp3/curl/OkcurlTest.kt | 0 okhttp-coroutines/build.gradle.kts | 19 +- .../kotlin/okhttp3/CommonCallExtensions.kt | 20 - .../kotlin/okhttp3/JvmCallExtensions.kt | 2 +- .../jvmTest/kotlin/okhttp3/SuspendCallTest.kt | 11 +- .../kotlin/okhttp3/NonJvmCallExtensions.kt | 20 - okhttp-testing-support/build.gradle.kts | 6 +- .../kotlin/okhttp3/TestUtilCommon.kt | 7 - .../src/jvmMain/kotlin/okhttp3/TestUtilJvm.kt | 6 +- .../Http2FlowControlConnectionListener.kt | 0 okhttp/build.gradle.kts | 31 +- .../kotlin/okhttp3/-CommonPlatform.kt | 22 - .../commonMain/kotlin/okhttp3/CacheControl.kt | 178 ----- okhttp/src/commonMain/kotlin/okhttp3/Call.kt | 68 -- .../commonMain/kotlin/okhttp3/Challenge.kt | 47 -- .../src/commonMain/kotlin/okhttp3/Headers.kt | 154 ---- .../src/commonMain/kotlin/okhttp3/HttpUrl.kt | 692 ------------------ .../commonMain/kotlin/okhttp3/MediaType.kt | 68 -- .../src/commonMain/kotlin/okhttp3/Request.kt | 149 ---- .../commonMain/kotlin/okhttp3/RequestBody.kt | 113 --- .../src/commonMain/kotlin/okhttp3/Response.kt | 219 ------ .../commonMain/kotlin/okhttp3/ResponseBody.kt | 172 ----- .../commonMain/kotlin/okhttp3/TlsVersion.kt | 27 - .../jvmMain/kotlin/okhttp3/-JvmPlatform.kt | 2 +- .../jvmMain/kotlin/okhttp3/CacheControl.kt | 74 +- okhttp/src/jvmMain/kotlin/okhttp3/Call.kt | 18 +- .../kotlin/okhttp3/Callback.kt | 0 .../src/jvmMain/kotlin/okhttp3/Challenge.kt | 16 +- okhttp/src/jvmMain/kotlin/okhttp3/Headers.kt | 46 +- okhttp/src/jvmMain/kotlin/okhttp3/HttpUrl.kt | 138 ++-- .../src/jvmMain/kotlin/okhttp3/MediaType.kt | 20 +- .../kotlin/okhttp3/OkHttp.kt | 0 .../kotlin/okhttp3/Protocol.kt | 0 okhttp/src/jvmMain/kotlin/okhttp3/Request.kt | 88 +-- .../src/jvmMain/kotlin/okhttp3/RequestBody.kt | 26 +- okhttp/src/jvmMain/kotlin/okhttp3/Response.kt | 96 +-- .../jvmMain/kotlin/okhttp3/ResponseBody.kt | 30 +- .../src/jvmMain/kotlin/okhttp3/TlsVersion.kt | 2 +- .../okhttp3/internal/-CacheControlCommon.kt | 0 .../okhttp3/internal/-ChallengeCommon.kt | 0 .../kotlin/okhttp3/internal/-HeadersCommon.kt | 0 .../okhttp3/internal/-HostnamesCommon.kt | 1 - .../kotlin/okhttp3/internal/-HttpUrlCommon.kt | 20 - .../kotlin/okhttp3/internal/-HttpUrlJvm.kt | 19 +- .../okhttp3/internal/-MediaTypeCommon.kt | 0 .../kotlin/okhttp3/internal/-NormalizeJvm.kt | 2 +- .../okhttp3/internal/-RequestBodyCommon.kt | 0 .../kotlin/okhttp3/internal/-RequestCommon.kt | 0 .../okhttp3/internal/-ResponseBodyCommon.kt | 0 .../okhttp3/internal/-ResponseCommon.kt | 0 .../kotlin/okhttp3/internal/-UtilCommon.kt | 0 .../okhttp3/internal/http/HttpMethod.kt | 0 .../okhttp3/internal/http/HttpStatusCodes.kt | 0 .../okhttp3/internal/http/StatusLine.kt | 0 .../okhttp3/internal/idn/IdnaMappingTable.kt | 0 .../kotlin/okhttp3/internal/idn/Punycode.kt | 0 .../okhttp3/internal/-InternalVersion.kt | 0 .../java}/okhttp3/CacheControlTest.kt | 0 .../java}/okhttp3/CommonRequestBodyTest.kt | 0 .../java}/okhttp3/HeadersTest.kt | 0 .../java}/okhttp3/HttpUrlTest.kt | 0 .../java}/okhttp3/MediaTypeGetTest.kt | 0 .../java}/okhttp3/MediaTypeTest.kt | 0 .../java}/okhttp3/RequestCommonTest.kt | 0 .../java}/okhttp3/ResponseBodyTest.kt | 0 .../java}/okhttp3/ResponseCommonTest.kt | 0 .../okhttp3/UrlComponentEncodingTester.kt | 4 - .../okhttp3/UrlComponentEncodingTesterJvm.kt | 2 +- .../java}/okhttp3/WebPlatformToAsciiData.kt | 2 +- .../java}/okhttp3/WebPlatformToAsciiTest.kt | 0 .../java}/okhttp3/internal/HostnamesTest.kt | 0 .../okhttp3/internal/idn/PunycodeTest.kt | 0 .../resources/web-platform-test-toascii.json | 0 77 files changed, 327 insertions(+), 2394 deletions(-) delete mode 100644 okcurl/src/commonMain/kotlin/okhttp3/curl/Main.kt rename okcurl/src/{commonMain => jvmMain}/kotlin/okhttp3/curl/internal/-MainCommon.kt (100%) rename okcurl/src/{commonTest => jvmTest}/kotlin/okhttp3/curl/OkcurlTest.kt (100%) delete mode 100644 okhttp-coroutines/src/commonMain/kotlin/okhttp3/CommonCallExtensions.kt delete mode 100644 okhttp-coroutines/src/nonJvmMain/kotlin/okhttp3/NonJvmCallExtensions.kt rename okhttp-testing-support/src/{commonMain => jvmMain}/kotlin/okhttp3/TestUtilCommon.kt (87%) rename okhttp-testing-support/src/{main => jvmMain}/kotlin/okhttp3/internal/http2/Http2FlowControlConnectionListener.kt (100%) delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/-CommonPlatform.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/CacheControl.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/Call.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/Challenge.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/Headers.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/HttpUrl.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/MediaType.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/Request.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/RequestBody.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/Response.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/ResponseBody.kt delete mode 100644 okhttp/src/commonMain/kotlin/okhttp3/TlsVersion.kt rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/Callback.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/OkHttp.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/Protocol.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-CacheControlCommon.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-ChallengeCommon.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-HeadersCommon.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-HostnamesCommon.kt (99%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-HttpUrlCommon.kt (98%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-MediaTypeCommon.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-RequestBodyCommon.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-RequestCommon.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-ResponseBodyCommon.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-ResponseCommon.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/-UtilCommon.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/http/HttpMethod.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/http/HttpStatusCodes.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/http/StatusLine.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/idn/IdnaMappingTable.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlin/okhttp3/internal/idn/Punycode.kt (100%) rename okhttp/src/{commonMain => jvmMain}/kotlinTemplates/okhttp3/internal/-InternalVersion.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/CacheControlTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/CommonRequestBodyTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/HeadersTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/HttpUrlTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/MediaTypeGetTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/MediaTypeTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/RequestCommonTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/ResponseBodyTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/ResponseCommonTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/UrlComponentEncodingTester.kt (98%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/WebPlatformToAsciiData.kt (93%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/WebPlatformToAsciiTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/internal/HostnamesTest.kt (100%) rename okhttp/src/{commonTest/kotlin => jvmTest/java}/okhttp3/internal/idn/PunycodeTest.kt (100%) rename okhttp/src/{commonTest => jvmTest}/resources/web-platform-test-toascii.json (100%) diff --git a/okcurl/build.gradle.kts b/okcurl/build.gradle.kts index 240cbdb60279..55417bede5c2 100644 --- a/okcurl/build.gradle.kts +++ b/okcurl/build.gradle.kts @@ -21,21 +21,11 @@ kotlin { jvm() sourceSets { - commonMain { + val jvmMain by getting { resources.srcDir(copyResourcesTemplates.get().outputs) dependencies { api(libs.kotlin.stdlib) } - } - - commonTest { - dependencies { - api(libs.kotlin.stdlib) - implementation(kotlin("test")) - } - } - - val jvmMain by getting { dependencies { api(libs.kotlin.stdlib) api(projects.okhttp) diff --git a/okcurl/src/commonMain/kotlin/okhttp3/curl/Main.kt b/okcurl/src/commonMain/kotlin/okhttp3/curl/Main.kt deleted file mode 100644 index 2d942a18edeb..000000000000 --- a/okcurl/src/commonMain/kotlin/okhttp3/curl/Main.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2014 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package okhttp3.curl - -import com.github.ajalt.clikt.core.CliktCommand -import okhttp3.Call -import okhttp3.Request - -expect class Main() : CliktCommand { - val method: String? - - val data: String? - - val url: String? - - val referer: String? - - val headers: List? - - val showHeaders: Boolean - - val userAgent: String - - var client: Call.Factory? - - override fun run() - - fun createClient(): Call.Factory - - fun createRequest(): Request - - internal fun close() -} diff --git a/okcurl/src/jvmMain/kotlin/okhttp3/curl/Main.kt b/okcurl/src/jvmMain/kotlin/okhttp3/curl/Main.kt index dcb678a9cde7..773f5d676653 100644 --- a/okcurl/src/jvmMain/kotlin/okhttp3/curl/Main.kt +++ b/okcurl/src/jvmMain/kotlin/okhttp3/curl/Main.kt @@ -39,14 +39,14 @@ import okhttp3.internal.platform.Platform import okhttp3.logging.HttpLoggingInterceptor import okhttp3.logging.LoggingEventListener -actual class Main : CliktCommand(name = NAME, help = "A curl for the next-generation web.") { - actual val method: String? by option("-X", "--request", help="Specify request command to use") +class Main : CliktCommand(name = NAME, help = "A curl for the next-generation web.") { + val method: String? by option("-X", "--request", help="Specify request command to use") - actual val data: String? by option("-d", "--data", help="HTTP POST data") + val data: String? by option("-d", "--data", help="HTTP POST data") - actual val headers: List? by option("-H", "--header", help="Custom header to pass to server").multiple() + val headers: List? by option("-H", "--header", help="Custom header to pass to server").multiple() - actual val userAgent: String by option("-A", "--user-agent", help="User-Agent to send to server").default(NAME + "/" + versionString()) + val userAgent: String by option("-A", "--user-agent", help="User-Agent to send to server").default(NAME + "/" + versionString()) val connectTimeout: Int by option("--connect-timeout", help="Maximum time allowed for connection (seconds)").int().default(DEFAULT_TIMEOUT) @@ -58,29 +58,29 @@ actual class Main : CliktCommand(name = NAME, help = "A curl for the next-genera val allowInsecure: Boolean by option("-k", "--insecure", help="Allow connections to SSL sites without certs").flag() - actual val showHeaders: Boolean by option("-i", "--include", help="Include protocol headers in the output").flag() + val showHeaders: Boolean by option("-i", "--include", help="Include protocol headers in the output").flag() val showHttp2Frames: Boolean by option("--frames", help="Log HTTP/2 frames to STDERR").flag() - actual val referer: String? by option("-e", "--referer", help="Referer URL") + val referer: String? by option("-e", "--referer", help="Referer URL") val verbose: Boolean by option("-v", "--verbose", help="Makes $NAME verbose during the operation").flag() val sslDebug: Boolean by option(help="Output SSL Debug").flag() - actual val url: String? by argument(name = "url", help="Remote resource URL") + val url: String? by argument(name = "url", help="Remote resource URL") - actual var client: Call.Factory? = null + var client: Call.Factory? = null - actual override fun run() { + override fun run() { LoggingUtil.configureLogging(debug = verbose, showHttp2Frames = showHttp2Frames, sslDebug = sslDebug) commonRun() } - actual fun createRequest(): Request = commonCreateRequest() + fun createRequest(): Request = commonCreateRequest() - actual fun createClient(): Call.Factory { + fun createClient(): Call.Factory { val builder = OkHttpClient.Builder() builder.followSslRedirects(followRedirects) if (connectTimeout != DEFAULT_TIMEOUT) { @@ -105,7 +105,7 @@ actual class Main : CliktCommand(name = NAME, help = "A curl for the next-genera return builder.build() } - actual fun close() { + fun close() { val okHttpClient = client as OkHttpClient okHttpClient.connectionPool.evictAll() // Close any persistent connections. okHttpClient.dispatcher.executorService.shutdownNow() diff --git a/okcurl/src/commonMain/kotlin/okhttp3/curl/internal/-MainCommon.kt b/okcurl/src/jvmMain/kotlin/okhttp3/curl/internal/-MainCommon.kt similarity index 100% rename from okcurl/src/commonMain/kotlin/okhttp3/curl/internal/-MainCommon.kt rename to okcurl/src/jvmMain/kotlin/okhttp3/curl/internal/-MainCommon.kt diff --git a/okcurl/src/commonTest/kotlin/okhttp3/curl/OkcurlTest.kt b/okcurl/src/jvmTest/kotlin/okhttp3/curl/OkcurlTest.kt similarity index 100% rename from okcurl/src/commonTest/kotlin/okhttp3/curl/OkcurlTest.kt rename to okcurl/src/jvmTest/kotlin/okhttp3/curl/OkcurlTest.kt diff --git a/okhttp-coroutines/build.gradle.kts b/okhttp-coroutines/build.gradle.kts index 29759afc8a44..376ee27d0670 100644 --- a/okhttp-coroutines/build.gradle.kts +++ b/okhttp-coroutines/build.gradle.kts @@ -14,30 +14,19 @@ kotlin { } sourceSets { - commonMain { + getByName("jvmMain") { dependencies { - api(libs.squareup.okio) api(projects.okhttp) implementation(libs.kotlinx.coroutines.core) - } - } - val commonTest by getting { - dependencies { - implementation(libs.kotlin.test.common) - implementation(libs.kotlin.test.annotations) - api(libs.assertk) - } - } - - getByName("jvmMain") { - dependencies { api(libs.squareup.okio) api(libs.kotlin.stdlib) } } getByName("jvmTest") { dependencies { - dependsOn(commonTest) + implementation(libs.kotlin.test.common) + implementation(libs.kotlin.test.annotations) + api(libs.assertk) implementation(projects.okhttpTestingSupport) implementation(libs.kotlinx.coroutines.test) implementation(projects.mockwebserver3Junit5) diff --git a/okhttp-coroutines/src/commonMain/kotlin/okhttp3/CommonCallExtensions.kt b/okhttp-coroutines/src/commonMain/kotlin/okhttp3/CommonCallExtensions.kt deleted file mode 100644 index 1e640af9419b..000000000000 --- a/okhttp-coroutines/src/commonMain/kotlin/okhttp3/CommonCallExtensions.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package okhttp3 - -expect suspend fun Call.executeAsync(): Response diff --git a/okhttp-coroutines/src/jvmMain/kotlin/okhttp3/JvmCallExtensions.kt b/okhttp-coroutines/src/jvmMain/kotlin/okhttp3/JvmCallExtensions.kt index de057c95ead9..4732a1782741 100644 --- a/okhttp-coroutines/src/jvmMain/kotlin/okhttp3/JvmCallExtensions.kt +++ b/okhttp-coroutines/src/jvmMain/kotlin/okhttp3/JvmCallExtensions.kt @@ -23,7 +23,7 @@ import okio.IOException import kotlin.coroutines.resumeWithException @OptIn(ExperimentalCoroutinesApi::class) -actual suspend fun Call.executeAsync(): Response = suspendCancellableCoroutine { continuation -> +suspend fun Call.executeAsync(): Response = suspendCancellableCoroutine { continuation -> continuation.invokeOnCancellation { this.cancel() } diff --git a/okhttp-coroutines/src/jvmTest/kotlin/okhttp3/SuspendCallTest.kt b/okhttp-coroutines/src/jvmTest/kotlin/okhttp3/SuspendCallTest.kt index a90d5a692d9c..696de522e864 100644 --- a/okhttp-coroutines/src/jvmTest/kotlin/okhttp3/SuspendCallTest.kt +++ b/okhttp-coroutines/src/jvmTest/kotlin/okhttp3/SuspendCallTest.kt @@ -22,6 +22,9 @@ package okhttp3 import assertk.assertThat import assertk.assertions.isEqualTo import assertk.assertions.isTrue +import java.io.IOException +import java.util.concurrent.TimeUnit +import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.TimeoutCancellationException @@ -30,17 +33,13 @@ import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeout import mockwebserver3.MockResponse import mockwebserver3.MockWebServer -import mockwebserver3.SocketPolicy +import mockwebserver3.SocketPolicy.DisconnectAfterRequest import mockwebserver3.junit5.internal.MockWebServerExtension +import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.api.extension.RegisterExtension import org.junit.jupiter.api.fail -import java.io.IOException -import java.util.concurrent.TimeUnit -import kotlin.time.Duration.Companion.seconds -import mockwebserver3.SocketPolicy.DisconnectAfterRequest -import org.junit.jupiter.api.BeforeEach @ExtendWith(MockWebServerExtension::class) class SuspendCallTest { diff --git a/okhttp-coroutines/src/nonJvmMain/kotlin/okhttp3/NonJvmCallExtensions.kt b/okhttp-coroutines/src/nonJvmMain/kotlin/okhttp3/NonJvmCallExtensions.kt deleted file mode 100644 index a9898580dae3..000000000000 --- a/okhttp-coroutines/src/nonJvmMain/kotlin/okhttp3/NonJvmCallExtensions.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package okhttp3 - -actual suspend fun Call.executeAsync(): Response = this.executeAsync() diff --git a/okhttp-testing-support/build.gradle.kts b/okhttp-testing-support/build.gradle.kts index 1af42e66e6f8..f6a38d13e0c4 100644 --- a/okhttp-testing-support/build.gradle.kts +++ b/okhttp-testing-support/build.gradle.kts @@ -9,13 +9,9 @@ kotlin { } sourceSets { - val commonMain by getting { - dependencies { - api(libs.squareup.okio) - } - } val jvmMain by getting { dependencies { + api(libs.squareup.okio) api(projects.okhttp) api(projects.okhttpTls) api(libs.assertj.core) diff --git a/okhttp-testing-support/src/commonMain/kotlin/okhttp3/TestUtilCommon.kt b/okhttp-testing-support/src/jvmMain/kotlin/okhttp3/TestUtilCommon.kt similarity index 87% rename from okhttp-testing-support/src/commonMain/kotlin/okhttp3/TestUtilCommon.kt rename to okhttp-testing-support/src/jvmMain/kotlin/okhttp3/TestUtilCommon.kt index f78bd8b82551..c3b4a261cfae 100644 --- a/okhttp-testing-support/src/commonMain/kotlin/okhttp3/TestUtilCommon.kt +++ b/okhttp-testing-support/src/jvmMain/kotlin/okhttp3/TestUtilCommon.kt @@ -16,19 +16,12 @@ package okhttp3 import okio.Buffer -import okio.FileSystem import okio.Path import okio.Path.Companion.toPath val okHttpRoot: Path get() = getEnv("OKHTTP_ROOT")!!.toPath() -expect val SYSTEM_FILE_SYSTEM: FileSystem - -expect fun getEnv(name: String): String? - -expect val isJvm: Boolean - fun String(vararg codePoints: Int): String { val buffer = Buffer() for (codePoint in codePoints) { diff --git a/okhttp-testing-support/src/jvmMain/kotlin/okhttp3/TestUtilJvm.kt b/okhttp-testing-support/src/jvmMain/kotlin/okhttp3/TestUtilJvm.kt index 47d58233e4bc..34e0322d24a1 100644 --- a/okhttp-testing-support/src/jvmMain/kotlin/okhttp3/TestUtilJvm.kt +++ b/okhttp-testing-support/src/jvmMain/kotlin/okhttp3/TestUtilJvm.kt @@ -124,8 +124,8 @@ object TestUtil { } } -actual fun getEnv(name: String) = System.getenv(name) +fun getEnv(name: String) = System.getenv(name) -actual val SYSTEM_FILE_SYSTEM = FileSystem.SYSTEM +val SYSTEM_FILE_SYSTEM = FileSystem.SYSTEM -actual val isJvm = true +val isJvm = true diff --git a/okhttp-testing-support/src/main/kotlin/okhttp3/internal/http2/Http2FlowControlConnectionListener.kt b/okhttp-testing-support/src/jvmMain/kotlin/okhttp3/internal/http2/Http2FlowControlConnectionListener.kt similarity index 100% rename from okhttp-testing-support/src/main/kotlin/okhttp3/internal/http2/Http2FlowControlConnectionListener.kt rename to okhttp-testing-support/src/jvmMain/kotlin/okhttp3/internal/http2/Http2FlowControlConnectionListener.kt diff --git a/okhttp/build.gradle.kts b/okhttp/build.gradle.kts index a387f548d1a9..9e197e87225f 100644 --- a/okhttp/build.gradle.kts +++ b/okhttp/build.gradle.kts @@ -1,10 +1,5 @@ -import com.android.build.gradle.internal.tasks.factory.dependsOn -import com.android.build.gradle.tasks.JavaDocJarTask import com.vanniktech.maven.publish.JavadocJar import com.vanniktech.maven.publish.KotlinMultiplatform -import org.jetbrains.dokka.gradle.DokkaTask -import org.jetbrains.dokka.gradle.DokkaTaskPartial -import org.jetbrains.kotlin.gradle.dsl.KotlinCompile plugins { kotlin("multiplatform") @@ -16,7 +11,7 @@ plugins { // Build & use okhttp3/internal/-InternalVersion.kt val copyKotlinTemplates = tasks.register("copyKotlinTemplates") { - from("src/commonMain/kotlinTemplates") + from("src/jvmMain/kotlinTemplates") into("$buildDir/generated/sources/kotlinTemplates") expand("projectVersion" to project.version) filteringCharset = Charsets.UTF_8.toString() @@ -40,25 +35,10 @@ kotlin { } sourceSets { - commonMain { + getByName("jvmMain") { kotlin.srcDir(copyKotlinTemplates.get().outputs) kotlin.srcDir(generateIdnaMappingTable.outputs) - dependencies { - api(libs.squareup.okio) - } - } - val commonTest 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) - } - } - getByName("jvmMain") { dependencies { api(libs.squareup.okio) api(libs.kotlin.stdlib) @@ -78,7 +58,12 @@ kotlin { } getByName("jvmTest") { dependencies { - dependsOn(commonTest) + 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) diff --git a/okhttp/src/commonMain/kotlin/okhttp3/-CommonPlatform.kt b/okhttp/src/commonMain/kotlin/okhttp3/-CommonPlatform.kt deleted file mode 100644 index f33949fdabba..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/-CommonPlatform.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2022 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package okhttp3 - -import okio.IOException - -expect class ProtocolException(message: String) : IOException diff --git a/okhttp/src/commonMain/kotlin/okhttp3/CacheControl.kt b/okhttp/src/commonMain/kotlin/okhttp3/CacheControl.kt deleted file mode 100644 index b6b7fc6e4307..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/CacheControl.kt +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) 2019 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package okhttp3 - -import kotlin.time.DurationUnit - -/** - * A Cache-Control header with cache directives from a server or client. These directives set policy - * on what responses can be stored, and which requests can be satisfied by those stored responses. - * - * See [RFC 7234, 5.2](https://tools.ietf.org/html/rfc7234#section-5.2). - */ -expect class CacheControl internal constructor( - noCache: Boolean, - - noStore: Boolean, - - maxAgeSeconds: Int, - - sMaxAgeSeconds: Int, - - isPrivate: Boolean, - isPublic: Boolean, - - mustRevalidate: Boolean, - - maxStaleSeconds: Int, - - minFreshSeconds: Int, - - onlyIfCached: Boolean, - - noTransform: Boolean, - - immutable: Boolean, - - headerValue: String? -) { - - /** - * In a response, this field's name "no-cache" is misleading. It doesn't prevent us from caching - * the response; it only means we have to validate the response with the origin server before - * returning it. We can do this with a conditional GET. - * - * In a request, it means do not use a cache to satisfy the request. - */ - val noCache: Boolean - - /** If true, this response should not be cached. */ - val noStore: Boolean - - /** The duration past the response's served date that it can be served without validation. */ - val maxAgeSeconds: Int - - /** - * The "s-maxage" directive is the max age for shared caches. Not to be confused with "max-age" - * for non-shared caches, As in Firefox and Chrome, this directive is not honored by this cache. - */ - val sMaxAgeSeconds: Int - - val isPrivate: Boolean - val isPublic: Boolean - - val mustRevalidate: Boolean - - val maxStaleSeconds: Int - - val minFreshSeconds: Int - - /** - * This field's name "only-if-cached" is misleading. It actually means "do not use the network". - * It is set by a client who only wants to make a request if it can be fully satisfied by the - * cache. Cached responses that would require validation (ie. conditional gets) are not permitted - * if this header is set. - */ - val onlyIfCached: Boolean - - val noTransform: Boolean - - val immutable: Boolean - - internal var headerValue: String? - - override fun toString(): String - - /** Builds a `Cache-Control` request header. */ - class Builder constructor() { - internal var noCache: Boolean - internal var noStore: Boolean - internal var maxAgeSeconds: Int - internal var maxStaleSeconds: Int - internal var minFreshSeconds: Int - internal var onlyIfCached: Boolean - internal var noTransform: Boolean - internal var immutable: Boolean - - /** Don't accept an unvalidated cached response. */ - fun noCache(): Builder - - /** Don't store the server's response in any cache. */ - fun noStore(): Builder - - /** - * Sets the maximum age of a cached response. If the cache response's age exceeds [maxAge], it - * will not be used and a network request will be made. - * - * @param maxAge a non-negative integer. This is stored and transmitted with [TimeUnit.SECONDS] - * precision; finer precision will be lost. - */ - fun maxAge(maxAge: Int, timeUnit: DurationUnit): Builder - - /** - * Accept cached responses that have exceeded their freshness lifetime by up to `maxStale`. If - * unspecified, stale cache responses will not be used. - * - * @param maxStale a non-negative integer. This is stored and transmitted with - * [TimeUnit.SECONDS] precision; finer precision will be lost. - */ - fun maxStale(maxStale: Int, timeUnit: DurationUnit): Builder - - /** - * Sets the minimum number of seconds that a response will continue to be fresh for. If the - * response will be stale when [minFresh] have elapsed, the cached response will not be used and - * a network request will be made. - * - * @param minFresh a non-negative integer. This is stored and transmitted with - * [TimeUnit.SECONDS] precision; finer precision will be lost. - */ - fun minFresh(minFresh: Int, timeUnit: DurationUnit): Builder - - /** - * Only accept the response if it is in the cache. If the response isn't cached, a `504 - * Unsatisfiable Request` response will be returned. - */ - fun onlyIfCached(): Builder - - /** Don't accept a transformed response. */ - fun noTransform(): Builder - - fun immutable(): Builder - - fun build(): CacheControl - } - - companion object { - /** - * Cache control request directives that require network validation of responses. Note that such - * requests may be assisted by the cache via conditional GET requests. - */ - val FORCE_NETWORK: CacheControl - - /** - * Cache control request directives that uses the cache only, even if the cached response is - * stale. If the response isn't available in the cache or requires server validation, the call - * will fail with a `504 Unsatisfiable Request`. - */ - val FORCE_CACHE: CacheControl - - /** - * Returns the cache directives of [headers]. This honors both Cache-Control and Pragma headers - * if they are present. - */ - fun parse(headers: Headers): CacheControl - } -} diff --git a/okhttp/src/commonMain/kotlin/okhttp3/Call.kt b/okhttp/src/commonMain/kotlin/okhttp3/Call.kt deleted file mode 100644 index 6183c654fec6..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/Call.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2014 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package okhttp3 - -/** - * A call is a request that has been prepared for execution. A call can be canceled. As this object - * represents a single request/response pair (stream), it cannot be executed twice. - */ -expect interface Call { - /** Returns the original request that initiated this call. */ - fun request(): Request - - /** - * Schedules the request to be executed at some point in the future. - * - * The [dispatcher][OkHttpClient.dispatcher] defines when the request will run: usually - * immediately unless there are several other requests currently being executed. - * - * This client will later call back `responseCallback` with either an HTTP response or a failure - * exception. - * - * @throws IllegalStateException when the call has already been executed. - */ - fun enqueue(responseCallback: Callback) - - /** Cancels the request, if possible. Requests that are already complete cannot be canceled. */ - fun cancel() - - /** - * Returns true if this call has been either [executed][execute] or [enqueued][enqueue]. It is an - * error to execute a call more than once. - */ - fun isExecuted(): Boolean - - fun isCanceled(): Boolean - -// /** -// * Returns a timeout that spans the entire call: resolving DNS, connecting, writing the request -// * body, server processing, and reading the response body. If the call requires redirects or -// * retries all must complete within one timeout period. -// * -// * Configure the client's default timeout with [OkHttpClient.Builder.callTimeout]. -// */ -// fun timeout(): Timeout - - /** - * Create a new, identical call to this one which can be enqueued or executed even if this call - * has already been. - */ - fun clone(): Call - - fun interface Factory { - fun newCall(request: Request): Call - } -} diff --git a/okhttp/src/commonMain/kotlin/okhttp3/Challenge.kt b/okhttp/src/commonMain/kotlin/okhttp3/Challenge.kt deleted file mode 100644 index 2f143fa7c6ed..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/Challenge.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2022 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package okhttp3 - -/** - * An [RFC 7235][rfc_7235] challenge. - * - * [rfc_7235]: https://tools.ietf.org/html/rfc7235 - */ -expect class Challenge { - - /** Returns the authentication scheme, like `Basic`. */ - val scheme: String - - /** - * Returns the auth params, including [realm] and [charset] if present, but as - * strings. The map's keys are lowercase and should be treated case-insensitively. - */ - val authParams: Map - - /** Returns the protection space. */ - val realm: String? - - constructor(scheme: String, realm: String) - constructor(scheme: String, authParams: Map) - - override fun equals(other: Any?): Boolean - - override fun hashCode(): Int - - override fun toString(): String -} diff --git a/okhttp/src/commonMain/kotlin/okhttp3/Headers.kt b/okhttp/src/commonMain/kotlin/okhttp3/Headers.kt deleted file mode 100644 index 3e4769892a73..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/Headers.kt +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package okhttp3 - -import okhttp3.Headers.Builder - -/** - * The header fields of a single HTTP message. Values are uninterpreted strings; use `Request` and - * `Response` for interpreted headers. This class maintains the order of the header fields within - * the HTTP message. - * - * This class tracks header values line-by-line. A field with multiple comma- separated values on - * the same line will be treated as a field with a single value by this class. It is the caller's - * responsibility to detect and split on commas if their field permits multiple values. This - * simplifies use of single-valued fields whose values routinely contain commas, such as cookies or - * dates. - * - * This class trims whitespace from values. It never returns values with leading or trailing - * whitespace. - * - * Instances of this class are immutable. Use [Builder] to create instances. - */ -@Suppress("NAME_SHADOWING") -expect class Headers internal constructor( - namesAndValues: Array -) : Iterable> { - internal val namesAndValues: Array - - /** Returns the last value corresponding to the specified field, or null. */ - operator fun get(name: String): String? - - /** Returns the number of field values. */ - val size: Int - - /** Returns the field at `position`. */ - fun name(index: Int): String - - /** Returns the value at `index`. */ - fun value(index: Int): String - - /** Returns an immutable case-insensitive set of header names. */ - fun names(): Set - - /** Returns an immutable list of the header values for `name`. */ - fun values(name: String): List - - override operator fun iterator(): Iterator> - - fun newBuilder(): Builder - - /** - * Returns true if `other` is a `Headers` object with the same headers, with the same casing, in - * the same order. Note that two headers instances may be *semantically* equal but not equal - * according to this method. In particular, none of the following sets of headers are equal - * according to this method: - * - * 1. Original - * ``` - * Content-Type: text/html - * Content-Length: 50 - * ``` - * - * 2. Different order - * - * ``` - * Content-Length: 50 - * Content-Type: text/html - * ``` - * - * 3. Different case - * - * ``` - * content-type: text/html - * content-length: 50 - * ``` - * - * 4. Different values - * - * ``` - * Content-Type: text/html - * Content-Length: 050 - * ``` - * - * Applications that require semantically equal headers should convert them into a canonical form - * before comparing them for equality. - */ - override fun equals(other: Any?): Boolean - - /** - * Returns header names and values. The names and values are separated by `: ` and each pair is - * followed by a newline character `\n`. - * - * Since OkHttp 5 this redacts these sensitive headers: - * - * * `Authorization` - * * `Cookie` - * * `Proxy-Authorization` - * * `Set-Cookie` - */ - override fun toString(): String - - class Builder internal constructor() { - internal val namesAndValues: MutableList - - /** - * Add a header with the specified name and value. Does validation of header names and values. - */ - fun add(name: String, value: String): Builder - - /** - * Adds all headers from an existing collection. - */ - fun addAll(headers: Headers): Builder - - fun removeAll(name: String): Builder - - /** - * Set a field with the specified value. If the field is not found, it is added. If the field is - * found, the existing values are replaced. - */ - operator fun set(name: String, value: String): Builder - - /** Equivalent to `build().get(name)`, but potentially faster. */ - operator fun get(name: String): String? - - fun build(): Headers - } - - companion object { - /** - * Returns headers for the alternating header names and values. There must be an even number of - * arguments, and they must alternate between header names and values. - */ - fun headersOf(vararg namesAndValues: String): Headers - - /** Returns headers for the header names and values in the [Map]. */ - fun Map.toHeaders(): Headers - } -} diff --git a/okhttp/src/commonMain/kotlin/okhttp3/HttpUrl.kt b/okhttp/src/commonMain/kotlin/okhttp3/HttpUrl.kt deleted file mode 100644 index d41a5dc32232..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/HttpUrl.kt +++ /dev/null @@ -1,692 +0,0 @@ -/* - * Copyright (C) 2015 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package okhttp3 - -import kotlin.jvm.JvmName -import okhttp3.HttpUrl.Companion.toHttpUrl -import okhttp3.HttpUrl.Companion.toHttpUrlOrNull - -/** - * A uniform resource locator (URL) with a scheme of either `http` or `https`. Use this class to - * compose and decompose Internet addresses. For example, this code will compose and print a URL for - * Google search: - * - * ```java - * HttpUrl url = new HttpUrl.Builder() - * .scheme("https") - * .host("www.google.com") - * .addPathSegment("search") - * .addQueryParameter("q", "polar bears") - * .build(); - * System.out.println(url); - * ``` - * - * which prints: - * - * ``` - * https://www.google.com/search?q=polar%20bears - * ``` - * - * As another example, this code prints the human-readable query parameters of a Twitter search: - * - * ```java - * HttpUrl url = HttpUrl.parse("https://twitter.com/search?q=cute%20%23puppies&f=images"); - * for (int i = 0, size = url.querySize(); i < size; i++) { - * System.out.println(url.queryParameterName(i) + ": " + url.queryParameterValue(i)); - * } - * ``` - * - * which prints: - * - * ``` - * q: cute #puppies - * f: images - * ``` - * - * In addition to composing URLs from their component parts and decomposing URLs into their - * component parts, this class implements relative URL resolution: what address you'd reach by - * clicking a relative link on a specified page. For example: - * - * ```java - * HttpUrl base = HttpUrl.parse("https://www.youtube.com/user/WatchTheDaily/videos"); - * HttpUrl link = base.resolve("../../watch?v=cbP2N1BQdYc"); - * System.out.println(link); - * ``` - * - * which prints: - * - * ``` - * https://www.youtube.com/watch?v=cbP2N1BQdYc - * ``` - * - * ## What's in a URL? - * - * A URL has several components. - * - * ### Scheme - * - * Sometimes referred to as *protocol*, A URL's scheme describes what mechanism should be used to - * retrieve the resource. Although URLs have many schemes (`mailto`, `file`, `ftp`), this class only - * supports `http` and `https`. Use [java.net.URI][URI] for URLs with arbitrary schemes. - * - * ### Username and Password - * - * Username and password are either present, or the empty string `""` if absent. This class offers - * no mechanism to differentiate empty from absent. Neither of these components are popular in - * practice. Typically HTTP applications use other mechanisms for user identification and - * authentication. - * - * ### Host - * - * The host identifies the webserver that serves the URL's resource. It is either a hostname like - * `square.com` or `localhost`, an IPv4 address like `192.168.0.1`, or an IPv6 address like `::1`. - * - * Usually a webserver is reachable with multiple identifiers: its IP addresses, registered - * domain names, and even `localhost` when connecting from the server itself. Each of a web server's - * names is a distinct URL and they are not interchangeable. For example, even if - * `http://square.github.io/dagger` and `http://google.github.io/dagger` are served by the same IP - * address, the two URLs identify different resources. - * - * ### Port - * - * The port used to connect to the web server. By default this is 80 for HTTP and 443 for HTTPS. - * This class never returns -1 for the port: if no port is explicitly specified in the URL then the - * scheme's default is used. - * - * ### Path - * - * The path identifies a specific resource on the host. Paths have a hierarchical structure like - * "/square/okhttp/issues/1486" and decompose into a list of segments like `["square", "okhttp", - * "issues", "1486"]`. - * - * This class offers methods to compose and decompose paths by segment. It composes each path - * from a list of segments by alternating between "/" and the encoded segment. For example the - * segments `["a", "b"]` build "/a/b" and the segments `["a", "b", ""]` build "/a/b/". - * - * If a path's last segment is the empty string then the path ends with "/". This class always - * builds non-empty paths: if the path is omitted it defaults to "/". The default path's segment - * list is a single empty string: `[""]`. - * - * ### Query - * - * The query is optional: it can be null, empty, or non-empty. For many HTTP URLs the query string - * is subdivided into a collection of name-value parameters. This class offers methods to set the - * query as the single string, or as individual name-value parameters. With name-value parameters - * the values are optional and names may be repeated. - * - * ### Fragment - * - * The fragment is optional: it can be null, empty, or non-empty. Unlike host, port, path, and - * query the fragment is not sent to the webserver: it's private to the client. - * - * ## Encoding - * - * Each component must be encoded before it is embedded in the complete URL. As we saw above, the - * string `cute #puppies` is encoded as `cute%20%23puppies` when used as a query parameter value. - * - * ### Percent encoding - * - * Percent encoding replaces a character (like `\ud83c\udf69`) with its UTF-8 hex bytes (like - * `%F0%9F%8D%A9`). This approach works for whitespace characters, control characters, non-ASCII - * characters, and characters that already have another meaning in a particular context. - * - * Percent encoding is used in every URL component except for the hostname. But the set of - * characters that need to be encoded is different for each component. For example, the path - * component must escape all of its `?` characters, otherwise it could be interpreted as the - * start of the URL's query. But within the query and fragment components, the `?` character - * doesn't delimit anything and doesn't need to be escaped. - * - * ```java - * HttpUrl url = HttpUrl.parse("http://who-let-the-dogs.out").newBuilder() - * .addPathSegment("_Who?_") - * .query("_Who?_") - * .fragment("_Who?_") - * .build(); - * System.out.println(url); - * ``` - * - * This prints: - * - * ``` - * http://who-let-the-dogs.out/_Who%3F_?_Who?_#_Who?_ - * ``` - * - * When parsing URLs that lack percent encoding where it is required, this class will percent encode - * the offending characters. - * - * ### IDNA Mapping and Punycode encoding - * - * Hostnames have different requirements and use a different encoding scheme. It consists of IDNA - * mapping and Punycode encoding. - * - * In order to avoid confusion and discourage phishing attacks, [IDNA Mapping][idna] transforms - * names to avoid confusing characters. This includes basic case folding: transforming shouting - * `SQUARE.COM` into cool and casual `square.com`. It also handles more exotic characters. For - * example, the Unicode trademark sign (™) could be confused for the letters "TM" in - * `http://ho™ail.com`. To mitigate this, the single character (™) maps to the string (tm). There - * is similar policy for all of the 1.1 million Unicode code points. Note that some code points such - * as "\ud83c\udf69" are not mapped and cannot be used in a hostname. - * - * [Punycode](http://ietf.org/rfc/rfc3492.txt) converts a Unicode string to an ASCII string to make - * international domain names work everywhere. For example, "σ" encodes as "xn--4xa". The encoded - * string is not human readable, but can be used with classes like [InetAddress] to establish - * connections. - * - * ## Why another URL model? - * - * Java includes both [java.net.URL][URL] and [java.net.URI][URI]. We offer a new URL - * model to address problems that the others don't. - * - * ### Different URLs should be different - * - * Although they have different content, `java.net.URL` considers the following two URLs - * equal, and the [equals()][Object.equals] method between them returns true: - * - * * https://example.net/ - * - * * https://example.com/ - * - * This is because those two hosts share the same IP address. This is an old, bad design decision - * that makes `java.net.URL` unusable for many things. It shouldn't be used as a [Map] key or in a - * [Set]. Doing so is both inefficient because equality may require a DNS lookup, and incorrect - * because unequal URLs may be equal because of how they are hosted. - * - * ### Equal URLs should be equal - * - * These two URLs are semantically identical, but `java.net.URI` disagrees: - * - * * http://host:80/ - * - * * http://host - * - * Both the unnecessary port specification (`:80`) and the absent trailing slash (`/`) cause URI to - * bucket the two URLs separately. This harms URI's usefulness in collections. Any application that - * stores information-per-URL will need to either canonicalize manually, or suffer unnecessary - * redundancy for such URLs. - * - * Because they don't attempt canonical form, these classes are surprisingly difficult to use - * securely. Suppose you're building a webservice that checks that incoming paths are prefixed - * "/static/images/" before serving the corresponding assets from the filesystem. - * - * ```java - * String attack = "http://example.com/static/images/../../../../../etc/passwd"; - * System.out.println(new URL(attack).getPath()); - * System.out.println(new URI(attack).getPath()); - * System.out.println(HttpUrl.parse(attack).encodedPath()); - * ``` - * - * By canonicalizing the input paths, they are complicit in directory traversal attacks. Code that - * checks only the path prefix may suffer! - * - * ``` - * /static/images/../../../../../etc/passwd - * /static/images/../../../../../etc/passwd - * /etc/passwd - * ``` - * - * ### If it works on the web, it should work in your application - * - * The `java.net.URI` class is strict around what URLs it accepts. It rejects URLs like - * `http://example.com/abc|def` because the `|` character is unsupported. This class is more - * forgiving: it will automatically percent-encode the `|'` yielding `http://example.com/abc%7Cdef`. - * This kind behavior is consistent with web browsers. `HttpUrl` prefers consistency with major web - * browsers over consistency with obsolete specifications. - * - * ### Paths and Queries should decompose - * - * Neither of the built-in URL models offer direct access to path segments or query parameters. - * Manually using `StringBuilder` to assemble these components is cumbersome: do '+' characters get - * silently replaced with spaces? If a query parameter contains a '&', does that get escaped? - * By offering methods to read and write individual query parameters directly, application - * developers are saved from the hassles of encoding and decoding. - * - * ### Plus a modern API - * - * The URL (JDK1.0) and URI (Java 1.4) classes predate builders and instead use telescoping - * constructors. For example, there's no API to compose a URI with a custom port without also - * providing a query and fragment. - * - * Instances of [HttpUrl] are well-formed and always have a scheme, host, and path. With - * `java.net.URL` it's possible to create an awkward URL like `http:/` with scheme and path but no - * hostname. Building APIs that consume such malformed values is difficult! - * - * This class has a modern API. It avoids punitive checked exceptions: [toHttpUrl] throws - * [IllegalArgumentException] on invalid input or [toHttpUrlOrNull] returns null if the input is an - * invalid URL. You can even be explicit about whether each component has been encoded already. - * - * [idna]: http://www.unicode.org/reports/tr46/#ToASCII - */ -expect class HttpUrl internal constructor( - scheme: String, - username: String, - password: String, - host: String, - port: Int, - pathSegments: List, - queryNamesAndValues: List?, - fragment: String?, - url: String -) { - - /** Either "http" or "https". */ - val scheme: String - - /** - * The decoded username, or an empty string if none is present. - * - * | URL | `username()` | - * | :------------------------------- | :----------- | - * | `http://host/` | `""` | - * | `http://username@host/` | `"username"` | - * | `http://username:password@host/` | `"username"` | - * | `http://a%20b:c%20d@host/` | `"a b"` | - */ - val username: String - - /** - * Returns the decoded password, or an empty string if none is present. - * - * | URL | `password()` | - * | :------------------------------- | :----------- | - * | `http://host/` | `""` | - * | `http://username@host/` | `""` | - * | `http://username:password@host/` | `"password"` | - * | `http://a%20b:c%20d@host/` | `"c d"` | - */ - val password: String - - /** - * The host address suitable for use with [InetAddress.getAllByName]. May be: - * - * * A regular host name, like `android.com`. - * - * * An IPv4 address, like `127.0.0.1`. - * - * * An IPv6 address, like `::1`. Note that there are no square braces. - * - * * An encoded IDN, like `xn--n3h.net`. - * - * | URL | `host()` | - * | :-------------------- | :-------------- | - * | `http://android.com/` | `"android.com"` | - * | `http://127.0.0.1/` | `"127.0.0.1"` | - * | `http://[::1]/` | `"::1"` | - * | `http://xn--n3h.net/` | `"xn--n3h.net"` | - */ - val host: String - - /** - * The explicitly-specified port if one was provided, or the default port for this URL's scheme. - * For example, this returns 8443 for `https://square.com:8443/` and 443 for - * `https://square.com/`. The result is in `[1..65535]`. - * - * | URL | `port()` | - * | :------------------ | :------- | - * | `http://host/` | `80` | - * | `http://host:8000/` | `8000` | - * | `https://host/` | `443` | - */ - val port: Int - - /** - * A list of path segments like `["a", "b", "c"]` for the URL `http://host/a/b/c`. This list is - * never empty though it may contain a single empty string. - * - * | URL | `pathSegments()` | - * | :----------------------- | :------------------ | - * | `http://host/` | `[""]` | - * | `http://host/a/b/c"` | `["a", "b", "c"]` | - * | `http://host/a/b%20c/d"` | `["a", "b c", "d"]` | - */ - val pathSegments: List - - /** - * This URL's fragment, like `"abc"` for `http://host/#abc`. This is null if the URL has no - * fragment. - * - * | URL | `fragment()` | - * | :--------------------- | :----------- | - * | `http://host/` | null | - * | `http://host/#` | `""` | - * | `http://host/#abc` | `"abc"` | - * | `http://host/#abc|def` | `"abc|def"` | - */ - val fragment: String? - - val isHttps: Boolean - - /** - * The username, or an empty string if none is set. - * - * | URL | `encodedUsername()` | - * | :------------------------------- | :------------------ | - * | `http://host/` | `""` | - * | `http://username@host/` | `"username"` | - * | `http://username:password@host/` | `"username"` | - * | `http://a%20b:c%20d@host/` | `"a%20b"` | - */ - val encodedUsername: String - - /** - * The password, or an empty string if none is set. - * - * | URL | `encodedPassword()` | - * | :--------------------------------| :------------------ | - * | `http://host/` | `""` | - * | `http://username@host/` | `""` | - * | `http://username:password@host/` | `"password"` | - * | `http://a%20b:c%20d@host/` | `"c%20d"` | - */ - val encodedPassword: String - - /** - * The number of segments in this URL's path. This is also the number of slashes in this URL's - * path, like 3 in `http://host/a/b/c`. This is always at least 1. - * - * | URL | `pathSize()` | - * | :------------------- | :----------- | - * | `http://host/` | `1` | - * | `http://host/a/b/c` | `3` | - * | `http://host/a/b/c/` | `4` | - */ - val pathSize: Int - - /** - * The entire path of this URL encoded for use in HTTP resource resolution. The returned path will - * start with `"/"`. - * - * | URL | `encodedPath()` | - * | :---------------------- | :-------------- | - * | `http://host/` | `"/"` | - * | `http://host/a/b/c` | `"/a/b/c"` | - * | `http://host/a/b%20c/d` | `"/a/b%20c/d"` | - */ - val encodedPath: String - - /** - * A list of encoded path segments like `["a", "b", "c"]` for the URL `http://host/a/b/c`. This - * list is never empty though it may contain a single empty string. - * - * | URL | `encodedPathSegments()` | - * | :---------------------- | :---------------------- | - * | `http://host/` | `[""]` | - * | `http://host/a/b/c` | `["a", "b", "c"]` | - * | `http://host/a/b%20c/d` | `["a", "b%20c", "d"]` | - */ - val encodedPathSegments: List - - /** - * The query of this URL, encoded for use in HTTP resource resolution. This string may be null - * (for URLs with no query), empty (for URLs with an empty query) or non-empty (all other URLs). - * - * | URL | `encodedQuery()` | - * | :-------------------------------- | :--------------------- | - * | `http://host/` | null | - * | `http://host/?` | `""` | - * | `http://host/?a=apple&k=key+lime` | `"a=apple&k=key+lime"` | - * | `http://host/?a=apple&a=apricot` | `"a=apple&a=apricot"` | - * | `http://host/?a=apple&b` | `"a=apple&b"` | - */ - val encodedQuery: String? - - /** - * This URL's query, like `"abc"` for `http://host/?abc`. Most callers should prefer - * [queryParameterName] and [queryParameterValue] because these methods offer direct access to - * individual query parameters. - * - * | URL | `query()` | - * | :-------------------------------- | :--------------------- | - * | `http://host/` | null | - * | `http://host/?` | `""` | - * | `http://host/?a=apple&k=key+lime` | `"a=apple&k=key lime"` | - * | `http://host/?a=apple&a=apricot` | `"a=apple&a=apricot"` | - * | `http://host/?a=apple&b` | `"a=apple&b"` | - */ - val query: String? - - /** - * The number of query parameters in this URL, like 2 for `http://host/?a=apple&b=banana`. If this - * URL has no query this is 0. Otherwise it is one more than the number of `"&"` separators in the - * query. - * - * | URL | `querySize()` | - * | :-------------------------------- | :------------ | - * | `http://host/` | `0` | - * | `http://host/?` | `1` | - * | `http://host/?a=apple&k=key+lime` | `2` | - * | `http://host/?a=apple&a=apricot` | `2` | - * | `http://host/?a=apple&b` | `2` | - */ - val querySize: Int - - /** - * The first query parameter named `name` decoded using UTF-8, or null if there is no such query - * parameter. - * - * | URL | `queryParameter("a")` | - * | :-------------------------------- | :-------------------- | - * | `http://host/` | null | - * | `http://host/?` | null | - * | `http://host/?a=apple&k=key+lime` | `"apple"` | - * | `http://host/?a=apple&a=apricot` | `"apple"` | - * | `http://host/?a=apple&b` | `"apple"` | - */ - fun queryParameter(name: String): String? - - /** - * The distinct query parameter names in this URL, like `["a", "b"]` for - * `http://host/?a=apple&b=banana`. If this URL has no query this is the empty set. - * - * | URL | `queryParameterNames()` | - * | :-------------------------------- | :---------------------- | - * | `http://host/` | `[]` | - * | `http://host/?` | `[""]` | - * | `http://host/?a=apple&k=key+lime` | `["a", "k"]` | - * | `http://host/?a=apple&a=apricot` | `["a"]` | - * | `http://host/?a=apple&b` | `["a", "b"]` | - */ - val queryParameterNames: Set - - internal val url: String - - /** - * Alternating, decoded query names and values, or null for no query. Names may be empty or - * non-empty, but never null. Values are null if the name has no corresponding '=' separator, or - * empty, or non-empty. - */ - internal val queryNamesAndValues: List? - - /** - * Returns all values for the query parameter `name` ordered by their appearance in this - * URL. For example this returns `["banana"]` for `queryParameterValue("b")` on - * `http://host/?a=apple&b=banana`. - * - * | URL | `queryParameterValues("a")` | `queryParameterValues("b")` | - * | :-------------------------------- | :-------------------------- | :-------------------------- | - * | `http://host/` | `[]` | `[]` | - * | `http://host/?` | `[]` | `[]` | - * | `http://host/?a=apple&k=key+lime` | `["apple"]` | `[]` | - * | `http://host/?a=apple&a=apricot` | `["apple", "apricot"]` | `[]` | - * | `http://host/?a=apple&b` | `["apple"]` | `[null]` | - */ - fun queryParameterValues(name: String): List - - /** - * Returns the name of the query parameter at `index`. For example this returns `"a"` - * for `queryParameterName(0)` on `http://host/?a=apple&b=banana`. This throws if - * `index` is not less than the [query size][querySize]. - * - * | URL | `queryParameterName(0)` | `queryParameterName(1)` | - * | :-------------------------------- | :---------------------- | :---------------------- | - * | `http://host/` | exception | exception | - * | `http://host/?` | `""` | exception | - * | `http://host/?a=apple&k=key+lime` | `"a"` | `"k"` | - * | `http://host/?a=apple&a=apricot` | `"a"` | `"a"` | - * | `http://host/?a=apple&b` | `"a"` | `"b"` | - */ - fun queryParameterName(index: Int): String - - /** - * Returns the value of the query parameter at `index`. For example this returns `"apple"` for - * `queryParameterName(0)` on `http://host/?a=apple&b=banana`. This throws if `index` is not less - * than the [query size][querySize]. - * - * | URL | `queryParameterValue(0)` | `queryParameterValue(1)` | - * | :-------------------------------- | :----------------------- | :----------------------- | - * | `http://host/` | exception | exception | - * | `http://host/?` | null | exception | - * | `http://host/?a=apple&k=key+lime` | `"apple"` | `"key lime"` | - * | `http://host/?a=apple&a=apricot` | `"apple"` | `"apricot"` | - * | `http://host/?a=apple&b` | `"apple"` | null | - */ - fun queryParameterValue(index: Int): String? - - /** - * This URL's encoded fragment, like `"abc"` for `http://host/#abc`. This is null if the URL has - * no fragment. - * - * | URL | `encodedFragment()` | - * | :--------------------- | :------------------ | - * | `http://host/` | null | - * | `http://host/#` | `""` | - * | `http://host/#abc` | `"abc"` | - * | `http://host/#abc|def` | `"abc|def"` | - */ - @get:JvmName("encodedFragment") val encodedFragment: String? - - /** - * Returns a string with containing this URL with its username, password, query, and fragment - * stripped, and its path replaced with `/...`. For example, redacting - * `http://username:password@example.com/path` returns `http://example.com/...`. - */ - fun redact(): String - - /** - * Returns the URL that would be retrieved by following `link` from this URL, or null if the - * resulting URL is not well-formed. - */ - fun resolve(link: String): HttpUrl? - - /** - * Returns a builder based on this URL. - */ - fun newBuilder(): Builder - - /** - * Returns a builder for the URL that would be retrieved by following `link` from this URL, - * or null if the resulting URL is not well-formed. - */ - fun newBuilder(link: String): Builder? - - class Builder constructor() { - internal var scheme: String? - internal var encodedUsername: String - internal var encodedPassword: String - internal var host: String? - internal var port: Int - internal val encodedPathSegments: MutableList - internal var encodedQueryNamesAndValues: MutableList? - internal var encodedFragment: String? - - /** - * @param scheme either "http" or "https". - */ - fun scheme(scheme: String): Builder - fun username(username: String): Builder - - fun encodedUsername(encodedUsername: String): Builder - - fun password(password: String): Builder - - fun encodedPassword(encodedPassword: String): Builder - - /** - * @param host either a regular hostname, International Domain Name, IPv4 address, or IPv6 - * address. - */ - fun host(host: String): Builder - fun port(port: Int): Builder - - fun addPathSegment(pathSegment: String): Builder - - /** - * Adds a set of path segments separated by a slash (either `\` or `/`). If `pathSegments` - * starts with a slash, the resulting URL will have empty path segment. - */ - fun addPathSegments(pathSegments: String): Builder - - fun addEncodedPathSegment(encodedPathSegment: String): Builder - - /** - * Adds a set of encoded path segments separated by a slash (either `\` or `/`). If - * `encodedPathSegments` starts with a slash, the resulting URL will have empty path segment. - */ - fun addEncodedPathSegments(encodedPathSegments: String): Builder - - fun setPathSegment(index: Int, pathSegment: String): Builder - - fun setEncodedPathSegment(index: Int, encodedPathSegment: String): Builder - - fun removePathSegment(index: Int): Builder - - fun encodedPath(encodedPath: String): Builder - - fun query(query: String?): Builder - - fun encodedQuery(encodedQuery: String?): Builder - - /** Encodes the query parameter using UTF-8 and adds it to this URL's query string. */ - fun addQueryParameter(name: String, value: String?): Builder - - /** Adds the pre-encoded query parameter to this URL's query string. */ - fun addEncodedQueryParameter(encodedName: String, encodedValue: String?): Builder - - fun setQueryParameter(name: String, value: String?): Builder - - fun setEncodedQueryParameter(encodedName: String, encodedValue: String?): Builder - - fun removeAllQueryParameters(name: String): Builder - - fun removeAllEncodedQueryParameters(encodedName: String): Builder - - fun fragment(fragment: String?): Builder - - fun encodedFragment(encodedFragment: String?): Builder - - fun build(): HttpUrl - - internal fun parse(base: HttpUrl?, input: String): Builder - - } - - companion object { - - fun defaultPort(scheme: String): Int - - /** - * Returns a new [HttpUrl] representing this. - * - * @throws IllegalArgumentException If this is not a well-formed HTTP or HTTPS URL. - */ - fun String.toHttpUrl(): HttpUrl - - /** - * Returns a new `HttpUrl` representing `url` if it is a well-formed HTTP or HTTPS URL, or null - * if it isn't. - */ - fun String.toHttpUrlOrNull(): HttpUrl? - } -} diff --git a/okhttp/src/commonMain/kotlin/okhttp3/MediaType.kt b/okhttp/src/commonMain/kotlin/okhttp3/MediaType.kt deleted file mode 100644 index f4d4e2a1f3eb..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/MediaType.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2013 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package okhttp3 - -/** - * An [RFC 2045][rfc_2045] Media Type, appropriate to describe the content type of an HTTP request - * or response body. - * - * [rfc_2045]: http://tools.ietf.org/html/rfc2045 - */ -expect class MediaType internal constructor( - mediaType: String, - type: String, - subtype: String, - parameterNamesAndValues: Array, -) { - internal val mediaType: String - - /** - * Returns the high-level media type, such as "text", "image", "audio", "video", or "application". - */ - val type: String - - /** - * Returns a specific media subtype, such as "plain" or "png", "mpeg", "mp4" or "xml". - */ - val subtype: String - - /** Alternating parameter names with their values, like `["charset", "utf-8"]`. */ - internal val parameterNamesAndValues: Array - - /** - * Returns the parameter [name] of this media type, or null if this media type does not define - * such a parameter. - */ - fun parameter(name: String): String? - - /** - * Returns the encoded media type, like "text/plain; charset=utf-8", appropriate for use in a - * Content-Type header. - */ - override fun toString(): String - - companion object { - /** - * Returns a media type for this string. - * - * @throws IllegalArgumentException if this is not a well-formed media type. - */ - fun String.toMediaType(): MediaType - - /** Returns a media type for this, or null if this is not a well-formed media type. */ - fun String.toMediaTypeOrNull(): MediaType? - } -} diff --git a/okhttp/src/commonMain/kotlin/okhttp3/Request.kt b/okhttp/src/commonMain/kotlin/okhttp3/Request.kt deleted file mode 100644 index 550ef66e0a5d..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/Request.kt +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2013 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package okhttp3 - -import kotlin.reflect.KClass -import okhttp3.internal.commonEmptyRequestBody - -/** - * An HTTP request. Instances of this class are immutable if their [body] is null or itself - * immutable. - */ -expect class Request private constructor(builder: Builder) { - val url: HttpUrl - val method: String - val headers: Headers - val body: RequestBody? - internal val tags: Map, Any> - - internal var lazyCacheControl: CacheControl? - - val isHttps: Boolean - - constructor( - url: HttpUrl, - headers: Headers = Headers.headersOf(), - method: String = "\u0000", // Sentinel value chooses based on what the body is. - body: RequestBody? = null, - ) - - fun header(name: String): String? - - fun headers(name: String): List - - /** Returns the tag attached with [T] as a key, or null if no tag is attached with that key. */ - inline fun tag(): T? - - /** Returns the tag attached with [type] as a key, or null if no tag is attached with that key. */ - fun tag(type: KClass): T? - - fun newBuilder(): Builder - - /** - * Returns the cache control directives for this response. This is never null, even if this - * response contains no `Cache-Control` header. - */ - val cacheControl: CacheControl - - open class Builder { - internal var url: HttpUrl? - internal var method: String - internal var headers: Headers.Builder - internal var body: RequestBody? - - /** A mutable map of tags, or an immutable empty map if we don't have any. */ - internal var tags: Map, Any> - - constructor() - - internal constructor(request: Request) - - // /** A mutable map of tags, or an immutable empty map if we don't have any. */ - // internal var tags: MutableMap, Any> = mutableMapOf() - - open fun url(url: HttpUrl): Builder - - /** - * Sets the URL target of this request. - * - * @throws IllegalArgumentException if [url] is not a valid HTTP or HTTPS URL. Avoid this - * exception by calling [HttpUrl.parse]; it returns null for invalid URLs. - */ - open fun url(url: String): Builder - - /** - * Sets the header named [name] to [value]. If this request already has any headers - * with that name, they are all replaced. - */ - open fun header(name: String, value: String): Builder - - /** - * Adds a header with [name] and [value]. Prefer this method for multiply-valued - * headers like "Cookie". - * - * Note that for some headers including `Content-Length` and `Content-Encoding`, - * OkHttp may replace [value] with a header derived from the request body. - */ - open fun addHeader(name: String, value: String): Builder - - /** Removes all headers named [name] on this builder. */ - open fun removeHeader(name: String): Builder - - /** Removes all headers on this builder and adds [headers]. */ - open fun headers(headers: Headers): Builder - - /** - * Sets this request's `Cache-Control` header, replacing any cache control headers already - * present. If [cacheControl] doesn't define any directives, this clears this request's - * cache-control headers. - */ - open fun cacheControl(cacheControl: CacheControl): Builder - - open fun get(): Builder - - open fun head(): Builder - - open fun post(body: RequestBody): Builder - - open fun delete(body: RequestBody? = commonEmptyRequestBody): Builder - - open fun put(body: RequestBody): Builder - - open fun patch(body: RequestBody): Builder - - open fun method(method: String, body: RequestBody?): Builder - - /** - * Attaches [tag] to the request using [T] as a key. Tags can be read from a request using - * [Request.tag]. Use null to remove any existing tag assigned for [T]. - * - * Use this API to attach timing, debugging, or other application data to a request so that - * you may read it in interceptors, event listeners, or callbacks. - */ - inline fun tag(tag: T?): Builder - - /** - * Attaches [tag] to the request using [type] as a key. Tags can be read from a request using - * [Request.tag]. Use null to remove any existing tag assigned for [type]. - * - * Use this API to attach timing, debugging, or other application data to a request so that - * you may read it in interceptors, event listeners, or callbacks. - */ - fun tag(type: KClass, tag: T?): Builder - - open fun build(): Request - } -} diff --git a/okhttp/src/commonMain/kotlin/okhttp3/RequestBody.kt b/okhttp/src/commonMain/kotlin/okhttp3/RequestBody.kt deleted file mode 100644 index 0af9f6427405..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/RequestBody.kt +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2014 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package okhttp3 - -import kotlin.jvm.JvmOverloads -import okio.BufferedSink -import okio.ByteString -import okio.IOException - -expect abstract class RequestBody constructor() { - - /** Returns the Content-Type header for this body. */ - abstract fun contentType(): MediaType? - - /** - * Returns the number of bytes that will be written to sink in a call to [writeTo], - * or -1 if that count is unknown. - */ - @Throws(IOException::class) - open fun contentLength(): Long - - /** Writes the content of this request to [sink]. */ - @Throws(IOException::class) - abstract fun writeTo(sink: BufferedSink) - - /** - * A duplex request body is special in how it is **transmitted** on the network and - * in the **API contract** between OkHttp and the application. - * - * This method returns false unless it is overridden by a subclass. - * - * ### Duplex Transmission - * - * With regular HTTP calls the request always completes sending before the response may begin - * receiving. With duplex the request and response may be interleaved! That is, request body bytes - * may be sent after response headers or body bytes have been received. - * - * Though any call may be initiated as a duplex call, only web servers that are specially - * designed for this nonstandard interaction will use it. As of 2019-01, the only widely-used - * implementation of this pattern is [gRPC][grpc]. - * - * Because the encoding of interleaved data is not well-defined for HTTP/1, duplex request - * bodies may only be used with HTTP/2. Calls to HTTP/1 servers will fail before the HTTP request - * is transmitted. If you cannot ensure that your client and server both support HTTP/2, do not - * use this feature. - * - * ### Duplex APIs - * - * With regular request bodies it is not legal to write bytes to the sink passed to - * [RequestBody.writeTo] after that method returns. For duplex requests bodies that condition is - * lifted. Such writes occur on an application-provided thread and may occur concurrently with - * reads of the [ResponseBody]. For duplex request bodies, [writeTo] should return - * quickly, possibly by handing off the provided request body to another thread to perform - * writing. - * - * [grpc]: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md - */ - open fun isDuplex(): Boolean - - /** - * Returns true if this body expects at most one call to [writeTo] and can be transmitted - * at most once. This is typically used when writing the request body is destructive and it is not - * possible to recreate the request body after it has been sent. - * - * This method returns false unless it is overridden by a subclass. - * - * By default OkHttp will attempt to retransmit request bodies when the original request fails - * due to any of: - * - * * A stale connection. The request was made on a reused connection and that reused connection - * has since been closed by the server. - * * A client timeout (HTTP 408). - * * A authorization challenge (HTTP 401 and 407) that is satisfied by the [Authenticator]. - * * A retryable server failure (HTTP 503 with a `Retry-After: 0` response header). - * * A misdirected request (HTTP 421) on a coalesced connection. - */ - open fun isOneShot(): Boolean - - companion object { - - /** - * Returns a new request body that transmits this string. If [contentType] is non-null and lacks - * a charset, this will use UTF-8. - */ - @JvmOverloads - fun String.toRequestBody(contentType: MediaType? = null): RequestBody - - /** Returns a new request body that transmits this. */ - @JvmOverloads - fun ByteString.toRequestBody(contentType: MediaType? = null): RequestBody - - /** Returns a new request body that transmits this. */ - @JvmOverloads - fun ByteArray.toRequestBody( - contentType: MediaType? = null, - offset: Int = 0, - byteCount: Int = size - ): RequestBody - } -} diff --git a/okhttp/src/commonMain/kotlin/okhttp3/Response.kt b/okhttp/src/commonMain/kotlin/okhttp3/Response.kt deleted file mode 100644 index 8d724a4d637b..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/Response.kt +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 2022 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package okhttp3 - -import okio.Closeable -import okio.IOException - -/** - * An HTTP response. Instances of this class are not immutable: the response body is a one-shot - * value that may be consumed only once and then closed. All other properties are immutable. - * - * This class implements [Closeable]. Closing it simply closes its response body. See - * [ResponseBody] for an explanation and examples. - */ -expect class Response : Closeable { - /** - * The request that initiated this HTTP response. This is not necessarily the same request issued - * by the application: - * - * * It may be transformed by the user's interceptors. For example, an application interceptor - * may add headers like `User-Agent`. - * * It may be the request generated in response to an HTTP redirect or authentication - * challenge. In this case the request URL may be different than the initial request URL. - * - * Use the `request` of the [networkResponse] field to get the wire-level request that was - * transmitted. In the case of follow-ups and redirects, also look at the `request` of the - * [priorResponse] objects, which have its own [priorResponse]. - */ - val request: Request - - /** Returns the HTTP protocol, such as [Protocol.HTTP_1_1] or [Protocol.HTTP_1_0]. */ - val protocol: Protocol - - /** Returns the HTTP status message. */ - val message: String - - /** Returns the HTTP status code. */ - val code: Int - - ///** - // * Returns the TLS handshake of the connection that carried this response, or null if the - // * response was received without TLS. - // */ - //val handshake: Handshake? - - /** Returns the HTTP headers. */ - val headers: Headers - - /** - * Returns a non-null value if this response was passed to [Callback.onResponse] or returned - * from [Call.execute]. Response bodies must be [closed][ResponseBody] and may - * be consumed only once. - * - * This always returns null on responses returned from [cacheResponse], [networkResponse], - * and [priorResponse]. - */ - val body: ResponseBody - - /** - * Returns the raw response received from the network. Will be null if this response didn't use - * the network, such as when the response is fully cached. The body of the returned response - * should not be read. - */ - val networkResponse: Response? - - /** - * Returns the raw response received from the cache. Will be null if this response didn't use - * the cache. For conditional get requests the cache response and network response may both be - * non-null. The body of the returned response should not be read. - */ - val cacheResponse: Response? - - /** - * Returns the response for the HTTP redirect or authorization challenge that triggered this - * response, or null if this response wasn't triggered by an automatic retry. The body of the - * returned response should not be read because it has already been consumed by the redirecting - * client. - */ - val priorResponse: Response? - - internal var lazyCacheControl: CacheControl? - - /** - * Returns true if the code is in [200..300), which means the request was successfully received, - * understood, and accepted. - */ - val isSuccessful: Boolean - - fun headers(name: String): List - - fun header(name: String, defaultValue: String? = null): String? - - /** - * Returns the trailers after the HTTP response, which may be empty. It is an error to call this - * before the entire HTTP response body has been consumed. - */ - @Throws(IOException::class) - fun trailers(): Headers - - /** - * Peeks up to [byteCount] bytes from the response body and returns them as a new response - * body. If fewer than [byteCount] bytes are in the response body, the full response body is - * returned. If more than [byteCount] bytes are in the response body, the returned value - * will be truncated to [byteCount] bytes. - * - * It is an error to call this method after the body has been consumed. - * - * **Warning:** this method loads the requested bytes into memory. Most applications should set - * a modest limit on `byteCount`, such as 1 MiB. - */ - @Throws(IOException::class) - fun peekBody(byteCount: Long): ResponseBody - - fun newBuilder(): Builder - - /** Returns true if this response redirects to another resource. */ - val isRedirect: Boolean - - // /** - // * Returns the RFC 7235 authorization challenges appropriate for this response's code. If the - // * response code is 401 unauthorized, this returns the "WWW-Authenticate" challenges. If the - // * response code is 407 proxy unauthorized, this returns the "Proxy-Authenticate" challenges. - // * Otherwise this returns an empty list of challenges. - // * - // * If a challenge uses the `token68` variant instead of auth params, there is exactly one - // * auth param in the challenge at key null. Invalid headers and challenges are ignored. - // * No semantic validation is done, for example that `Basic` auth must have a `realm` - // * auth param, this is up to the caller that interprets these challenges. - // */ - // fun challenges(): List - - /** - * Returns the cache control directives for this response. This is never null, even if this - * response contains no `Cache-Control` header. - */ - val cacheControl: CacheControl - - /** - * Closes the response body. Equivalent to `body().close()`. - * - * Prior to OkHttp 5.0, it was an error to close a response that is not eligible for a body. This - * includes the responses returned from [cacheResponse], [networkResponse], and [priorResponse]. - */ - override fun close() - - override fun toString(): String - - open class Builder { - internal var request: Request? - internal var protocol: Protocol? - internal var code: Int - internal var message: String? - // internal var handshake: Handshake? - internal var headers: Headers.Builder - internal var body: ResponseBody - internal var networkResponse: Response? - internal var cacheResponse: Response? - internal var priorResponse: Response? - internal var trailersFn: (() -> Headers) - - constructor() - - internal constructor(response: Response) - - open fun request(request: Request): Builder - - open fun protocol(protocol: Protocol): Builder - - open fun code(code: Int): Builder - - open fun message(message: String): Builder - - // open fun handshake(handshake: Handshake?): Builder - - /** - * Sets the header named [name] to [value]. If this request already has any headers - * with that name, they are all replaced. - */ - open fun header(name: String, value: String): Builder - - /** - * Adds a header with [name] to [value]. Prefer this method for multiply-valued - * headers like "Set-Cookie". - */ - open fun addHeader(name: String, value: String): Builder - - /** Removes all headers named [name] on this builder. */ - open fun removeHeader(name: String): Builder - - /** Removes all headers on this builder and adds [headers]. */ - open fun headers(headers: Headers): Builder - - open fun trailers(trailersFn: (() -> Headers)): Builder - - open fun body(body: ResponseBody): Builder - - open fun networkResponse(networkResponse: Response?): Builder - - open fun cacheResponse(cacheResponse: Response?): Builder - - open fun priorResponse(priorResponse: Response?): Builder - - open fun build(): Response - } -} diff --git a/okhttp/src/commonMain/kotlin/okhttp3/ResponseBody.kt b/okhttp/src/commonMain/kotlin/okhttp3/ResponseBody.kt deleted file mode 100644 index 0c149f4fcafc..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/ResponseBody.kt +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2022 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package okhttp3 - -import okio.BufferedSource -import okio.ByteString -import okio.Closeable -import okio.IOException - -/** - * A one-shot stream from the origin server to the client application with the raw bytes of the - * response body. Each response body is supported by an active connection to the webserver. This - * imposes both obligations and limits on the client application. - * - * ### The response body must be closed. - * - * Each response body is backed by a limited resource like a socket (live network responses) or - * an open file (for cached responses). Failing to close the response body will leak resources and - * may ultimately cause the application to slow down or crash. - * - * Both this class and [Response] implement [Closeable]. Closing a response simply - * closes its response body. If you invoke [Call.execute] or implement [Callback.onResponse] you - * must close this body by calling any of the following methods: - * - * * `Response.close()` - * * `Response.body().close()` - * * `Response.body().source().close()` - * * `Response.body().charStream().close()` - * * `Response.body().byteStream().close()` - * * `Response.body().bytes()` - * * `Response.body().string()` - * - * There is no benefit to invoking multiple `close()` methods for the same response body. - * - * For synchronous calls, the easiest way to make sure a response body is closed is with a `try` - * block. With this structure the compiler inserts an implicit `finally` clause that calls - * [close()][Response.close] for you. - * - * ```java - * Call call = client.newCall(request); - * try (Response response = call.execute()) { - * ... // Use the response. - * } - * ``` - * - * You can use a similar block for asynchronous calls: - * - * ```java - * Call call = client.newCall(request); - * call.enqueue(new Callback() { - * public void onResponse(Call call, Response response) throws IOException { - * try (ResponseBody responseBody = response.body()) { - * ... // Use the response. - * } - * } - * - * public void onFailure(Call call, IOException e) { - * ... // Handle the failure. - * } - * }); - * ``` - * - * These examples will not work if you're consuming the response body on another thread. In such - * cases the consuming thread must call [close] when it has finished reading the response - * body. - * - * ### The response body can be consumed only once. - * - * This class may be used to stream very large responses. For example, it is possible to use this - * class to read a response that is larger than the entire memory allocated to the current process. - * It can even stream a response larger than the total storage on the current device, which is a - * common requirement for video streaming applications. - * - * Because this class does not buffer the full response in memory, the application may not - * re-read the bytes of the response. Use this one shot to read the entire response into memory with - * [bytes] or [string]. Or stream the response with either [source], [byteStream], or [charStream]. - */ -expect abstract class ResponseBody constructor() : Closeable { - abstract fun contentType(): MediaType? - - /** - * Returns the number of bytes in that will returned by [bytes], or [byteStream], or -1 if - * unknown. - */ - abstract fun contentLength(): Long - - abstract fun source(): BufferedSource - - /** - * Returns the response as a byte array. - * - * This method loads entire response body into memory. If the response body is very large this - * may trigger an [OutOfMemoryError]. Prefer to stream the response body if this is a - * possibility for your response. - */ - @Throws(IOException::class) - fun bytes(): ByteArray - - /** - * Returns the response as a [ByteString]. - * - * This method loads entire response body into memory. If the response body is very large this - * may trigger an [OutOfMemoryError]. Prefer to stream the response body if this is a - * possibility for your response. - */ - @Throws(IOException::class) - fun byteString(): ByteString - - /** - * Returns the response as a string. - * - * On Non JVM Platforms, this only supports the UTF-8 encoding, all other encodings will - * be treated as unknown. - * - * On JVM Platforms: - * - * If the response starts with a - * [Byte Order Mark (BOM)](https://en.wikipedia.org/wiki/Byte_order_mark), it is consumed and - * used to determine the charset of the response bytes. - * - * Otherwise if the response has a `Content-Type` header that specifies a charset, that is used - * to determine the charset of the response bytes. - * - * Otherwise the response bytes are decoded as UTF-8. - * - * This method loads entire response body into memory. If the response body is very large this - * may trigger an [OutOfMemoryError]. Prefer to stream the response body if this is a - * possibility for your response. - */ - @Throws(IOException::class) - fun string(): String - - override fun close() - - companion object { - /** - * Returns a new response body that transmits this string. If [contentType] is non-null and - * has a charset other than utf-8 the behaviour differs by platform. - * - * On the JVM the encoding will be used instead of utf-8. - * - * On non JVM platforms, this method will fail for encodings other than utf-8. - */ - fun String.toResponseBody(contentType: MediaType? = null): ResponseBody - - /** Returns a new response body that transmits this byte array. */ - fun ByteArray.toResponseBody(contentType: MediaType? = null): ResponseBody - - /** Returns a new response body that transmits this byte string. */ - fun ByteString.toResponseBody(contentType: MediaType? = null): ResponseBody - - /** Returns a new response body that transmits this source. */ - fun BufferedSource.asResponseBody( - contentType: MediaType? = null, - contentLength: Long = -1L - ): ResponseBody - } -} diff --git a/okhttp/src/commonMain/kotlin/okhttp3/TlsVersion.kt b/okhttp/src/commonMain/kotlin/okhttp3/TlsVersion.kt deleted file mode 100644 index 21d3a75cc4e0..000000000000 --- a/okhttp/src/commonMain/kotlin/okhttp3/TlsVersion.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2021 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package okhttp3 - -/** - * Versions of TLS that can be offered when negotiating a secure socket. - */ -expect enum class TlsVersion { - TLS_1_3, // 2016. - TLS_1_2, // 2008. - TLS_1_1, // 2006. - TLS_1_0, // 1999. - SSL_3_0; // 1996. -} diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/-JvmPlatform.kt b/okhttp/src/jvmMain/kotlin/okhttp3/-JvmPlatform.kt index b7ae344e54d6..4e238d6e506d 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/-JvmPlatform.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/-JvmPlatform.kt @@ -17,4 +17,4 @@ package okhttp3 -actual typealias ProtocolException = java.net.ProtocolException +typealias ProtocolException = java.net.ProtocolException diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/CacheControl.kt b/okhttp/src/jvmMain/kotlin/okhttp3/CacheControl.kt index e7a0547e445a..5147d04eb8ca 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/CacheControl.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/CacheControl.kt @@ -38,7 +38,7 @@ import okhttp3.internal.commonToString * * See [RFC 7234, 5.2](https://tools.ietf.org/html/rfc7234#section-5.2). */ -actual class CacheControl internal actual constructor( +class CacheControl internal constructor( /** * In a response, this field's name "no-cache" is misleading. It doesn't prevent us from caching * the response; it only means we have to validate the response with the origin server before @@ -46,28 +46,28 @@ actual class CacheControl internal actual constructor( * * In a request, it means do not use a cache to satisfy the request. */ - @get:JvmName("noCache") actual val noCache: Boolean, + @get:JvmName("noCache") val noCache: Boolean, /** If true, this response should not be cached. */ - @get:JvmName("noStore") actual val noStore: Boolean, + @get:JvmName("noStore") val noStore: Boolean, /** The duration past the response's served date that it can be served without validation. */ - @get:JvmName("maxAgeSeconds") actual val maxAgeSeconds: Int, + @get:JvmName("maxAgeSeconds") val maxAgeSeconds: Int, /** * The "s-maxage" directive is the max age for shared caches. Not to be confused with "max-age" * for non-shared caches, As in Firefox and Chrome, this directive is not honored by this cache. */ - @get:JvmName("sMaxAgeSeconds") actual val sMaxAgeSeconds: Int, + @get:JvmName("sMaxAgeSeconds") val sMaxAgeSeconds: Int, - actual val isPrivate: Boolean, - actual val isPublic: Boolean, + val isPrivate: Boolean, + val isPublic: Boolean, - @get:JvmName("mustRevalidate") actual val mustRevalidate: Boolean, + @get:JvmName("mustRevalidate") val mustRevalidate: Boolean, - @get:JvmName("maxStaleSeconds") actual val maxStaleSeconds: Int, + @get:JvmName("maxStaleSeconds") val maxStaleSeconds: Int, - @get:JvmName("minFreshSeconds") actual val minFreshSeconds: Int, + @get:JvmName("minFreshSeconds") val minFreshSeconds: Int, /** * This field's name "only-if-cached" is misleading. It actually means "do not use the network". @@ -75,13 +75,13 @@ actual class CacheControl internal actual constructor( * cache. Cached responses that would require validation (ie. conditional gets) are not permitted * if this header is set. */ - @get:JvmName("onlyIfCached") actual val onlyIfCached: Boolean, + @get:JvmName("onlyIfCached") val onlyIfCached: Boolean, - @get:JvmName("noTransform") actual val noTransform: Boolean, + @get:JvmName("noTransform") val noTransform: Boolean, - @get:JvmName("immutable") actual val immutable: Boolean, + @get:JvmName("immutable") val immutable: Boolean, - internal actual var headerValue: String? + internal var headerValue: String? ) { @JvmName("-deprecated_noCache") @Deprecated( @@ -153,35 +153,35 @@ actual class CacheControl internal actual constructor( level = DeprecationLevel.ERROR) fun immutable(): Boolean = immutable - actual override fun toString(): String = commonToString() + override fun toString(): String = commonToString() /** Builds a `Cache-Control` request header. */ - actual class Builder { - internal actual var noCache: Boolean = false - internal actual var noStore: Boolean = false - internal actual var maxAgeSeconds = -1 - internal actual var maxStaleSeconds = -1 - internal actual var minFreshSeconds = -1 - internal actual var onlyIfCached: Boolean = false - internal actual var noTransform: Boolean = false - internal actual var immutable: Boolean = false + class Builder { + internal var noCache: Boolean = false + internal var noStore: Boolean = false + internal var maxAgeSeconds = -1 + internal var maxStaleSeconds = -1 + internal var minFreshSeconds = -1 + internal var onlyIfCached: Boolean = false + internal var noTransform: Boolean = false + internal var immutable: Boolean = false /** Don't accept an unvalidated cached response. */ - actual fun noCache() = commonNoCache() + fun noCache() = commonNoCache() /** Don't store the server's response in any cache. */ - actual fun noStore() = commonNoStore() + fun noStore() = commonNoStore() /** * Only accept the response if it is in the cache. If the response isn't cached, a `504 * Unsatisfiable Request` response will be returned. */ - actual fun onlyIfCached() = commonOnlyIfCached() + fun onlyIfCached() = commonOnlyIfCached() /** Don't accept a transformed response. */ - actual fun noTransform() = commonNoTransform() + fun noTransform() = commonNoTransform() - actual fun immutable() = commonImmutable() + fun immutable() = commonImmutable() /** * Sets the maximum age of a cached response. If the cache response's age exceeds [maxAge], it @@ -190,11 +190,11 @@ actual class CacheControl internal actual constructor( * @param maxAge a non-negative integer. This is stored and transmitted with [TimeUnit.SECONDS] * precision; finer precision will be lost. */ - actual fun maxAge(maxAge: Int, timeUnit: DurationUnit) = commonMaxAge(maxAge, timeUnit) + fun maxAge(maxAge: Int, timeUnit: DurationUnit) = commonMaxAge(maxAge, timeUnit) - actual fun maxStale(maxStale: Int, timeUnit: DurationUnit) = commonMaxStale(maxStale, timeUnit) + fun maxStale(maxStale: Int, timeUnit: DurationUnit) = commonMaxStale(maxStale, timeUnit) - actual fun minFresh(minFresh: Int, timeUnit: DurationUnit) = commonMinFresh(minFresh, timeUnit) + fun minFresh(minFresh: Int, timeUnit: DurationUnit) = commonMinFresh(minFresh, timeUnit) /** * Sets the maximum age of a cached response. If the cache response's age exceeds [maxAge], it @@ -236,16 +236,16 @@ actual class CacheControl internal actual constructor( this.minFreshSeconds = minFreshSecondsLong.commonClampToInt() } - actual fun build(): CacheControl = commonBuild() + fun build(): CacheControl = commonBuild() } - actual companion object { + companion object { /** * Cache control request directives that require network validation of responses. Note that such * requests may be assisted by the cache via conditional GET requests. */ @JvmField - actual val FORCE_NETWORK = commonForceNetwork() + val FORCE_NETWORK = commonForceNetwork() /** * Cache control request directives that uses the cache only, even if the cached response is @@ -253,13 +253,13 @@ actual class CacheControl internal actual constructor( * will fail with a `504 Unsatisfiable Request`. */ @JvmField - actual val FORCE_CACHE = commonForceCache() + val FORCE_CACHE = commonForceCache() /** * Returns the cache directives of [headers]. This honors both Cache-Control and Pragma headers * if they are present. */ @JvmStatic - actual fun parse(headers: Headers): CacheControl = commonParse(headers) + fun parse(headers: Headers): CacheControl = commonParse(headers) } } diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/Call.kt b/okhttp/src/jvmMain/kotlin/okhttp3/Call.kt index d3953bdc0d24..fdd3d3da294e 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/Call.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/Call.kt @@ -22,9 +22,9 @@ import okio.Timeout * A call is a request that has been prepared for execution. A call can be canceled. As this object * represents a single request/response pair (stream), it cannot be executed twice. */ -actual interface Call : Cloneable { +interface Call : Cloneable { /** Returns the original request that initiated this call. */ - actual fun request(): Request + fun request(): Request /** * Invokes the request immediately, and blocks until the response can be processed or is in error. @@ -65,18 +65,18 @@ actual interface Call : Cloneable { * * @throws IllegalStateException when the call has already been executed. */ - actual fun enqueue(responseCallback: Callback) + fun enqueue(responseCallback: Callback) /** Cancels the request, if possible. Requests that are already complete cannot be canceled. */ - actual fun cancel() + fun cancel() /** * Returns true if this call has been either [executed][execute] or [enqueued][enqueue]. It is an * error to execute a call more than once. */ - actual fun isExecuted(): Boolean + fun isExecuted(): Boolean - actual fun isCanceled(): Boolean + fun isCanceled(): Boolean /** * Returns a timeout that spans the entire call: resolving DNS, connecting, writing the request @@ -91,9 +91,9 @@ actual interface Call : Cloneable { * Create a new, identical call to this one which can be enqueued or executed even if this call * has already been. */ - public actual override fun clone(): Call + public override fun clone(): Call - actual fun interface Factory { - actual fun newCall(request: Request): Call + fun interface Factory { + fun newCall(request: Request): Call } } diff --git a/okhttp/src/commonMain/kotlin/okhttp3/Callback.kt b/okhttp/src/jvmMain/kotlin/okhttp3/Callback.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/Callback.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/Callback.kt diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/Challenge.kt b/okhttp/src/jvmMain/kotlin/okhttp3/Challenge.kt index eca4372ba87a..1ceaa87c2f26 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/Challenge.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/Challenge.kt @@ -29,9 +29,9 @@ import okhttp3.internal.commonToString * * [rfc_7235]: https://tools.ietf.org/html/rfc7235 */ -actual class Challenge actual constructor( +class Challenge( /** Returns the authentication scheme, like `Basic`. */ - @get:JvmName("scheme") actual val scheme: String, + @get:JvmName("scheme") val scheme: String, authParams: Map ) { @@ -39,10 +39,10 @@ actual class Challenge actual constructor( * Returns the auth params, including [realm] and [charset] if present, but as * strings. The map's keys are lowercase and should be treated case-insensitively. */ - @get:JvmName("authParams") actual val authParams: Map + @get:JvmName("authParams") val authParams: Map /** Returns the protection space. */ - @get:JvmName("realm") actual val realm: String? + @get:JvmName("realm") val realm: String? get() = authParams["realm"] /** The charset that should be used to encode the credentials. */ @@ -58,7 +58,7 @@ actual class Challenge actual constructor( return ISO_8859_1 } - actual constructor(scheme: String, realm: String) : this(scheme, singletonMap("realm", realm)) + constructor(scheme: String, realm: String) : this(scheme, singletonMap("realm", realm)) init { val newAuthParams = mutableMapOf() @@ -104,9 +104,9 @@ actual class Challenge actual constructor( level = DeprecationLevel.ERROR) fun charset(): Charset = charset - actual override fun equals(other: Any?): Boolean = commonEquals(other) + override fun equals(other: Any?): Boolean = commonEquals(other) - actual override fun hashCode(): Int = commonHashCode() + override fun hashCode(): Int = commonHashCode() - actual override fun toString(): String = commonToString() + override fun toString(): String = commonToString() } diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/Headers.kt b/okhttp/src/jvmMain/kotlin/okhttp3/Headers.kt index 71ba54992257..da74b0504bdc 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/Headers.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/Headers.kt @@ -63,11 +63,11 @@ import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement * Instances of this class are immutable. Use [Builder] to create instances. */ @Suppress("NAME_SHADOWING") -actual class Headers internal actual constructor( - internal actual val namesAndValues: Array +class Headers internal constructor( + internal val namesAndValues: Array ) : Iterable> { /** Returns the last value corresponding to the specified field, or null. */ - actual operator fun get(name: String): String? = commonHeadersGet(namesAndValues, name) + operator fun get(name: String): String? = commonHeadersGet(namesAndValues, name) /** * Returns the last value corresponding to the specified field parsed as an HTTP date, or null if @@ -85,7 +85,7 @@ actual class Headers internal actual constructor( } /** Returns the number of field values. */ - @get:JvmName("size") actual val size: Int + @get:JvmName("size") val size: Int get() = namesAndValues.size / 2 @JvmName("-deprecated_size") @@ -96,13 +96,13 @@ actual class Headers internal actual constructor( fun size(): Int = size /** Returns the field at `position`. */ - actual fun name(index: Int): String = commonName(index) + fun name(index: Int): String = commonName(index) /** Returns the value at `index`. */ - actual fun value(index: Int): String = commonValue(index) + fun value(index: Int): String = commonValue(index) /** Returns an immutable case-insensitive set of header names. */ - actual fun names(): Set { + fun names(): Set { val result = TreeSet(String.CASE_INSENSITIVE_ORDER) for (i in 0 until size) { result.add(name(i)) @@ -111,7 +111,7 @@ actual class Headers internal actual constructor( } /** Returns an immutable list of the header values for `name`. */ - actual fun values(name: String): List = commonValues(name) + fun values(name: String): List = commonValues(name) /** * Returns the number of bytes required to encode these headers using HTTP/1.1. This is also the @@ -130,9 +130,9 @@ actual class Headers internal actual constructor( return result } - actual override operator fun iterator(): Iterator> = commonIterator() + override operator fun iterator(): Iterator> = commonIterator() - actual fun newBuilder(): Builder = commonNewBuilder() + fun newBuilder(): Builder = commonNewBuilder() /** * Returns true if `other` is a `Headers` object with the same headers, with the same casing, in @@ -170,7 +170,7 @@ actual class Headers internal actual constructor( * Applications that require semantically equal headers should convert them into a canonical form * before comparing them for equality. */ - actual override fun equals(other: Any?): Boolean = commonEquals(other) + override fun equals(other: Any?): Boolean = commonEquals(other) override fun hashCode(): Int = commonHashCode() @@ -185,7 +185,7 @@ actual class Headers internal actual constructor( * * `Proxy-Authorization` * * `Set-Cookie` */ - actual override fun toString(): String = commonToString() + override fun toString(): String = commonToString() fun toMultimap(): Map> { val result = TreeMap>(String.CASE_INSENSITIVE_ORDER) @@ -201,8 +201,8 @@ actual class Headers internal actual constructor( return result } - actual class Builder { - internal actual val namesAndValues: MutableList = ArrayList(20) + class Builder { + internal val namesAndValues: MutableList = ArrayList(20) /** * Add a header line without any validation. Only appropriate for headers from the remote peer @@ -236,7 +236,7 @@ actual class Headers internal actual constructor( /** * Add a header with the specified name and value. Does validation of header names and values. */ - actual fun add(name: String, value: String) = commonAdd(name, value) + fun add(name: String, value: String) = commonAdd(name, value) /** * Add a header with the specified name and value. Does validation of header names, allowing @@ -250,7 +250,7 @@ actual class Headers internal actual constructor( /** * Adds all headers from an existing collection. */ - actual fun addAll(headers: Headers) = commonAddAll(headers) + fun addAll(headers: Headers) = commonAddAll(headers) /** * Add a header with the specified name and formatted date. Does validation of header names and @@ -284,28 +284,28 @@ actual class Headers internal actual constructor( */ internal fun addLenient(name: String, value: String) = commonAddLenient(name, value) - actual fun removeAll(name: String) = commonRemoveAll(name) + fun removeAll(name: String) = commonRemoveAll(name) /** * Set a field with the specified value. If the field is not found, it is added. If the field is * found, the existing values are replaced. */ - actual operator fun set(name: String, value: String) = commonSet(name, value) + operator fun set(name: String, value: String) = commonSet(name, value) /** Equivalent to `build().get(name)`, but potentially faster. */ - actual operator fun get(name: String): String? = commonGet(name) + operator fun get(name: String): String? = commonGet(name) - actual fun build(): Headers = commonBuild() + fun build(): Headers = commonBuild() } - actual companion object { + companion object { /** * Returns headers for the alternating header names and values. There must be an even number of * arguments, and they must alternate between header names and values. */ @JvmStatic @JvmName("of") - actual fun headersOf(vararg namesAndValues: String): Headers = commonHeadersOf(*namesAndValues) + fun headersOf(vararg namesAndValues: String): Headers = commonHeadersOf(*namesAndValues) @JvmName("-deprecated_of") @Deprecated( @@ -319,7 +319,7 @@ actual class Headers internal actual constructor( /** Returns headers for the header names and values in the [Map]. */ @JvmStatic @JvmName("of") - actual fun Map.toHeaders(): Headers = commonToHeaders() + fun Map.toHeaders(): Headers = commonToHeaders() @JvmName("-deprecated_of") @Deprecated( diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/HttpUrl.kt b/okhttp/src/jvmMain/kotlin/okhttp3/HttpUrl.kt index 7fef4e460e4d..07dc1f77f625 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/HttpUrl.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/HttpUrl.kt @@ -320,9 +320,9 @@ import okhttp3.internal.publicsuffix.PublicSuffixDatabase * * [idna]: http://www.unicode.org/reports/tr46/#ToASCII */ -actual class HttpUrl internal actual constructor( +class HttpUrl internal constructor( /** Either "http" or "https". */ - @get:JvmName("scheme") actual val scheme: String, + @get:JvmName("scheme") val scheme: String, /** * The decoded username, or an empty string if none is present. @@ -334,7 +334,7 @@ actual class HttpUrl internal actual constructor( * | `http://username:password@host/` | `"username"` | * | `http://a%20b:c%20d@host/` | `"a b"` | */ - @get:JvmName("username") actual val username: String, + @get:JvmName("username") val username: String, /** * Returns the decoded password, or an empty string if none is present. @@ -346,7 +346,7 @@ actual class HttpUrl internal actual constructor( * | `http://username:password@host/` | `"password"` | * | `http://a%20b:c%20d@host/` | `"c d"` | */ - @get:JvmName("password") actual val password: String, + @get:JvmName("password") val password: String, /** * The host address suitable for use with [InetAddress.getAllByName]. May be: @@ -366,7 +366,7 @@ actual class HttpUrl internal actual constructor( * | `http://[::1]/` | `"::1"` | * | `http://xn--n3h.net/` | `"xn--n3h.net"` | */ - @get:JvmName("host") actual val host: String, + @get:JvmName("host") val host: String, /** * The explicitly-specified port if one was provided, or the default port for this URL's scheme. @@ -379,7 +379,7 @@ actual class HttpUrl internal actual constructor( * | `http://host:8000/` | `8000` | * | `https://host/` | `443` | */ - @get:JvmName("port") actual val port: Int, + @get:JvmName("port") val port: Int, /** * A list of path segments like `["a", "b", "c"]` for the URL `http://host/a/b/c`. This list is @@ -391,14 +391,14 @@ actual class HttpUrl internal actual constructor( * | `http://host/a/b/c"` | `["a", "b", "c"]` | * | `http://host/a/b%20c/d"` | `["a", "b c", "d"]` | */ - @get:JvmName("pathSegments") actual val pathSegments: List, + @get:JvmName("pathSegments") val pathSegments: List, /** * Alternating, decoded query names and values, or null for no query. Names may be empty or * non-empty, but never null. Values are null if the name has no corresponding '=' separator, or * empty, or non-empty. */ - internal actual val queryNamesAndValues: List?, + internal val queryNamesAndValues: List?, /** * This URL's fragment, like `"abc"` for `http://host/#abc`. This is null if the URL has no @@ -411,12 +411,12 @@ actual class HttpUrl internal actual constructor( * | `http://host/#abc` | `"abc"` | * | `http://host/#abc|def` | `"abc|def"` | */ - @get:JvmName("fragment") actual val fragment: String?, + @get:JvmName("fragment") val fragment: String?, /** Canonical URL. */ - internal actual val url: String + internal val url: String ) { - actual val isHttps: Boolean + val isHttps: Boolean get() = scheme == "https" /** Returns this URL as a [java.net.URL][URL]. */ @@ -466,7 +466,7 @@ actual class HttpUrl internal actual constructor( * | `http://username:password@host/` | `"username"` | * | `http://a%20b:c%20d@host/` | `"a%20b"` | */ - @get:JvmName("encodedUsername") actual val encodedUsername: String + @get:JvmName("encodedUsername") val encodedUsername: String get() = commonEncodedUsername /** @@ -479,7 +479,7 @@ actual class HttpUrl internal actual constructor( * | `http://username:password@host/` | `"password"` | * | `http://a%20b:c%20d@host/` | `"c%20d"` | */ - @get:JvmName("encodedPassword") actual val encodedPassword: String + @get:JvmName("encodedPassword") val encodedPassword: String get() = commonEncodedPassword /** @@ -493,7 +493,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/a/b/c/` | `4` | */ @get:JvmName("pathSize") - actual val pathSize: Int + val pathSize: Int get() = commonPathSize /** @@ -506,7 +506,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/a/b/c` | `"/a/b/c"` | * | `http://host/a/b%20c/d` | `"/a/b%20c/d"` | */ - @get:JvmName("encodedPath") actual val encodedPath: String + @get:JvmName("encodedPath") val encodedPath: String get() = commonEncodedPath /** @@ -519,7 +519,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/a/b/c` | `["a", "b", "c"]` | * | `http://host/a/b%20c/d` | `["a", "b%20c", "d"]` | */ - @get:JvmName("encodedPathSegments") actual val encodedPathSegments: List + @get:JvmName("encodedPathSegments") val encodedPathSegments: List get() = commonEncodedPathSegments /** @@ -534,7 +534,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/?a=apple&a=apricot` | `"a=apple&a=apricot"` | * | `http://host/?a=apple&b` | `"a=apple&b"` | */ - @get:JvmName("encodedQuery") actual val encodedQuery: String? + @get:JvmName("encodedQuery") val encodedQuery: String? get() = commonEncodedQuery /** @@ -550,7 +550,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/?a=apple&a=apricot` | `"a=apple&a=apricot"` | * | `http://host/?a=apple&b` | `"a=apple&b"` | */ - @get:JvmName("query") actual val query: String? + @get:JvmName("query") val query: String? get() = commonQuery /** @@ -566,7 +566,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/?a=apple&a=apricot` | `2` | * | `http://host/?a=apple&b` | `2` | */ - @get:JvmName("querySize") actual val querySize: Int + @get:JvmName("querySize") val querySize: Int get() = commonQuerySize /** @@ -581,7 +581,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/?a=apple&a=apricot` | `"apple"` | * | `http://host/?a=apple&b` | `"apple"` | */ - actual fun queryParameter(name: String): String? = commonQueryParameter(name) + fun queryParameter(name: String): String? = commonQueryParameter(name) /** * The distinct query parameter names in this URL, like `["a", "b"]` for @@ -595,7 +595,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/?a=apple&a=apricot` | `["a"]` | * | `http://host/?a=apple&b` | `["a", "b"]` | */ - actual @get:JvmName("queryParameterNames") val queryParameterNames: Set + @get:JvmName("queryParameterNames") val queryParameterNames: Set get() = commonQueryParameterNames /** @@ -611,7 +611,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/?a=apple&a=apricot` | `["apple", "apricot"]` | `[]` | * | `http://host/?a=apple&b` | `["apple"]` | `[null]` | */ - actual fun queryParameterValues(name: String): List = commonQueryParameterValues(name) + fun queryParameterValues(name: String): List = commonQueryParameterValues(name) /** * Returns the name of the query parameter at `index`. For example this returns `"a"` @@ -626,7 +626,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/?a=apple&a=apricot` | `"a"` | `"a"` | * | `http://host/?a=apple&b` | `"a"` | `"b"` | */ - actual fun queryParameterName(index: Int): String = commonQueryParameterName(index) + fun queryParameterName(index: Int): String = commonQueryParameterName(index) /** * Returns the value of the query parameter at `index`. For example this returns `"apple"` for @@ -641,7 +641,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/?a=apple&a=apricot` | `"apple"` | `"apricot"` | * | `http://host/?a=apple&b` | `"apple"` | null | */ - actual fun queryParameterValue(index: Int): String? = commonQueryParameterValue(index) + fun queryParameterValue(index: Int): String? = commonQueryParameterValue(index) /** * This URL's encoded fragment, like `"abc"` for `http://host/#abc`. This is null if the URL has @@ -655,7 +655,7 @@ actual class HttpUrl internal actual constructor( * | `http://host/#abc|def` | `"abc|def"` | */ @get:JvmName("encodedFragment") - actual val encodedFragment: String? + val encodedFragment: String? get() = commonEncodedFragment /** @@ -663,24 +663,24 @@ actual class HttpUrl internal actual constructor( * stripped, and its path replaced with `/...`. For example, redacting * `http://username:password@example.com/path` returns `http://example.com/...`. */ - actual fun redact(): String = commonRedact() + fun redact(): String = commonRedact() /** * Returns the URL that would be retrieved by following `link` from this URL, or null if the * resulting URL is not well-formed. */ - actual fun resolve(link: String): HttpUrl? = commonResolve(link) + fun resolve(link: String): HttpUrl? = commonResolve(link) /** * Returns a builder based on this URL. */ - actual fun newBuilder(): Builder = commonNewBuilder() + fun newBuilder(): Builder = commonNewBuilder() /** * Returns a builder for the URL that would be retrieved by following `link` from this URL, * or null if the resulting URL is not well-formed. */ - actual fun newBuilder(link: String): Builder? = commonNewBuilder(link) + fun newBuilder(link: String): Builder? = commonNewBuilder(link) override fun equals(other: Any?): Boolean = commonEquals(other) @@ -846,82 +846,82 @@ actual class HttpUrl internal actual constructor( level = DeprecationLevel.ERROR) fun fragment(): String? = fragment - actual class Builder { - internal actual var scheme: String? = null - internal actual var encodedUsername = "" - internal actual var encodedPassword = "" - internal actual var host: String? = null - internal actual var port = -1 - internal actual val encodedPathSegments = mutableListOf("") - internal actual var encodedQueryNamesAndValues: MutableList? = null - internal actual var encodedFragment: String? = null + class Builder { + internal var scheme: String? = null + internal var encodedUsername = "" + internal var encodedPassword = "" + internal var host: String? = null + internal var port = -1 + internal val encodedPathSegments = mutableListOf("") + internal var encodedQueryNamesAndValues: MutableList? = null + internal var encodedFragment: String? = null /** * @param scheme either "http" or "https". */ - actual fun scheme(scheme: String) = commonScheme(scheme) + fun scheme(scheme: String) = commonScheme(scheme) - actual fun username(username: String) = commonUsername(username) + fun username(username: String) = commonUsername(username) - actual fun encodedUsername(encodedUsername: String) = commonEncodedUsername(encodedUsername) + fun encodedUsername(encodedUsername: String) = commonEncodedUsername(encodedUsername) - actual fun password(password: String) = commonPassword(password) + fun password(password: String) = commonPassword(password) - actual fun encodedPassword(encodedPassword: String) = commonEncodedPassword(encodedPassword) + fun encodedPassword(encodedPassword: String) = commonEncodedPassword(encodedPassword) /** * @param host either a regular hostname, International Domain Name, IPv4 address, or IPv6 * address. */ - actual fun host(host: String) = commonHost(host) + fun host(host: String) = commonHost(host) - actual fun port(port: Int) = commonPort(port) + fun port(port: Int) = commonPort(port) - actual fun addPathSegment(pathSegment: String) = commonAddPathSegment(pathSegment) + fun addPathSegment(pathSegment: String) = commonAddPathSegment(pathSegment) /** * Adds a set of path segments separated by a slash (either `\` or `/`). If `pathSegments` * starts with a slash, the resulting URL will have empty path segment. */ - actual fun addPathSegments(pathSegments: String): Builder = commonAddPathSegments(pathSegments) + fun addPathSegments(pathSegments: String): Builder = commonAddPathSegments(pathSegments) - actual fun addEncodedPathSegment(encodedPathSegment: String) = commonAddEncodedPathSegment(encodedPathSegment) + fun addEncodedPathSegment(encodedPathSegment: String) = commonAddEncodedPathSegment(encodedPathSegment) /** * Adds a set of encoded path segments separated by a slash (either `\` or `/`). If * `encodedPathSegments` starts with a slash, the resulting URL will have empty path segment. */ - actual fun addEncodedPathSegments(encodedPathSegments: String): Builder = commonAddEncodedPathSegments(encodedPathSegments) + fun addEncodedPathSegments(encodedPathSegments: String): Builder = commonAddEncodedPathSegments(encodedPathSegments) - actual fun setPathSegment(index: Int, pathSegment: String) = commonSetPathSegment(index, pathSegment) + fun setPathSegment(index: Int, pathSegment: String) = commonSetPathSegment(index, pathSegment) - actual fun setEncodedPathSegment(index: Int, encodedPathSegment: String) = commonSetEncodedPathSegment(index, encodedPathSegment) + fun setEncodedPathSegment(index: Int, encodedPathSegment: String) = commonSetEncodedPathSegment(index, encodedPathSegment) - actual fun removePathSegment(index: Int) = commonRemovePathSegment(index) + fun removePathSegment(index: Int) = commonRemovePathSegment(index) - actual fun encodedPath(encodedPath: String) = commonEncodedPath(encodedPath) + fun encodedPath(encodedPath: String) = commonEncodedPath(encodedPath) - actual fun query(query: String?) = commonQuery(query) + fun query(query: String?) = commonQuery(query) - actual fun encodedQuery(encodedQuery: String?) = commonEncodedQuery(encodedQuery) + fun encodedQuery(encodedQuery: String?) = commonEncodedQuery(encodedQuery) /** Encodes the query parameter using UTF-8 and adds it to this URL's query string. */ - actual fun addQueryParameter(name: String, value: String?) = commonAddQueryParameter(name, value) + fun addQueryParameter(name: String, value: String?) = commonAddQueryParameter(name, value) /** Adds the pre-encoded query parameter to this URL's query string. */ - actual fun addEncodedQueryParameter(encodedName: String, encodedValue: String?) = commonAddEncodedQueryParameter(encodedName, encodedValue) + fun addEncodedQueryParameter(encodedName: String, encodedValue: String?) = commonAddEncodedQueryParameter(encodedName, encodedValue) - actual fun setQueryParameter(name: String, value: String?) = commonSetQueryParameter(name, value) + fun setQueryParameter(name: String, value: String?) = commonSetQueryParameter(name, value) - actual fun setEncodedQueryParameter(encodedName: String, encodedValue: String?) = commonSetEncodedQueryParameter(encodedName, encodedValue) + fun setEncodedQueryParameter(encodedName: String, encodedValue: String?) = commonSetEncodedQueryParameter(encodedName, encodedValue) - actual fun removeAllQueryParameters(name: String) = commonRemoveAllQueryParameters(name) + fun removeAllQueryParameters(name: String) = commonRemoveAllQueryParameters(name) - actual fun removeAllEncodedQueryParameters(encodedName: String) = commonRemoveAllEncodedQueryParameters(encodedName) + fun removeAllEncodedQueryParameters(encodedName: String) = commonRemoveAllEncodedQueryParameters(encodedName) - actual fun fragment(fragment: String?) = commonFragment(fragment) + fun fragment(fragment: String?) = commonFragment(fragment) - actual fun encodedFragment(encodedFragment: String?) = commonEncodedFragment(encodedFragment) + fun encodedFragment(encodedFragment: String?) = commonEncodedFragment(encodedFragment) /** * Re-encodes the components of this URL so that it satisfies (obsolete) RFC 2396, which is @@ -958,16 +958,16 @@ actual class HttpUrl internal actual constructor( ) } - actual fun build(): HttpUrl = commonBuild() + fun build(): HttpUrl = commonBuild() override fun toString(): String = commonToString() - internal actual fun parse(base: HttpUrl?, input: String): Builder = commonParse(base, input) + internal fun parse(base: HttpUrl?, input: String): Builder = commonParse(base, input) } - actual companion object { + companion object { @JvmStatic - actual fun defaultPort(scheme: String): Int = commonDefaultPort(scheme) + fun defaultPort(scheme: String): Int = commonDefaultPort(scheme) /** * Returns a new [HttpUrl] representing this. @@ -975,7 +975,7 @@ actual class HttpUrl internal actual constructor( * @throws IllegalArgumentException If this is not a well-formed HTTP or HTTPS URL. */ @JvmStatic - @JvmName("get") actual fun String.toHttpUrl(): HttpUrl = commonToHttpUrl() + @JvmName("get") fun String.toHttpUrl(): HttpUrl = commonToHttpUrl() /** * Returns a new `HttpUrl` representing `url` if it is a well-formed HTTP or HTTPS URL, or null @@ -983,7 +983,7 @@ actual class HttpUrl internal actual constructor( */ @JvmStatic @JvmName("parse") - actual fun String.toHttpUrlOrNull(): HttpUrl? = commonToHttpUrlOrNull() + fun String.toHttpUrlOrNull(): HttpUrl? = commonToHttpUrlOrNull() /** * Returns an [HttpUrl] for this if its protocol is `http` or `https`, or null if it has any diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/MediaType.kt b/okhttp/src/jvmMain/kotlin/okhttp3/MediaType.kt index 20bca3d153b8..8980142e97b9 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/MediaType.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/MediaType.kt @@ -29,21 +29,21 @@ import okhttp3.internal.commonToString * * [rfc_2045]: http://tools.ietf.org/html/rfc2045 */ -actual class MediaType internal actual constructor( - internal actual val mediaType: String, +class MediaType internal constructor( + internal val mediaType: String, /** * Returns the high-level media type, such as "text", "image", "audio", "video", or "application". */ - @get:JvmName("type") actual val type: String, + @get:JvmName("type") val type: String, /** * Returns a specific media subtype, such as "plain" or "png", "mpeg", "mp4" or "xml". */ - @get:JvmName("subtype") actual val subtype: String, + @get:JvmName("subtype") val subtype: String, /** Alternating parameter names with their values, like `["charset", "utf-8"]`. */ - internal actual val parameterNamesAndValues: Array + internal val parameterNamesAndValues: Array ) { /** @@ -64,7 +64,7 @@ actual class MediaType internal actual constructor( * Returns the parameter [name] of this media type, or null if this media type does not define * such a parameter. */ - actual fun parameter(name: String): String? = commonParameter(name) + fun parameter(name: String): String? = commonParameter(name) @JvmName("-deprecated_type") @Deprecated( @@ -86,13 +86,13 @@ actual class MediaType internal actual constructor( * Returns the encoded media type, like "text/plain; charset=utf-8", appropriate for use in a * Content-Type header. */ - actual override fun toString(): String = commonToString() + override fun toString(): String = commonToString() override fun equals(other: Any?): Boolean = commonEquals(other) override fun hashCode(): Int = commonHashCode() - actual companion object { + companion object { /** * Returns a media type for this string. * @@ -100,12 +100,12 @@ actual class MediaType internal actual constructor( */ @JvmStatic @JvmName("get") - actual fun String.toMediaType(): MediaType = commonToMediaType() + fun String.toMediaType(): MediaType = commonToMediaType() /** Returns a media type for this, or null if this is not a well-formed media type. */ @JvmStatic @JvmName("parse") - actual fun String.toMediaTypeOrNull(): MediaType? = commonToMediaTypeOrNull() + fun String.toMediaTypeOrNull(): MediaType? = commonToMediaTypeOrNull() @JvmName("-deprecated_get") @Deprecated( diff --git a/okhttp/src/commonMain/kotlin/okhttp3/OkHttp.kt b/okhttp/src/jvmMain/kotlin/okhttp3/OkHttp.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/OkHttp.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/OkHttp.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/Protocol.kt b/okhttp/src/jvmMain/kotlin/okhttp3/Protocol.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/Protocol.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/Protocol.kt diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/Request.kt b/okhttp/src/jvmMain/kotlin/okhttp3/Request.kt index 355776851848..5e8bf27af87f 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/Request.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/Request.kt @@ -18,11 +18,13 @@ package okhttp3 import java.net.URL import kotlin.reflect.KClass import kotlin.reflect.cast +import okhttp3.Headers.Companion.headersOf import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.internal.canonicalUrl import okhttp3.internal.commonAddHeader import okhttp3.internal.commonCacheControl import okhttp3.internal.commonDelete +import okhttp3.internal.commonEmptyRequestBody import okhttp3.internal.commonGet import okhttp3.internal.commonHead import okhttp3.internal.commonHeader @@ -39,24 +41,24 @@ import okhttp3.internal.commonToString * An HTTP request. Instances of this class are immutable if their [body] is null or itself * immutable. */ -actual class Request internal actual constructor(builder: Builder) { +class Request internal constructor(builder: Builder) { @get:JvmName("url") - actual val url: HttpUrl = checkNotNull(builder.url) { "url == null" } + val url: HttpUrl = checkNotNull(builder.url) { "url == null" } @get:JvmName("method") - actual val method: String = builder.method + val method: String = builder.method @get:JvmName("headers") - actual val headers: Headers = builder.headers.build() + val headers: Headers = builder.headers.build() @get:JvmName("body") - actual val body: RequestBody? = builder.body + val body: RequestBody? = builder.body - internal actual val tags: Map, Any> = builder.tags.toMap() + internal val tags: Map, Any> = builder.tags.toMap() - internal actual var lazyCacheControl: CacheControl? = null + internal var lazyCacheControl: CacheControl? = null - actual val isHttps: Boolean + val isHttps: Boolean get() = url.isHttps /** @@ -66,11 +68,11 @@ actual class Request internal actual constructor(builder: Builder) { * * @param method defaults to "GET" if [body] is null, and "POST" otherwise. */ - actual constructor( + constructor( url: HttpUrl, - headers: Headers, - method: String, - body: RequestBody?, + headers: Headers = headersOf(), + method: String = "\u0000", // Sentinel value chooses based on what the body is. + body: RequestBody? = null, ) : this( Builder() .url(url) @@ -85,16 +87,16 @@ actual class Request internal actual constructor(builder: Builder) { ) ) - actual fun header(name: String): String? = commonHeader(name) + fun header(name: String): String? = commonHeader(name) - actual fun headers(name: String): List = commonHeaders(name) + fun headers(name: String): List = commonHeaders(name) /** Returns the tag attached with [T] as a key, or null if no tag is attached with that key. */ @JvmName("reifiedTag") - actual inline fun tag(): T? = tag(T::class) + inline fun tag(): T? = tag(T::class) /** Returns the tag attached with [type] as a key, or null if no tag is attached with that key. */ - actual fun tag(type: KClass): T? = type.java.cast(tags[type]) + fun tag(type: KClass): T? = type.java.cast(tags[type]) /** * Returns the tag attached with `Object.class` as a key, or null if no tag is attached with @@ -114,13 +116,13 @@ actual class Request internal actual constructor(builder: Builder) { */ fun tag(type: Class): T? = tag(type.kotlin) - actual fun newBuilder(): Builder = Builder(this) + fun newBuilder(): Builder = Builder(this) /** * Returns the cache control directives for this response. This is never null, even if this * response contains no `Cache-Control` header. */ - @get:JvmName("cacheControl") actual val cacheControl: CacheControl + @get:JvmName("cacheControl") val cacheControl: CacheControl get() { var result = lazyCacheControl if (result == null) { @@ -167,20 +169,20 @@ actual class Request internal actual constructor(builder: Builder) { override fun toString(): String = commonToString() - actual open class Builder { - internal actual var url: HttpUrl? = null - internal actual var method: String - internal actual var headers: Headers.Builder - internal actual var body: RequestBody? = null + open class Builder { + internal var url: HttpUrl? = null + internal var method: String + internal var headers: Headers.Builder + internal var body: RequestBody? = null /** A mutable map of tags, or an immutable empty map if we don't have any. */ - internal actual var tags = mapOf, Any>() + internal var tags = mapOf, Any>() - actual constructor() { + constructor() { this.method = "GET" this.headers = Headers.Builder() } - internal actual constructor(request: Request) { + internal constructor(request: Request) { this.url = request.url this.method = request.method this.body = request.body @@ -191,7 +193,7 @@ actual class Request internal actual constructor(builder: Builder) { this.headers = request.headers.newBuilder() } - actual open fun url(url: HttpUrl): Builder = apply { + open fun url(url: HttpUrl): Builder = apply { this.url = url } @@ -201,7 +203,7 @@ actual class Request internal actual constructor(builder: Builder) { * @throws IllegalArgumentException if [url] is not a valid HTTP or HTTPS URL. Avoid this * exception by calling [HttpUrl.parse]; it returns null for invalid URLs. */ - actual open fun url(url: String): Builder { + open fun url(url: String): Builder { return url(canonicalUrl(url).toHttpUrl()) } @@ -216,7 +218,7 @@ actual class Request internal actual constructor(builder: Builder) { * Sets the header named [name] to [value]. If this request already has any headers * with that name, they are all replaced. */ - actual open fun header(name: String, value: String) = commonHeader(name, value) + open fun header(name: String, value: String) = commonHeader(name, value) /** * Adds a header with [name] and [value]. Prefer this method for multiply-valued @@ -225,35 +227,35 @@ actual class Request internal actual constructor(builder: Builder) { * Note that for some headers including `Content-Length` and `Content-Encoding`, * OkHttp may replace [value] with a header derived from the request body. */ - actual open fun addHeader(name: String, value: String) = commonAddHeader(name, value) + open fun addHeader(name: String, value: String) = commonAddHeader(name, value) /** Removes all headers named [name] on this builder. */ - actual open fun removeHeader(name: String) = commonRemoveHeader(name) + open fun removeHeader(name: String) = commonRemoveHeader(name) /** Removes all headers on this builder and adds [headers]. */ - actual open fun headers(headers: Headers) = commonHeaders(headers) + open fun headers(headers: Headers) = commonHeaders(headers) /** * Sets this request's `Cache-Control` header, replacing any cache control headers already * present. If [cacheControl] doesn't define any directives, this clears this request's * cache-control headers. */ - actual open fun cacheControl(cacheControl: CacheControl): Builder = commonCacheControl(cacheControl) + open fun cacheControl(cacheControl: CacheControl): Builder = commonCacheControl(cacheControl) - actual open fun get(): Builder = commonGet() + open fun get(): Builder = commonGet() - actual open fun head(): Builder = commonHead() + open fun head(): Builder = commonHead() - actual open fun post(body: RequestBody): Builder = commonPost(body) + open fun post(body: RequestBody): Builder = commonPost(body) @JvmOverloads - actual open fun delete(body: RequestBody?): Builder = commonDelete(body) + open fun delete(body: RequestBody? = commonEmptyRequestBody): Builder = commonDelete(body) - actual open fun put(body: RequestBody): Builder = commonPut(body) + open fun put(body: RequestBody): Builder = commonPut(body) - actual open fun patch(body: RequestBody): Builder = commonPatch(body) + open fun patch(body: RequestBody): Builder = commonPatch(body) - actual open fun method(method: String, body: RequestBody?): Builder = commonMethod(method, body) + open fun method(method: String, body: RequestBody?): Builder = commonMethod(method, body) /** * Attaches [tag] to the request using [T] as a key. Tags can be read from a request using @@ -263,7 +265,7 @@ actual class Request internal actual constructor(builder: Builder) { * you may read it in interceptors, event listeners, or callbacks. */ @JvmName("reifiedTag") - actual inline fun tag(tag: T?): Builder = tag(T::class, tag) + inline fun tag(tag: T?): Builder = tag(T::class, tag) /** * Attaches [tag] to the request using [type] as a key. Tags can be read from a request using @@ -272,7 +274,7 @@ actual class Request internal actual constructor(builder: Builder) { * Use this API to attach timing, debugging, or other application data to a request so that * you may read it in interceptors, event listeners, or callbacks. */ - actual fun tag(type: KClass, tag: T?): Builder = commonTag(type, type.cast(tag)) + fun tag(type: KClass, tag: T?): Builder = commonTag(type, type.cast(tag)) /** Attaches [tag] to the request using `Object.class` as a key. */ open fun tag(tag: Any?): Builder = commonTag(Any::class, tag) @@ -286,6 +288,6 @@ actual class Request internal actual constructor(builder: Builder) { */ open fun tag(type: Class, tag: T?) = commonTag(type.kotlin, tag) - actual open fun build(): Request = Request(this) + open fun build(): Request = Request(this) } } diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/RequestBody.kt b/okhttp/src/jvmMain/kotlin/okhttp3/RequestBody.kt index c2ceee2ed50d..bcdc43252932 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/RequestBody.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/RequestBody.kt @@ -32,21 +32,21 @@ import okio.Path import okio.buffer import okio.source -actual abstract class RequestBody { +abstract class RequestBody { /** Returns the Content-Type header for this body. */ - actual abstract fun contentType(): MediaType? + abstract fun contentType(): MediaType? /** * Returns the number of bytes that will be written to sink in a call to [writeTo], * or -1 if that count is unknown. */ @Throws(IOException::class) - actual open fun contentLength(): Long = commonContentLength() + open fun contentLength(): Long = commonContentLength() /** Writes the content of this request to [sink]. */ @Throws(IOException::class) - actual abstract fun writeTo(sink: BufferedSink) + abstract fun writeTo(sink: BufferedSink) /** * A duplex request body is special in how it is **transmitted** on the network and @@ -80,7 +80,7 @@ actual abstract class RequestBody { * * [grpc]: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md */ - actual open fun isDuplex(): Boolean = commonIsDuplex() + open fun isDuplex(): Boolean = commonIsDuplex() /** * Returns true if this body expects at most one call to [writeTo] and can be transmitted @@ -99,16 +99,16 @@ actual abstract class RequestBody { * * A retryable server failure (HTTP 503 with a `Retry-After: 0` response header). * * A misdirected request (HTTP 421) on a coalesced connection. */ - actual open fun isOneShot(): Boolean = commonIsOneShot() + open fun isOneShot(): Boolean = commonIsOneShot() - actual companion object { + companion object { /** * Returns a new request body that transmits this string. If [contentType] is non-null and lacks * a charset, this will use UTF-8. */ @JvmStatic @JvmName("create") - actual fun String.toRequestBody(contentType: MediaType?): RequestBody { + fun String.toRequestBody(contentType: MediaType? = null): RequestBody { val (charset, finalContentType) = contentType.chooseCharset() val bytes = toByteArray(charset) return bytes.toRequestBody(finalContentType, 0, bytes.size) @@ -116,7 +116,7 @@ actual abstract class RequestBody { @JvmStatic @JvmName("create") - actual fun ByteString.toRequestBody(contentType: MediaType?): RequestBody = + fun ByteString.toRequestBody(contentType: MediaType? = null): RequestBody = commonToRequestBody(contentType) /** Returns a new request body that transmits this. */ @@ -140,10 +140,10 @@ actual abstract class RequestBody { @JvmOverloads @JvmStatic @JvmName("create") - actual fun ByteArray.toRequestBody( - contentType: MediaType?, - offset: Int, - byteCount: Int + fun ByteArray.toRequestBody( + contentType: MediaType? = null, + offset: Int = 0, + byteCount: Int = size, ): RequestBody = commonToRequestBody(contentType, offset, byteCount) /** Returns a new request body that transmits the content of this. */ diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/Response.kt b/okhttp/src/jvmMain/kotlin/okhttp3/Response.kt index d75fb2efbe5c..3f3ba4a8cc5d 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/Response.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/Response.kt @@ -51,7 +51,7 @@ import okio.Buffer * This class implements [Closeable]. Closing it simply closes its response body. See * [ResponseBody] for an explanation and examples. */ -actual class Response internal constructor( +class Response internal constructor( /** * The request that initiated this HTTP response. This is not necessarily the same request issued * by the application: @@ -65,16 +65,16 @@ actual class Response internal constructor( * transmitted. In the case of follow-ups and redirects, also look at the `request` of the * [priorResponse] objects, which have its own [priorResponse]. */ - @get:JvmName("request") actual val request: Request, + @get:JvmName("request") val request: Request, /** Returns the HTTP protocol, such as [Protocol.HTTP_1_1] or [Protocol.HTTP_1_0]. */ - @get:JvmName("protocol") actual val protocol: Protocol, + @get:JvmName("protocol") val protocol: Protocol, /** Returns the HTTP status message. */ - @get:JvmName("message") actual val message: String, + @get:JvmName("message") val message: String, /** Returns the HTTP status code. */ - @get:JvmName("code") actual val code: Int, + @get:JvmName("code") val code: Int, /** * Returns the TLS handshake of the connection that carried this response, or null if the @@ -83,7 +83,7 @@ actual class Response internal constructor( @get:JvmName("handshake") val handshake: Handshake?, /** Returns the HTTP headers. */ - @get:JvmName("headers") actual val headers: Headers, + @get:JvmName("headers") val headers: Headers, /** * Returns a non-null value if this response was passed to [Callback.onResponse] or returned @@ -93,21 +93,21 @@ actual class Response internal constructor( * This always returns null on responses returned from [cacheResponse], [networkResponse], * and [priorResponse]. */ - @get:JvmName("body") actual val body: ResponseBody, + @get:JvmName("body") val body: ResponseBody, /** * Returns the raw response received from the network. Will be null if this response didn't use * the network, such as when the response is fully cached. The body of the returned response * should not be read. */ - @get:JvmName("networkResponse") actual val networkResponse: Response?, + @get:JvmName("networkResponse") val networkResponse: Response?, /** * Returns the raw response received from the cache. Will be null if this response didn't use * the cache. For conditional get requests the cache response and network response may both be * non-null. The body of the returned response should not be read. */ - @get:JvmName("cacheResponse") actual val cacheResponse: Response?, + @get:JvmName("cacheResponse") val cacheResponse: Response?, /** * Returns the response for the HTTP redirect or authorization challenge that triggered this @@ -115,7 +115,7 @@ actual class Response internal constructor( * returned response should not be read because it has already been consumed by the redirecting * client. */ - @get:JvmName("priorResponse") actual val priorResponse: Response?, + @get:JvmName("priorResponse") val priorResponse: Response?, /** * Returns a [timestamp][System.currentTimeMillis] taken immediately before OkHttp @@ -136,7 +136,7 @@ actual class Response internal constructor( private var trailersFn: (() -> Headers) ) : Closeable { - internal actual var lazyCacheControl: CacheControl? = null + internal var lazyCacheControl: CacheControl? = null @JvmName("-deprecated_request") @Deprecated( @@ -163,7 +163,7 @@ actual class Response internal constructor( * Returns true if the code is in [200..300), which means the request was successfully received, * understood, and accepted. */ - actual val isSuccessful: Boolean = commonIsSuccessful + val isSuccessful: Boolean = commonIsSuccessful @JvmName("-deprecated_message") @Deprecated( @@ -179,10 +179,10 @@ actual class Response internal constructor( level = DeprecationLevel.ERROR) fun handshake(): Handshake? = handshake - actual fun headers(name: String): List = commonHeaders(name) + fun headers(name: String): List = commonHeaders(name) @JvmOverloads - actual fun header(name: String, defaultValue: String?): String? = commonHeader(name, defaultValue) + fun header(name: String, defaultValue: String? = null): String? = commonHeader(name, defaultValue) @JvmName("-deprecated_headers") @Deprecated( @@ -196,7 +196,7 @@ actual class Response internal constructor( * before the entire HTTP response body has been consumed. */ @Throws(IOException::class) - actual fun trailers(): Headers = trailersFn() + fun trailers(): Headers = trailersFn() /** * Peeks up to [byteCount] bytes from the response body and returns them as a new response @@ -210,7 +210,7 @@ actual class Response internal constructor( * a modest limit on `byteCount`, such as 1 MiB. */ @Throws(IOException::class) - actual fun peekBody(byteCount: Long): ResponseBody { + fun peekBody(byteCount: Long): ResponseBody { val peeked = body.source().peek() val buffer = Buffer() peeked.request(byteCount) @@ -225,10 +225,10 @@ actual class Response internal constructor( level = DeprecationLevel.ERROR) fun body() = body - actual fun newBuilder(): Builder = commonNewBuilder() + fun newBuilder(): Builder = commonNewBuilder() /** Returns true if this response redirects to another resource. */ - actual val isRedirect: Boolean = commonIsRedirect + val isRedirect: Boolean = commonIsRedirect @JvmName("-deprecated_networkResponse") @Deprecated( @@ -276,7 +276,7 @@ actual class Response internal constructor( * Returns the cache control directives for this response. This is never null, even if this * response contains no `Cache-Control` header. */ - @get:JvmName("cacheControl") actual val cacheControl: CacheControl + @get:JvmName("cacheControl") val cacheControl: CacheControl get() = commonCacheControl @JvmName("-deprecated_cacheControl") @@ -306,31 +306,31 @@ actual class Response internal constructor( * Prior to OkHttp 5.0, it was an error to close a response that is not eligible for a body. This * includes the responses returned from [cacheResponse], [networkResponse], and [priorResponse]. */ - actual override fun close() = commonClose() + override fun close() = commonClose() - actual override fun toString(): String = commonToString() + override fun toString(): String = commonToString() - actual open class Builder { - internal actual var request: Request? = null - internal actual var protocol: Protocol? = null - internal actual var code = -1 - internal actual var message: String? = null + open class Builder { + internal var request: Request? = null + internal var protocol: Protocol? = null + internal var code = -1 + internal var message: String? = null internal var handshake: Handshake? = null - internal actual var headers: Headers.Builder - internal actual var body: ResponseBody = commonEmptyResponse - internal actual var networkResponse: Response? = null - internal actual var cacheResponse: Response? = null - internal actual var priorResponse: Response? = null + internal var headers: Headers.Builder + internal var body: ResponseBody = commonEmptyResponse + internal var networkResponse: Response? = null + internal var cacheResponse: Response? = null + internal var priorResponse: Response? = null internal var sentRequestAtMillis: Long = 0 internal var receivedResponseAtMillis: Long = 0 internal var exchange: Exchange? = null - internal actual var trailersFn: (() -> Headers) = { Headers.headersOf() } + internal var trailersFn: (() -> Headers) = { Headers.headersOf() } - actual constructor() { + constructor() { headers = Headers.Builder() } - internal actual constructor(response: Response) { + internal constructor(response: Response) { this.request = response.request this.protocol = response.protocol this.code = response.code @@ -347,13 +347,13 @@ actual class Response internal constructor( this.trailersFn = response.trailersFn } - actual open fun request(request: Request) = commonRequest(request) + open fun request(request: Request) = commonRequest(request) - actual open fun protocol(protocol: Protocol) =commonProtocol(protocol) + open fun protocol(protocol: Protocol) =commonProtocol(protocol) - actual open fun code(code: Int) = commonCode(code) + open fun code(code: Int) = commonCode(code) - actual open fun message(message: String) = commonMessage(message) + open fun message(message: String) = commonMessage(message) open fun handshake(handshake: Handshake?) = apply { this.handshake = handshake @@ -363,29 +363,29 @@ actual class Response internal constructor( * Sets the header named [name] to [value]. If this request already has any headers * with that name, they are all replaced. */ - actual open fun header(name: String, value: String) = commonHeader(name, value) + open fun header(name: String, value: String) = commonHeader(name, value) /** * Adds a header with [name] to [value]. Prefer this method for multiply-valued * headers like "Set-Cookie". */ - actual open fun addHeader(name: String, value: String) = commonAddHeader(name, value) + open fun addHeader(name: String, value: String) = commonAddHeader(name, value) /** Removes all headers named [name] on this builder. */ - actual open fun removeHeader(name: String) = commonRemoveHeader(name) + open fun removeHeader(name: String) = commonRemoveHeader(name) /** Removes all headers on this builder and adds [headers]. */ - actual open fun headers(headers: Headers) = commonHeaders(headers) + open fun headers(headers: Headers) = commonHeaders(headers) - actual open fun body(body: ResponseBody) = commonBody(body) + open fun body(body: ResponseBody) = commonBody(body) - actual open fun networkResponse(networkResponse: Response?) = commonNetworkResponse(networkResponse) + open fun networkResponse(networkResponse: Response?) = commonNetworkResponse(networkResponse) - actual open fun cacheResponse(cacheResponse: Response?) = commonCacheResponse(cacheResponse) + open fun cacheResponse(cacheResponse: Response?) = commonCacheResponse(cacheResponse) - actual open fun priorResponse(priorResponse: Response?) = commonPriorResponse(priorResponse) + open fun priorResponse(priorResponse: Response?) = commonPriorResponse(priorResponse) - actual open fun trailers(trailersFn: (() -> Headers)): Builder = commonTrailers(trailersFn) + open fun trailers(trailersFn: (() -> Headers)): Builder = commonTrailers(trailersFn) open fun sentRequestAtMillis(sentRequestAtMillis: Long) = apply { this.sentRequestAtMillis = sentRequestAtMillis @@ -400,7 +400,7 @@ actual class Response internal constructor( this.trailersFn = { exchange.trailers() } } - actual open fun build(): Response { + open fun build(): Response { check(code >= 0) { "code < 0: $code" } return Response( checkNotNull(request) { "request == null" }, diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/ResponseBody.kt b/okhttp/src/jvmMain/kotlin/okhttp3/ResponseBody.kt index cecf237a2c33..555ee961dc56 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/ResponseBody.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/ResponseBody.kt @@ -101,21 +101,21 @@ import okio.ByteString * re-read the bytes of the response. Use this one shot to read the entire response into memory with * [bytes] or [string]. Or stream the response with either [source], [byteStream], or [charStream]. */ -actual abstract class ResponseBody : Closeable { +abstract class ResponseBody : Closeable { /** Multiple calls to [charStream] must return the same instance. */ private var reader: Reader? = null - actual abstract fun contentType(): MediaType? + abstract fun contentType(): MediaType? /** * Returns the number of bytes in that will returned by [bytes], or [byteStream], or -1 if * unknown. */ - actual abstract fun contentLength(): Long + abstract fun contentLength(): Long fun byteStream(): InputStream = source().inputStream() - actual abstract fun source(): BufferedSource + abstract fun source(): BufferedSource /** * Returns the response as a byte array. @@ -125,7 +125,7 @@ actual abstract class ResponseBody : Closeable { * possibility for your response. */ @Throws(IOException::class) - actual fun bytes() = commonBytes() + fun bytes() = commonBytes() /** * Returns the response as a [ByteString]. @@ -135,7 +135,7 @@ actual abstract class ResponseBody : Closeable { * possibility for your response. */ @Throws(IOException::class) - actual fun byteString() = commonByteString() + fun byteString() = commonByteString() /** * Returns the response as a character stream. @@ -170,13 +170,13 @@ actual abstract class ResponseBody : Closeable { * possibility for your response. */ @Throws(IOException::class) - actual fun string(): String = source().use { source -> + fun string(): String = source().use { source -> source.readString(charset = source.readBomAsCharset(charset())) } private fun charset() = contentType().charsetOrUtf8() - actual override fun close() = commonClose() + override fun close() = commonClose() internal class BomAwareReader( private val source: BufferedSource, @@ -205,7 +205,7 @@ actual abstract class ResponseBody : Closeable { } } - actual companion object { + companion object { /** * Returns a new response body that transmits this string. If [contentType] is non-null and * has a charset other than utf-8 the behaviour differs by platform. @@ -216,7 +216,7 @@ actual abstract class ResponseBody : Closeable { */ @JvmStatic @JvmName("create") - actual fun String.toResponseBody(contentType: MediaType?): ResponseBody { + fun String.toResponseBody(contentType: MediaType? = null): ResponseBody { val (charset, finalContentType) = contentType.chooseCharset() val buffer = Buffer().writeString(this, charset) return buffer.asResponseBody(finalContentType, buffer.size) @@ -225,19 +225,19 @@ actual abstract class ResponseBody : Closeable { /** Returns a new response body that transmits this byte array. */ @JvmStatic @JvmName("create") - actual fun ByteArray.toResponseBody(contentType: MediaType?): ResponseBody = commonToResponseBody(contentType) + fun ByteArray.toResponseBody(contentType: MediaType? = null): ResponseBody = commonToResponseBody(contentType) /** Returns a new response body that transmits this byte string. */ @JvmStatic @JvmName("create") - actual fun ByteString.toResponseBody(contentType: MediaType?): ResponseBody = commonToResponseBody(contentType) + fun ByteString.toResponseBody(contentType: MediaType? = null): ResponseBody = commonToResponseBody(contentType) /** Returns a new response body that transmits this source. */ @JvmStatic @JvmName("create") - actual fun BufferedSource.asResponseBody( - contentType: MediaType?, - contentLength: Long + fun BufferedSource.asResponseBody( + contentType: MediaType? = null, + contentLength: Long = -1L, ): ResponseBody = commonAsResponseBody(contentType, contentLength) @JvmStatic diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/TlsVersion.kt b/okhttp/src/jvmMain/kotlin/okhttp3/TlsVersion.kt index 4a81d219eaff..5bd4b491e1b0 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/TlsVersion.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/TlsVersion.kt @@ -19,7 +19,7 @@ package okhttp3 * Versions of TLS that can be offered when negotiating a secure socket. See * [javax.net.ssl.SSLSocket.setEnabledProtocols]. */ -actual enum class TlsVersion( +enum class TlsVersion( @get:JvmName("javaName") val javaName: String ) { TLS_1_3("TLSv1.3"), // 2016. diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-CacheControlCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-CacheControlCommon.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-CacheControlCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-CacheControlCommon.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-ChallengeCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-ChallengeCommon.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-ChallengeCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-ChallengeCommon.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-HeadersCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-HeadersCommon.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-HeadersCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-HeadersCommon.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-HostnamesCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-HostnamesCommon.kt similarity index 99% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-HostnamesCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-HostnamesCommon.kt index 9cd5e4f6e270..b1f7539338c3 100644 --- a/okhttp/src/commonMain/kotlin/okhttp3/internal/-HostnamesCommon.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-HostnamesCommon.kt @@ -332,4 +332,3 @@ internal fun idnToAscii(host: String): String? { return Punycode.encode(decoded) } -internal expect fun normalizeNfc(string: String): String diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-HttpUrlCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-HttpUrlCommon.kt similarity index 98% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-HttpUrlCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-HttpUrlCommon.kt index a740cd7038ec..e2981b5f3ab6 100644 --- a/okhttp/src/commonMain/kotlin/okhttp3/internal/-HttpUrlCommon.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-HttpUrlCommon.kt @@ -21,26 +21,6 @@ import okhttp3.internal.HttpUrlCommon.canonicalize import okhttp3.internal.HttpUrlCommon.writePercentDecoded import okio.Buffer -internal expect object HttpUrlCommon { - internal fun Buffer.writePercentDecoded( - encoded: String, - pos: Int, - limit: Int, - plusIsSpace: Boolean - ) - - internal fun String.canonicalize( - pos: Int = 0, - limit: Int = length, - encodeSet: String, - alreadyEncoded: Boolean = false, - strict: Boolean = false, - plusIsSpace: Boolean = false, - unicodeAllowed: Boolean = false, - ): String - -} - internal object CommonHttpUrl { internal val HEX_DIGITS = diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/internal/-HttpUrlJvm.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-HttpUrlJvm.kt index adc5d7e8642c..dc9cdc951264 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/internal/-HttpUrlJvm.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-HttpUrlJvm.kt @@ -145,8 +145,8 @@ internal object JvmHttpUrl { } } -internal actual object HttpUrlCommon { - internal actual fun Buffer.writePercentDecoded( +internal object HttpUrlCommon { + internal fun Buffer.writePercentDecoded( encoded: String, pos: Int, limit: Int, @@ -174,14 +174,14 @@ internal actual object HttpUrlCommon { i += Character.charCount(codePoint) } } - internal actual fun String.canonicalize( - pos: Int, - limit: Int, + internal fun String.canonicalize( + pos: Int = 0, + limit: Int = length, encodeSet: String, - alreadyEncoded: Boolean, - strict: Boolean, - plusIsSpace: Boolean, - unicodeAllowed: Boolean, + alreadyEncoded: Boolean = false, + strict: Boolean = false, + plusIsSpace: Boolean = false, + unicodeAllowed: Boolean = false, ): String { return canonicalizeWithCharset( pos = pos, @@ -193,5 +193,4 @@ internal actual object HttpUrlCommon { unicodeAllowed = unicodeAllowed ) } - } diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-MediaTypeCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-MediaTypeCommon.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-MediaTypeCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-MediaTypeCommon.kt diff --git a/okhttp/src/jvmMain/kotlin/okhttp3/internal/-NormalizeJvm.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-NormalizeJvm.kt index cf635aee2720..8367e035898b 100644 --- a/okhttp/src/jvmMain/kotlin/okhttp3/internal/-NormalizeJvm.kt +++ b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-NormalizeJvm.kt @@ -18,5 +18,5 @@ package okhttp3.internal import java.text.Normalizer import java.text.Normalizer.Form.NFC -internal actual fun normalizeNfc(string: String): String = +internal fun normalizeNfc(string: String): String = Normalizer.normalize(string, NFC) diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-RequestBodyCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-RequestBodyCommon.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-RequestBodyCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-RequestBodyCommon.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-RequestCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-RequestCommon.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-RequestCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-RequestCommon.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-ResponseBodyCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-ResponseBodyCommon.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-ResponseBodyCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-ResponseBodyCommon.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-ResponseCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-ResponseCommon.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-ResponseCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-ResponseCommon.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/-UtilCommon.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/-UtilCommon.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/-UtilCommon.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/-UtilCommon.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/http/HttpMethod.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/http/HttpMethod.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/http/HttpMethod.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/http/HttpMethod.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/http/HttpStatusCodes.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/http/HttpStatusCodes.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/http/HttpStatusCodes.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/http/HttpStatusCodes.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/http/StatusLine.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/http/StatusLine.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/http/StatusLine.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/http/StatusLine.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/idn/IdnaMappingTable.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/idn/IdnaMappingTable.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/idn/IdnaMappingTable.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/idn/IdnaMappingTable.kt diff --git a/okhttp/src/commonMain/kotlin/okhttp3/internal/idn/Punycode.kt b/okhttp/src/jvmMain/kotlin/okhttp3/internal/idn/Punycode.kt similarity index 100% rename from okhttp/src/commonMain/kotlin/okhttp3/internal/idn/Punycode.kt rename to okhttp/src/jvmMain/kotlin/okhttp3/internal/idn/Punycode.kt diff --git a/okhttp/src/commonMain/kotlinTemplates/okhttp3/internal/-InternalVersion.kt b/okhttp/src/jvmMain/kotlinTemplates/okhttp3/internal/-InternalVersion.kt similarity index 100% rename from okhttp/src/commonMain/kotlinTemplates/okhttp3/internal/-InternalVersion.kt rename to okhttp/src/jvmMain/kotlinTemplates/okhttp3/internal/-InternalVersion.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/CacheControlTest.kt b/okhttp/src/jvmTest/java/okhttp3/CacheControlTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/CacheControlTest.kt rename to okhttp/src/jvmTest/java/okhttp3/CacheControlTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/CommonRequestBodyTest.kt b/okhttp/src/jvmTest/java/okhttp3/CommonRequestBodyTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/CommonRequestBodyTest.kt rename to okhttp/src/jvmTest/java/okhttp3/CommonRequestBodyTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/HeadersTest.kt b/okhttp/src/jvmTest/java/okhttp3/HeadersTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/HeadersTest.kt rename to okhttp/src/jvmTest/java/okhttp3/HeadersTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/HttpUrlTest.kt b/okhttp/src/jvmTest/java/okhttp3/HttpUrlTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/HttpUrlTest.kt rename to okhttp/src/jvmTest/java/okhttp3/HttpUrlTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/MediaTypeGetTest.kt b/okhttp/src/jvmTest/java/okhttp3/MediaTypeGetTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/MediaTypeGetTest.kt rename to okhttp/src/jvmTest/java/okhttp3/MediaTypeGetTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/MediaTypeTest.kt b/okhttp/src/jvmTest/java/okhttp3/MediaTypeTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/MediaTypeTest.kt rename to okhttp/src/jvmTest/java/okhttp3/MediaTypeTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/RequestCommonTest.kt b/okhttp/src/jvmTest/java/okhttp3/RequestCommonTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/RequestCommonTest.kt rename to okhttp/src/jvmTest/java/okhttp3/RequestCommonTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/ResponseBodyTest.kt b/okhttp/src/jvmTest/java/okhttp3/ResponseBodyTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/ResponseBodyTest.kt rename to okhttp/src/jvmTest/java/okhttp3/ResponseBodyTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/ResponseCommonTest.kt b/okhttp/src/jvmTest/java/okhttp3/ResponseCommonTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/ResponseCommonTest.kt rename to okhttp/src/jvmTest/java/okhttp3/ResponseCommonTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/UrlComponentEncodingTester.kt b/okhttp/src/jvmTest/java/okhttp3/UrlComponentEncodingTester.kt similarity index 98% rename from okhttp/src/commonTest/kotlin/okhttp3/UrlComponentEncodingTester.kt rename to okhttp/src/jvmTest/java/okhttp3/UrlComponentEncodingTester.kt index a290c1b4f24a..31f9c84adf86 100644 --- a/okhttp/src/commonTest/kotlin/okhttp3/UrlComponentEncodingTester.kt +++ b/okhttp/src/jvmTest/java/okhttp3/UrlComponentEncodingTester.kt @@ -348,7 +348,3 @@ class UrlComponentEncodingTester private constructor() { } } } - -expect fun urlComponentEncodingTesterJvmPlatform( - component: UrlComponentEncodingTester.Component, -): UrlComponentEncodingTester.Platform diff --git a/okhttp/src/jvmTest/java/okhttp3/UrlComponentEncodingTesterJvm.kt b/okhttp/src/jvmTest/java/okhttp3/UrlComponentEncodingTesterJvm.kt index bd2353d49777..502495c62558 100644 --- a/okhttp/src/jvmTest/java/okhttp3/UrlComponentEncodingTesterJvm.kt +++ b/okhttp/src/jvmTest/java/okhttp3/UrlComponentEncodingTesterJvm.kt @@ -20,7 +20,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.UrlComponentEncodingTester.Component -actual fun urlComponentEncodingTesterJvmPlatform( +fun urlComponentEncodingTesterJvmPlatform( component: Component, ): UrlComponentEncodingTester.Platform { return when (component) { diff --git a/okhttp/src/commonTest/kotlin/okhttp3/WebPlatformToAsciiData.kt b/okhttp/src/jvmTest/java/okhttp3/WebPlatformToAsciiData.kt similarity index 93% rename from okhttp/src/commonTest/kotlin/okhttp3/WebPlatformToAsciiData.kt rename to okhttp/src/jvmTest/java/okhttp3/WebPlatformToAsciiData.kt index ac1f3019e00f..1912ae0c7442 100644 --- a/okhttp/src/commonTest/kotlin/okhttp3/WebPlatformToAsciiData.kt +++ b/okhttp/src/jvmTest/java/okhttp3/WebPlatformToAsciiData.kt @@ -34,7 +34,7 @@ class WebPlatformToAsciiData { companion object { fun load(): List { - val path = okHttpRoot / "okhttp/src/commonTest/resources/web-platform-test-toascii.json" + val path = okHttpRoot / "okhttp/src/jvmTest/resources/web-platform-test-toascii.json" return SYSTEM_FILE_SYSTEM.read(path) { Json.decodeFromString>(readUtf8()) } diff --git a/okhttp/src/commonTest/kotlin/okhttp3/WebPlatformToAsciiTest.kt b/okhttp/src/jvmTest/java/okhttp3/WebPlatformToAsciiTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/WebPlatformToAsciiTest.kt rename to okhttp/src/jvmTest/java/okhttp3/WebPlatformToAsciiTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/internal/HostnamesTest.kt b/okhttp/src/jvmTest/java/okhttp3/internal/HostnamesTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/internal/HostnamesTest.kt rename to okhttp/src/jvmTest/java/okhttp3/internal/HostnamesTest.kt diff --git a/okhttp/src/commonTest/kotlin/okhttp3/internal/idn/PunycodeTest.kt b/okhttp/src/jvmTest/java/okhttp3/internal/idn/PunycodeTest.kt similarity index 100% rename from okhttp/src/commonTest/kotlin/okhttp3/internal/idn/PunycodeTest.kt rename to okhttp/src/jvmTest/java/okhttp3/internal/idn/PunycodeTest.kt diff --git a/okhttp/src/commonTest/resources/web-platform-test-toascii.json b/okhttp/src/jvmTest/resources/web-platform-test-toascii.json similarity index 100% rename from okhttp/src/commonTest/resources/web-platform-test-toascii.json rename to okhttp/src/jvmTest/resources/web-platform-test-toascii.json