diff --git a/ktor-server/ktor-server-core/api/ktor-server-core.api b/ktor-server/ktor-server-core/api/ktor-server-core.api index ff48e5ac0a4..4cce6b30df3 100644 --- a/ktor-server/ktor-server-core/api/ktor-server-core.api +++ b/ktor-server/ktor-server-core/api/ktor-server-core.api @@ -1000,11 +1000,11 @@ public final class io/ktor/server/plugins/UnsupportedMediaTypeException : io/kto } public final class io/ktor/server/request/ApplicationReceiveFunctionsJvmKt { + public static final fun getDEFAULT_FORM_FIELD_LIMIT ()J public static final fun receiveStream (Lio/ktor/server/application/ApplicationCall;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public final class io/ktor/server/request/ApplicationReceiveFunctionsKt { - public static final field DEFAULT_FORM_FIELD_MAX_SIZE J public static final fun getFormFieldLimit (Lio/ktor/server/application/ApplicationCall;)J public static final fun receive (Lio/ktor/server/application/ApplicationCall;Lio/ktor/util/reflect/TypeInfo;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun receive (Lio/ktor/server/application/ApplicationCall;Lkotlin/reflect/KClass;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/ktor-server/ktor-server-core/api/ktor-server-core.klib.api b/ktor-server/ktor-server-core/api/ktor-server-core.klib.api index 015707e5355..2fc2e279451 100644 --- a/ktor-server/ktor-server-core/api/ktor-server-core.klib.api +++ b/ktor-server/ktor-server-core/api/ktor-server-core.klib.api @@ -1602,9 +1602,6 @@ final object io.ktor.server.routing/TrailingSlashRouteSelector : io.ktor.server. final suspend fun evaluate(io.ktor.server.routing/RoutingResolveContext, kotlin/Int): io.ktor.server.routing/RouteSelectorEvaluation // io.ktor.server.routing/TrailingSlashRouteSelector.evaluate|evaluate(io.ktor.server.routing.RoutingResolveContext;kotlin.Int){}[0] } -final const val io.ktor.server.request/DEFAULT_FORM_FIELD_MAX_SIZE // io.ktor.server.request/DEFAULT_FORM_FIELD_MAX_SIZE|{}DEFAULT_FORM_FIELD_MAX_SIZE[0] - final fun (): kotlin/Long // io.ktor.server.request/DEFAULT_FORM_FIELD_MAX_SIZE.|(){}[0] - final val io.ktor.server.application/ApplicationStarted // io.ktor.server.application/ApplicationStarted|{}ApplicationStarted[0] final fun (): io.ktor.events/EventDefinition // io.ktor.server.application/ApplicationStarted.|(){}[0] final val io.ktor.server.application/ApplicationStarting // io.ktor.server.application/ApplicationStarting|{}ApplicationStarting[0] @@ -1649,6 +1646,8 @@ final val io.ktor.server.plugins/mutableOriginConnectionPoint // io.ktor.server. final fun (io.ktor.server.application/ApplicationCall).(): io.ktor.server.plugins/MutableOriginConnectionPoint // io.ktor.server.plugins/mutableOriginConnectionPoint.|@io.ktor.server.application.ApplicationCall(){}[0] final val io.ktor.server.plugins/origin // io.ktor.server.plugins/origin|@io.ktor.server.request.ApplicationRequest{}origin[0] final fun (io.ktor.server.request/ApplicationRequest).(): io.ktor.http/RequestConnectionPoint // io.ktor.server.plugins/origin.|@io.ktor.server.request.ApplicationRequest(){}[0] +final val io.ktor.server.request/DEFAULT_FORM_FIELD_LIMIT // io.ktor.server.request/DEFAULT_FORM_FIELD_LIMIT|{}DEFAULT_FORM_FIELD_LIMIT[0] + final fun (): kotlin/Long // io.ktor.server.request/DEFAULT_FORM_FIELD_LIMIT.|(){}[0] final val io.ktor.server.request/httpMethod // io.ktor.server.request/httpMethod|@io.ktor.server.request.ApplicationRequest{}httpMethod[0] final fun (io.ktor.server.request/ApplicationRequest).(): io.ktor.http/HttpMethod // io.ktor.server.request/httpMethod.|@io.ktor.server.request.ApplicationRequest(){}[0] final val io.ktor.server.request/httpVersion // io.ktor.server.request/httpVersion|@io.ktor.server.request.ApplicationRequest{}httpVersion[0] diff --git a/ktor-server/ktor-server-core/common/src/io/ktor/server/request/ApplicationReceiveFunctions.kt b/ktor-server/ktor-server-core/common/src/io/ktor/server/request/ApplicationReceiveFunctions.kt index 64ac8207378..babaa9f731b 100644 --- a/ktor-server/ktor-server-core/common/src/io/ktor/server/request/ApplicationReceiveFunctions.kt +++ b/ktor-server/ktor-server-core/common/src/io/ktor/server/request/ApplicationReceiveFunctions.kt @@ -20,7 +20,7 @@ import kotlin.reflect.* private val FORM_FIELD_LIMIT = AttributeKey("FormFieldLimit") @PublishedApi -internal const val DEFAULT_FORM_FIELD_MAX_SIZE: Long = 50 * 1024 * 1024 +internal expect val DEFAULT_FORM_FIELD_LIMIT: Long /** * A pipeline for processing incoming content. @@ -176,7 +176,7 @@ public suspend inline fun ApplicationCall.receiveChannel(): ByteReadChannel = re */ public var ApplicationCall.formFieldLimit: Long get() { - return attributes.getOrNull(FORM_FIELD_LIMIT) ?: DEFAULT_FORM_FIELD_MAX_SIZE + return attributes.getOrNull(FORM_FIELD_LIMIT) ?: DEFAULT_FORM_FIELD_LIMIT } set(value) { attributes.put(FORM_FIELD_LIMIT, value) diff --git a/ktor-server/ktor-server-core/jsAndWasmShared/src/io/ktor/server/request/ApplicationReceiveFunctions.jsAndWasmShared.kt b/ktor-server/ktor-server-core/jsAndWasmShared/src/io/ktor/server/request/ApplicationReceiveFunctions.jsAndWasmShared.kt new file mode 100644 index 00000000000..ffe338b8710 --- /dev/null +++ b/ktor-server/ktor-server-core/jsAndWasmShared/src/io/ktor/server/request/ApplicationReceiveFunctions.jsAndWasmShared.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package io.ktor.server.request + +@PublishedApi +internal actual val DEFAULT_FORM_FIELD_LIMIT: Long + get() = 50 * 1024 * 1024L diff --git a/ktor-server/ktor-server-core/jvm/src/io/ktor/server/engine/DefaultTransformJvm.kt b/ktor-server/ktor-server-core/jvm/src/io/ktor/server/engine/DefaultTransformJvm.kt index a5379f8e5e7..00305e63558 100644 --- a/ktor-server/ktor-server-core/jvm/src/io/ktor/server/engine/DefaultTransformJvm.kt +++ b/ktor-server/ktor-server-core/jvm/src/io/ktor/server/engine/DefaultTransformJvm.kt @@ -45,7 +45,7 @@ internal actual fun PipelineContext<*, PipelineCall>.multiPartData(rc: ByteReadC rc, contentType, contentLength, - call.formFieldLimit + formFieldLimit = call.formFieldLimit ) } catch (_: UnsupportedMediaTypeExceptionCIO) { throw UnsupportedMediaTypeException(ContentType.parse(contentType)) diff --git a/ktor-server/ktor-server-core/jvm/src/io/ktor/server/request/ApplicationReceiveFunctionsJvm.kt b/ktor-server/ktor-server-core/jvm/src/io/ktor/server/request/ApplicationReceiveFunctionsJvm.kt index aefcfd8de80..469cd36291f 100644 --- a/ktor-server/ktor-server-core/jvm/src/io/ktor/server/request/ApplicationReceiveFunctionsJvm.kt +++ b/ktor-server/ktor-server-core/jvm/src/io/ktor/server/request/ApplicationReceiveFunctionsJvm.kt @@ -14,3 +14,7 @@ import java.io.* */ @Suppress("NOTHING_TO_INLINE") public suspend inline fun ApplicationCall.receiveStream(): InputStream = receive() + +@PublishedApi +internal actual val DEFAULT_FORM_FIELD_LIMIT: Long + get() = System.getProperty("io.ktor.server.request.formFieldLimit")?.toLongOrNull() ?: (50 * 1024 * 1024L) diff --git a/ktor-server/ktor-server-core/posix/src/io/ktor/server/request/ApplicationReceiveFunctions.posix.kt b/ktor-server/ktor-server-core/posix/src/io/ktor/server/request/ApplicationReceiveFunctions.posix.kt new file mode 100644 index 00000000000..ffe338b8710 --- /dev/null +++ b/ktor-server/ktor-server-core/posix/src/io/ktor/server/request/ApplicationReceiveFunctions.posix.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package io.ktor.server.request + +@PublishedApi +internal actual val DEFAULT_FORM_FIELD_LIMIT: Long + get() = 50 * 1024 * 1024L