Class FormBodyPartBuilder

java.lang.Object
org.apache.hc.client5.http.entity.mime.FormBodyPartBuilder

public class FormBodyPartBuilder extends Object
Builder for individual FormBodyParts.
Since:
4.4
  • Field Details

    • name

      private String name
    • body

      private ContentBody body
    • mode

      private HttpMultipartMode mode
      The multipart mode determining how filenames are encoded in the Content-Disposition header, defaults to HttpMultipartMode.STRICT.
      Since:
      5.5
    • iso8859_1Encoder

      private CharsetEncoder iso8859_1Encoder
      Encoder used to check if strings can be encoded in ISO-8859-1, supporting filename compatibility determinations in multipart form data.
  • Constructor Details

  • Method Details

    • create

      public static FormBodyPartBuilder create(String name, ContentBody body, HttpMultipartMode mode)
      Creates a new builder instance with the specified name, content body, and multipart mode.
      Parameters:
      name - the name of the form field
      body - the content body of the part
      mode - the HttpMultipartMode to use, determining filename encoding behavior;
      Returns:
      a new FormBodyPartBuilder instance
      Since:
      5.5
    • create

      public static FormBodyPartBuilder create(String name, ContentBody body)
    • create

      public static FormBodyPartBuilder create()
    • setName

      public FormBodyPartBuilder setName(String name)
    • setBody

      public FormBodyPartBuilder setBody(ContentBody body)
    • addField

      public FormBodyPartBuilder addField(String name, String value, List<org.apache.hc.core5.http.NameValuePair> parameters)
      Since:
      4.6
    • addField

      public FormBodyPartBuilder addField(String name, String value)
    • setField

      public FormBodyPartBuilder setField(String name, String value)
    • removeFields

      public FormBodyPartBuilder removeFields(String name)
    • canEncodeToISO8859_1

      private boolean canEncodeToISO8859_1(String input)
      Determines whether the given string can be encoded in ISO-8859-1 without loss of data. This is used to decide whether the filename parameter can be used as-is or if the filename* parameter is needed for non-ISO-8859-1 characters.
      Parameters:
      input - the string to check, must not be null
      Returns:
      true if the string can be encoded in ISO-8859-1, false otherwise
      Since:
      5.5
    • encodeRFC5987

      private static String encodeRFC5987(String filename)
      Encodes the given filename according to RFC 5987, prefixing it with UTF-8'' and applying percent-encoding to non-ASCII characters. This is used for the filename* parameter in the Content-Disposition header when non-ISO-8859-1 characters are present.
      Parameters:
      filename - the filename to encode, must not be null
      Returns:
      the RFC 5987-encoded string, e.g., UTF-8''example%20text
      Since:
      5.5
    • build

      public FormBodyPart build()