Class RequestBodyLimit
java.lang.Object
io.jenkins.plugins.batchcontrol.policy.RequestBodyLimit
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
public final class RequestBodyLimit
extends Object
D-72, D-74 (2): the size cap on a run request submission. Requesting a run does not require
Item/Build (D-38a), and a submission may carry file parameters, so its size is checked
in two stages, each answered with HTTP 413 and nothing created or kept:
exceeds(jakarta.servlet.http.HttpServletRequest): the declaredContent-Length, after the permission checks and before the form is read. This is an early filter only; a body without a declared length passes it.checkKept(java.util.List<? extends hudson.model.ParameterValue>, java.util.Map<java.lang.String, java.lang.Long>): what the request would keep, before anything is stored: the size of each value (its stored text, or its file content) and of the uploaded parts it was created from (uploadedSize(org.kohsuke.stapler.StaplerRequest2, java.util.Collection<java.lang.String>)), measured on what the submission actually created whatever names, encodings or part kinds the client used.
org.kohsuke.stapler.RequestImpl.FILEUPLOAD_MAX_SIZE, not this cap.
The cap is the system property "io.jenkins.plugins.batchcontrol.maxRequestBodyBytes" (bytes), default 104857600L (100 MB), read on every check. A missing, unparsable or non-positive value means the default.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault cap: 100 MB.static final StringSystem property holding the cap in bytes. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidStage 2: refuses typed values whosekeptSize(java.util.List<? extends hudson.model.ParameterValue>, java.util.Map<java.lang.String, java.lang.Long>)is over the cap, with aRequestTooLargeExceptionnaming the cap.static booleanexceeds(jakarta.servlet.http.HttpServletRequest req) Stage 1: whether the declaredContent-Lengthof the run request submissionreqis over the cap, from the header alone, for any content type; nothing of the body is read.static longThe size in bytes of what a run request holdingvalueswould keep: for each value its name plus the larger of its own size (ownSize(hudson.model.ParameterValue)) and the size of the uploaded parts it was created from (uploaded, by name).static longThe current cap in bytes.partNames(net.sf.json.JSONObject entry) The part names ajsonparameter entry can refer to: each top-level value asJSONObject.getString(java.lang.String)reads it (a number or an object as its text).static longuploadedSize(org.kohsuke.stapler.StaplerRequest2 req, Collection<String> partNames) The size in bytes of the uploaded parts ofreqnamed bypartNames, the parts a parameter definition'screateValuereads: for core's form, every top-level value of the parameter'sjsonentry as text (partNames(JSONObject), a file parameter names its part infile); for a scripted submission withoutjson, the parameter's own name.
-
Field Details
-
PROPERTY
System property holding the cap in bytes.- See Also:
-
DEFAULT_MAX_BYTES
public static final long DEFAULT_MAX_BYTESDefault cap: 100 MB.- See Also:
-
-
Method Details
-
maxRequestBodyBytes
public static long maxRequestBodyBytes()The current cap in bytes. -
exceeds
public static boolean exceeds(jakarta.servlet.http.HttpServletRequest req) Stage 1: whether the declaredContent-Lengthof the run request submissionreqis over the cap, from the header alone, for any content type; nothing of the body is read. A body without a declared length is judged by stage 2 (checkKept(java.util.List<? extends hudson.model.ParameterValue>, java.util.Map<java.lang.String, java.lang.Long>)). Call it after the permission checks and before anything reads the submitted values. -
uploadedSize
public static long uploadedSize(org.kohsuke.stapler.StaplerRequest2 req, Collection<String> partNames) The size in bytes of the uploaded parts ofreqnamed bypartNames, the parts a parameter definition'screateValuereads: for core's form, every top-level value of the parameter'sjsonentry as text (partNames(JSONObject), a file parameter names its part infile); for a scripted submission withoutjson, the parameter's own name. A name with no uploaded part counts nothing.Long.MAX_VALUEwhen the parts cannot be read. -
partNames
The part names ajsonparameter entry can refer to: each top-level value asJSONObject.getString(java.lang.String)reads it (a number or an object as its text). -
checkKept
Stage 2: refuses typed values whosekeptSize(java.util.List<? extends hudson.model.ParameterValue>, java.util.Map<java.lang.String, java.lang.Long>)is over the cap, with aRequestTooLargeExceptionnaming the cap. The caller disposes of the values' temporary files. Call it before anything of the request is stored.- Parameters:
uploaded- the size of the uploaded parts each value was created from, by parameter name (uploadedSize(org.kohsuke.stapler.StaplerRequest2, java.util.Collection<java.lang.String>)); empty for values that were not uploaded
-
keptSize
public static long keptSize(@CheckForNull List<? extends ParameterValue> values, Map<String, Long> uploaded) The size in bytes of what a run request holdingvalueswould keep: for each value its name plus the larger of its own size (ownSize(hudson.model.ParameterValue)) and the size of the uploaded parts it was created from (uploaded, by name). The second covers a value whose content its public API does not expose (the file-parameters plugin's stashed file keeps a copy of its part); the first covers values that were not uploaded in this submission (an incident rerun).Long.MAX_VALUEwhen a size cannot be determined (fail closed).
-