Skip to content

Commit 34d951e

Browse files
committed
Updated okhttp3 dependency
1 parent 9de755f commit 34d951e

9 files changed

Lines changed: 14 additions & 17 deletions

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
okhttp3 = "4.12.0"
2+
okhttp3 = "5.3.2"
33
uri-templates = "2.1.8"
44
kotlinx-serialization = "1.8.0"
55
jackson = "2.19.0"

typedrest/src/main/kotlin/net/typedrest/endpoints/generic/ElementEndpointImpl.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,12 @@ open class ElementEndpointImpl<TEntity>(
8282
}
8383

8484
private fun tryReadAs(response: Response): TEntity? {
85-
val body = response.body
86-
if (body == null || response.code == HttpStatusCode.NoContent.code) {
85+
if (response.code == HttpStatusCode.NoContent.code) {
8786
return null
8887
}
8988

9089
return try {
91-
deserialize(body, entityType)
90+
deserialize(response.body, entityType)
9291
} catch (ex: Exception) {
9392
null
9493
}

typedrest/src/main/kotlin/net/typedrest/endpoints/generic/GenericCollectionEndpointImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ open class GenericCollectionEndpointImpl<TEntity, TElementEndpoint : ElementEndp
7272
execute(Request.Builder().get().uri(uri).header("Range", "${rangeUnit}=${from ?: ""}-${to ?: ""}").build())
7373
.use { response ->
7474
PartialResponse(
75-
response.body?.let { deserializeList(it, entityType) } ?: throw NotFoundException("Result not deserializable as List<${entityType.simpleName}>"),
75+
deserializeList(response.body, entityType) ?: throw NotFoundException("Result not deserializable as List<${entityType.simpleName}>"),
7676
HttpContentRangeHeader.parse(response.headers)
7777
)
7878
}

typedrest/src/main/kotlin/net/typedrest/endpoints/raw/BlobEndpointImpl.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ open class BlobEndpointImpl(referrer: Endpoint, relativeUri: URI) : AbstractEndp
3030
override val isDownloadAllowed: Boolean?
3131
get() = isMethodAllowed(HttpMethod.GET)
3232

33-
override fun download(): InputStream {
34-
val response = execute(Request.Builder().get().uri(uri).build())
35-
return response.body?.byteStream() ?: throw IllegalStateException("Response body is null")
36-
}
33+
override fun download(): InputStream =
34+
execute(Request.Builder().get().uri(uri).build()).body.byteStream()
3735

3836
override val isUploadAllowed: Boolean?
3937
get() = isMethodAllowed(HttpMethod.PUT)

typedrest/src/main/kotlin/net/typedrest/endpoints/rpc/FunctionEndpointImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ open class FunctionEndpointImpl<TEntity, TResult>(
3636

3737
override fun invoke(entity: TEntity): TResult =
3838
execute(Request.Builder().post(serialize(entity, entityType)).uri(uri).build()).use { response ->
39-
response.body?.let { deserialize(it, resultType) }
39+
deserialize(response.body, resultType)
4040
?: throw NotFoundException("Result not deserializable as ${resultType.simpleName}")
4141
}
4242
}

typedrest/src/main/kotlin/net/typedrest/endpoints/rpc/ProducerEndpointImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ open class ProducerEndpointImpl<TResult>(
3232

3333
override fun invoke(): TResult =
3434
execute(Request.Builder().post("".toRequestBody()).uri(uri).build()).use { response ->
35-
response.body?.let { deserialize(it, resultType) }
35+
deserialize(response.body, resultType)
3636
?: throw NotFoundException("Result not deserializable as ${resultType.simpleName}")
3737
}
3838
}

typedrest/src/main/kotlin/net/typedrest/errors/DefaultErrorHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ open class DefaultErrorHandler : ErrorHandler {
1414
override fun handle(response: Response) {
1515
if (response.isSuccessful) return
1616

17-
val message = response.body?.let(::extractJsonMessage)
17+
val message = extractJsonMessage(response.body)
1818
?: "${response.request.url} responded with ${response.code} ${response.message}"
1919

2020
throw mapException(HttpStatusCode.parse(response.code) ?: HttpStatusCode.InternalServerError, message, response)

typedrest/src/main/kotlin/net/typedrest/http/ResponseCache.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ class ResponseCache private constructor(response: Response) {
1717
*/
1818
@JvmStatic
1919
fun from(response: Response): ResponseCache? =
20-
if (response.isSuccessful && response.code != HttpStatusCode.NoContent.code && !response.cacheControl.noStore && response.body != null) {
20+
if (response.isSuccessful && response.code != HttpStatusCode.NoContent.code && !response.cacheControl.noStore) {
2121
ResponseCache(response)
2222
} else null
2323

2424
private val dateFormat = SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US)
2525
.apply { timeZone = TimeZone.getTimeZone("GMT") }
2626
}
2727

28-
private val bodyByteString = response.body?.byteString()
29-
private val contentType = response.body?.contentType()
28+
private val bodyByteString = response.body.byteString()
29+
private val contentType = response.body.contentType()
3030

3131
/**
3232
* Returns a copy of the cached [RequestBody].
3333
*/
34-
fun getBody() = bodyByteString?.toResponseBody(contentType) ?: throw IllegalArgumentException("Missing content.")
34+
fun getBody() = bodyByteString.toResponseBody(contentType)
3535

3636
private var expires =
3737
if (response.cacheControl.noCache) {

typedrest/src/main/kotlin/net/typedrest/links/HalLinkExtractor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import okhttp3.Response
1010
class HalLinkExtractor : LinkExtractor {
1111
override fun getLinks(response: Response): List<Link> =
1212
if (response.header("Content-Type") == "application/hal+json") {
13-
parseJsonBody(response.body?.string().orEmpty())
13+
parseJsonBody(response.body.string())
1414
} else emptyList()
1515

1616
private fun parseJsonBody(body: String): List<Link> =

0 commit comments

Comments
 (0)