Skip to content

Commit

Permalink
KTOR-8082 Add formFieldLimit system property
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Jan 23, 2025
1 parent fb57b18 commit 99c8cf0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
5 changes: 4 additions & 1 deletion ktor-server/ktor-server-core/api/ktor-server-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,6 @@ public final class io/ktor/server/request/ApplicationReceiveFunctionsJvmKt {
}

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;
Expand All @@ -1018,6 +1017,10 @@ public final class io/ktor/server/request/ApplicationReceiveFunctionsKt {
public static final fun setFormFieldLimit (Lio/ktor/server/application/ApplicationCall;J)V
}

public final class io/ktor/server/request/ApplicationReceiveFunctions_jvmKt {
public static final fun getDEFAULT_FORM_FIELD_LIMIT ()J
}

public class io/ktor/server/request/ApplicationReceivePipeline : io/ktor/util/pipeline/Pipeline {
public static final field Phases Lio/ktor/server/request/ApplicationReceivePipeline$Phases;
public fun <init> ()V
Expand Down
5 changes: 2 additions & 3 deletions ktor-server/ktor-server-core/api/ktor-server-core.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <get-DEFAULT_FORM_FIELD_MAX_SIZE>(): kotlin/Long // io.ktor.server.request/DEFAULT_FORM_FIELD_MAX_SIZE.<get-DEFAULT_FORM_FIELD_MAX_SIZE>|<get-DEFAULT_FORM_FIELD_MAX_SIZE>(){}[0]

final val io.ktor.server.application/ApplicationStarted // io.ktor.server.application/ApplicationStarted|{}ApplicationStarted[0]
final fun <get-ApplicationStarted>(): io.ktor.events/EventDefinition<io.ktor.server.application/Application> // io.ktor.server.application/ApplicationStarted.<get-ApplicationStarted>|<get-ApplicationStarted>(){}[0]
final val io.ktor.server.application/ApplicationStarting // io.ktor.server.application/ApplicationStarting|{}ApplicationStarting[0]
Expand Down Expand Up @@ -1649,6 +1646,8 @@ final val io.ktor.server.plugins/mutableOriginConnectionPoint // io.ktor.server.
final fun (io.ktor.server.application/ApplicationCall).<get-mutableOriginConnectionPoint>(): io.ktor.server.plugins/MutableOriginConnectionPoint // io.ktor.server.plugins/mutableOriginConnectionPoint.<get-mutableOriginConnectionPoint>|<get-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).<get-origin>(): io.ktor.http/RequestConnectionPoint // io.ktor.server.plugins/origin.<get-origin>|<get-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 <get-DEFAULT_FORM_FIELD_LIMIT>(): kotlin/Long // io.ktor.server.request/DEFAULT_FORM_FIELD_LIMIT.<get-DEFAULT_FORM_FIELD_LIMIT>|<get-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).<get-httpMethod>(): io.ktor.http/HttpMethod // io.ktor.server.request/httpMethod.<get-httpMethod>|<get-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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlin.reflect.*
private val FORM_FIELD_LIMIT = AttributeKey<Long>("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.
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ 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)
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 99c8cf0

Please sign in to comment.