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:
  1. exceeds(jakarta.servlet.http.HttpServletRequest): the declared Content-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.
  2. 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.
Core has already parsed a multipart body into Stapler's temporary upload directory while it dispatched the URL (D-72a); the instance-wide bound on that is Stapler's 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 Details

  • 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 declared Content-Length of the run request submission req is 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 of req named by partNames, the parts a parameter definition's createValue reads: for core's form, every top-level value of the parameter's json entry as text (partNames(JSONObject), a file parameter names its part in file); for a scripted submission without json, the parameter's own name. A name with no uploaded part counts nothing. Long.MAX_VALUE when the parts cannot be read.
    • partNames

      public static Set<String> partNames(net.sf.json.JSONObject entry)
      The part names a json parameter entry can refer to: each top-level value as JSONObject.getString(java.lang.String) reads it (a number or an object as its text).
    • checkKept

      public static void checkKept(List<? extends ParameterValue> values, Map<String,Long> uploaded)
      Stage 2: refuses typed values whose keptSize(java.util.List<? extends hudson.model.ParameterValue>, java.util.Map<java.lang.String, java.lang.Long>) is over the cap, with a RequestTooLargeException naming 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 holding values would 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_VALUE when a size cannot be determined (fail closed).