Skip to content

Commit 3421dc2

Browse files
authored
chore: drop redundant toReplayable overrides and derive Method token from enum name (#189)
PR: #189
1 parent b4239df commit 3421dc2

4 files changed

Lines changed: 22 additions & 29 deletions

File tree

sdk-core/api/sdk-core.api

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,6 @@ public final class org/dexpace/sdk/core/http/request/FileRequestBody : org/dexpa
10481048
public fun isReplayable ()Z
10491049
public fun mediaType ()Lorg/dexpace/sdk/core/http/common/MediaType;
10501050
public final fun toByteBuffer ()Ljava/nio/ByteBuffer;
1051-
public fun toReplayable (Lorg/dexpace/sdk/core/io/IoProvider;)Lorg/dexpace/sdk/core/http/request/RequestBody;
10521051
public fun writeTo (Lorg/dexpace/sdk/core/io/BufferedSink;)V
10531052
}
10541053

@@ -1078,7 +1077,6 @@ public final class org/dexpace/sdk/core/http/request/Method : java/lang/Enum {
10781077
public static fun getEntries ()Lkotlin/enums/EnumEntries;
10791078
public final fun getMethod ()Ljava/lang/String;
10801079
public final fun getPermitsRequestBody ()Z
1081-
public fun toString ()Ljava/lang/String;
10821080
public static fun valueOf (Ljava/lang/String;)Lorg/dexpace/sdk/core/http/request/Method;
10831081
public static fun values ()[Lorg/dexpace/sdk/core/http/request/Method;
10841082
}

sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/FileRequestBody.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package org.dexpace.sdk.core.http.request
99

1010
import org.dexpace.sdk.core.http.common.MediaType
1111
import org.dexpace.sdk.core.io.BufferedSink
12-
import org.dexpace.sdk.core.io.IoProvider
1312
import java.io.IOException
1413
import java.nio.ByteBuffer
1514
import java.nio.channels.Channels
@@ -100,8 +99,6 @@ public class FileRequestBody
10099

101100
override fun isReplayable(): Boolean = true
102101

103-
override fun toReplayable(provider: IoProvider): RequestBody = this
104-
105102
@Throws(IOException::class)
106103
override fun writeTo(sink: BufferedSink) {
107104
FileChannel.open(file, StandardOpenOption.READ).use { channel ->

sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/Method.kt

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ package org.dexpace.sdk.core.http.request
1010
// Public API surface — not every HTTP method entry is referenced within this module; SDK consumers may use any.
1111

1212
/**
13-
* HTTP request methods recognized by the SDK. Each constant carries the canonical token used
14-
* on the wire; [toString] returns that same token so the enum can be written directly into a
15-
* request line without translation.
13+
* HTTP request methods recognized by the SDK. Each constant's name is the canonical token used
14+
* on the wire, so the enum's default `toString()` returns that token and the constant can be
15+
* written directly into a request line without translation.
1616
*
17-
* @property method Canonical uppercase method token sent in the request line.
1817
* @property permitsRequestBody Whether this SDK permits the method to carry a request body.
1918
* `false` for `GET`, `HEAD`, `TRACE`, and `CONNECT`. Of these only `TRACE` is forbidden a body
2019
* outright by HTTP — a TRACE request "MUST NOT send content" (RFC 9110 §9.3.8); for `GET`/`HEAD`
@@ -26,20 +25,25 @@ package org.dexpace.sdk.core.http.request
2625
* differently per transport.
2726
*/
2827
@Suppress("unused")
29-
public enum class Method(
30-
public val method: String,
31-
public val permitsRequestBody: Boolean,
32-
) {
33-
GET("GET", permitsRequestBody = false),
34-
POST("POST", permitsRequestBody = true),
35-
PUT("PUT", permitsRequestBody = true),
36-
DELETE("DELETE", permitsRequestBody = true),
37-
PATCH("PATCH", permitsRequestBody = true),
38-
HEAD("HEAD", permitsRequestBody = false),
39-
OPTIONS("OPTIONS", permitsRequestBody = true),
40-
TRACE("TRACE", permitsRequestBody = false),
41-
CONNECT("CONNECT", permitsRequestBody = false),
28+
public enum class Method(public val permitsRequestBody: Boolean) {
29+
GET(permitsRequestBody = false),
30+
POST(permitsRequestBody = true),
31+
PUT(permitsRequestBody = true),
32+
DELETE(permitsRequestBody = true),
33+
PATCH(permitsRequestBody = true),
34+
HEAD(permitsRequestBody = false),
35+
OPTIONS(permitsRequestBody = true),
36+
TRACE(permitsRequestBody = false),
37+
CONNECT(permitsRequestBody = false),
4238
;
4339

44-
override fun toString(): String = method
40+
/**
41+
* Canonical uppercase method token sent in the request line; identical to the enum [name].
42+
*
43+
* `MemberNameEqualsClassName` is suppressed: the accessor is retained for API compatibility
44+
* (`getMethod()`) and the token genuinely *is* the method's name, so renaming it would only
45+
* obscure that and break callers.
46+
*/
47+
@Suppress("MemberNameEqualsClassName")
48+
public val method: String get() = name
4549
}

sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/request/RequestBody.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ private class BufferRequestBody(
225225

226226
override fun isReplayable(): Boolean = true
227227

228-
override fun toReplayable(provider: IoProvider): RequestBody = this
229-
230228
@Throws(IOException::class)
231229
override fun writeTo(sink: BufferedSink) {
232230
sink.writeAll(buffer.peek())
@@ -244,8 +242,6 @@ private class ByteArrayRequestBody(
244242

245243
override fun isReplayable(): Boolean = true
246244

247-
override fun toReplayable(provider: IoProvider): RequestBody = this
248-
249245
@Throws(IOException::class)
250246
override fun writeTo(sink: BufferedSink) {
251247
sink.write(bytes)
@@ -274,8 +270,6 @@ private class ResettableInputStreamRequestBody(
274270

275271
override fun isReplayable(): Boolean = true
276272

277-
override fun toReplayable(provider: IoProvider): RequestBody = this
278-
279273
@Throws(IOException::class)
280274
override fun writeTo(sink: BufferedSink) {
281275
if (hasWritten.getAndSet(true)) {

0 commit comments

Comments
 (0)