From 10b7c4c41dbf4cda269a87858d759347834e9085 Mon Sep 17 00:00:00 2001 From: OmarAlJarrah Date: Sun, 28 Jun 2026 03:39:12 +0300 Subject: [PATCH 1/2] chore: drop redundant toReplayable overrides and derive Method token from name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove a cluster of declarations in http/request that restate inherited behavior. All changes are behavior-preserving. - RequestBody: the base toReplayable() short-circuits to `this` whenever isReplayable() is true. The three private replayable bodies (BufferRequestBody, ByteArrayRequestBody, ResettableInputStreamRequestBody) each return true from isReplayable() and then override toReplayable to return `this` — exactly the inherited behavior. Drop the overrides. - FileRequestBody: same no-op override on the public body. The inherited toReplayable() still returns `this` (the FileRequestBody), so the transport-side `is FileRequestBody` sendfile(2) fast path keeps matching. Removing it leaves the IoProvider import unreferenced, so drop that too. - Method: every constant passed a wire-token string identical to its own enum name, and toString() returned that string — which is what the default enum toString() already produces. Drop the constructor parameter and the nine duplicated literals; expose the token as `method` computed from `name`, and let the default toString() stand. getMethod() stays public and callable. Public API: FileRequestBody.toReplayable(IoProvider) and Method.toString() were explicit overrides in the snapshot and are now inherited/default, so both lines drop from sdk-core.api (regenerated). getMethod() is unchanged. Closes #174 --- sdk-core/api/sdk-core.api | 2 -- .../sdk/core/http/request/FileRequestBody.kt | 3 -- .../dexpace/sdk/core/http/request/Method.kt | 33 +++++++++---------- .../sdk/core/http/request/RequestBody.kt | 6 ---- 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/sdk-core/api/sdk-core.api b/sdk-core/api/sdk-core.api index f551a3f3..3055cb47 100644 --- a/sdk-core/api/sdk-core.api +++ b/sdk-core/api/sdk-core.api @@ -1048,7 +1048,6 @@ public final class org/dexpace/sdk/core/http/request/FileRequestBody : org/dexpa public fun isReplayable ()Z public fun mediaType ()Lorg/dexpace/sdk/core/http/common/MediaType; public final fun toByteBuffer ()Ljava/nio/ByteBuffer; - public fun toReplayable (Lorg/dexpace/sdk/core/io/IoProvider;)Lorg/dexpace/sdk/core/http/request/RequestBody; public fun writeTo (Lorg/dexpace/sdk/core/io/BufferedSink;)V } @@ -1078,7 +1077,6 @@ public final class org/dexpace/sdk/core/http/request/Method : java/lang/Enum { public static fun getEntries ()Lkotlin/enums/EnumEntries; public final fun getMethod ()Ljava/lang/String; public final fun getPermitsRequestBody ()Z - public fun toString ()Ljava/lang/String; public static fun valueOf (Ljava/lang/String;)Lorg/dexpace/sdk/core/http/request/Method; public static fun values ()[Lorg/dexpace/sdk/core/http/request/Method; } diff --git a/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/FileRequestBody.kt b/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/FileRequestBody.kt index e8727d7a..7fa468be 100644 --- a/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/FileRequestBody.kt +++ b/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/FileRequestBody.kt @@ -9,7 +9,6 @@ package org.dexpace.sdk.core.http.request import org.dexpace.sdk.core.http.common.MediaType import org.dexpace.sdk.core.io.BufferedSink -import org.dexpace.sdk.core.io.IoProvider import java.io.IOException import java.nio.ByteBuffer import java.nio.channels.Channels @@ -100,8 +99,6 @@ public class FileRequestBody override fun isReplayable(): Boolean = true - override fun toReplayable(provider: IoProvider): RequestBody = this - @Throws(IOException::class) override fun writeTo(sink: BufferedSink) { FileChannel.open(file, StandardOpenOption.READ).use { channel -> diff --git a/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/Method.kt b/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/Method.kt index 107bff4f..a4d2d4cf 100644 --- a/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/Method.kt +++ b/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/Method.kt @@ -10,11 +10,10 @@ package org.dexpace.sdk.core.http.request // Public API surface — not every HTTP method entry is referenced within this module; SDK consumers may use any. /** - * HTTP request methods recognized by the SDK. Each constant carries the canonical token used - * on the wire; [toString] returns that same token so the enum can be written directly into a - * request line without translation. + * HTTP request methods recognized by the SDK. Each constant's name is the canonical token used + * on the wire, so the enum's default `toString()` returns that token and the constant can be + * written directly into a request line without translation. * - * @property method Canonical uppercase method token sent in the request line. * @property permitsRequestBody Whether this SDK permits the method to carry a request body. * `false` for `GET`, `HEAD`, `TRACE`, and `CONNECT`. Of these only `TRACE` is forbidden a body * outright by HTTP — a TRACE request "MUST NOT send content" (RFC 9110 §9.3.8); for `GET`/`HEAD` @@ -26,20 +25,18 @@ package org.dexpace.sdk.core.http.request * differently per transport. */ @Suppress("unused") -public enum class Method( - public val method: String, - public val permitsRequestBody: Boolean, -) { - GET("GET", permitsRequestBody = false), - POST("POST", permitsRequestBody = true), - PUT("PUT", permitsRequestBody = true), - DELETE("DELETE", permitsRequestBody = true), - PATCH("PATCH", permitsRequestBody = true), - HEAD("HEAD", permitsRequestBody = false), - OPTIONS("OPTIONS", permitsRequestBody = true), - TRACE("TRACE", permitsRequestBody = false), - CONNECT("CONNECT", permitsRequestBody = false), +public enum class Method(public val permitsRequestBody: Boolean) { + GET(permitsRequestBody = false), + POST(permitsRequestBody = true), + PUT(permitsRequestBody = true), + DELETE(permitsRequestBody = true), + PATCH(permitsRequestBody = true), + HEAD(permitsRequestBody = false), + OPTIONS(permitsRequestBody = true), + TRACE(permitsRequestBody = false), + CONNECT(permitsRequestBody = false), ; - override fun toString(): String = method + /** Canonical uppercase method token sent in the request line; identical to the enum [name]. */ + public val method: String get() = name } diff --git a/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/RequestBody.kt b/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/RequestBody.kt index 1ed01aca..864d7f21 100644 --- a/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/RequestBody.kt +++ b/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/RequestBody.kt @@ -225,8 +225,6 @@ private class BufferRequestBody( override fun isReplayable(): Boolean = true - override fun toReplayable(provider: IoProvider): RequestBody = this - @Throws(IOException::class) override fun writeTo(sink: BufferedSink) { sink.writeAll(buffer.peek()) @@ -244,8 +242,6 @@ private class ByteArrayRequestBody( override fun isReplayable(): Boolean = true - override fun toReplayable(provider: IoProvider): RequestBody = this - @Throws(IOException::class) override fun writeTo(sink: BufferedSink) { sink.write(bytes) @@ -274,8 +270,6 @@ private class ResettableInputStreamRequestBody( override fun isReplayable(): Boolean = true - override fun toReplayable(provider: IoProvider): RequestBody = this - @Throws(IOException::class) override fun writeTo(sink: BufferedSink) { if (hasWritten.getAndSet(true)) { From 5a9407f7011901964cc3ad042b25913a66b722ae Mon Sep 17 00:00:00 2001 From: OmarAlJarrah Date: Sun, 28 Jun 2026 03:43:20 +0300 Subject: [PATCH 2/2] chore: suppress MemberNameEqualsClassName on Method.method accessor Moving the wire-token from a constructor parameter to a body-level computed property surfaces detekt's MemberNameEqualsClassName (the rule only inspects body-declared members, so it was dormant while method was a constructor val). The accessor is kept for API compatibility and the token genuinely is the method's name, so suppress the rule rather than rename. --- .../kotlin/org/dexpace/sdk/core/http/request/Method.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/Method.kt b/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/Method.kt index a4d2d4cf..8120e4ba 100644 --- a/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/Method.kt +++ b/sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/Method.kt @@ -37,6 +37,13 @@ public enum class Method(public val permitsRequestBody: Boolean) { CONNECT(permitsRequestBody = false), ; - /** Canonical uppercase method token sent in the request line; identical to the enum [name]. */ + /** + * Canonical uppercase method token sent in the request line; identical to the enum [name]. + * + * `MemberNameEqualsClassName` is suppressed: the accessor is retained for API compatibility + * (`getMethod()`) and the token genuinely *is* the method's name, so renaming it would only + * obscure that and break callers. + */ + @Suppress("MemberNameEqualsClassName") public val method: String get() = name }