Get request body size on the network thread

This commit is contained in:
Jonas Lochmann 2023-02-13 01:00:00 +01:00
parent 1c5b18c2af
commit 196dbcd5a0
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36

View file

@ -66,7 +66,7 @@ class HttpServerApi(private val endpointWithoutSlashAtEnd: String): ServerApi {
private val JSON = "application/json; charset=utf-8".toMediaTypeOrNull() private val JSON = "application/json; charset=utf-8".toMediaTypeOrNull()
private fun createJsonRequestBody( private suspend fun createJsonRequestBody(
serialize: (writer: JsonWriter) -> Unit, serialize: (writer: JsonWriter) -> Unit,
measureContentLength: Boolean measureContentLength: Boolean
): RequestBody { ): RequestBody {
@ -84,7 +84,7 @@ class HttpServerApi(private val endpointWithoutSlashAtEnd: String): ServerApi {
} }
val length = val length =
if (measureContentLength) LengthSink().also { write(it) }.length if (measureContentLength) Threads.network.executeAndWait { LengthSink().also { write(it) }.length }
else null else null
return object: RequestBody() { return object: RequestBody() {