Class RFC2231

java.lang.Object
org.nuxeo.common.utils.RFC2231

public class RFC2231 extends Object
RFC-2231 specifies how a MIME parameter value, like Content-Disposition's filename, can be encoded to contain arbitrary character sets.
Author:
Florent Guillaume
  • Method Details

    • percentEscape

      @Deprecated(since="2025.18", forRemoval=true) public static void percentEscape(StringBuilder sb, String value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 2025.18, not used anymore
    • encodeRFC2231

      protected static void encodeRFC2231(StringBuilder sb, String value)
      Encodes a value per RFC 2231, percent-encoding all non-attr-char bytes of the UTF-8 representation.
      Parameters:
      sb - the buffer to append the encoded value to
      value - the value to encode
    • encodeContentDisposition

      public static String encodeContentDisposition(String filename, boolean inline)
      Encodes a Content-Disposition header following RFC 6266 best practice. When encoding is needed, both filename (ASCII fallback per RFC 6266 Appendix D) and filename* (RFC 2231 / RFC 5987 encoded) parameters are included. The fallback is a best-effort ASCII transliteration of the original filename, so legacy user agents that ignore filename* still receive a usable name.

      If the filename is null or blank, defaults to "file" to avoid NPEs and ensure valid headers.

      Parameters:
      filename - the filename, or null/"" to default to "file"
      inline - true for an inline disposition, false for an attachment
      Returns:
      a full string to set as value of a Content-Disposition header
      Since:
      2025.18
    • encodeContentDisposition

      @Deprecated(since="2025.18", forRemoval=true) public static String encodeContentDisposition(String filename, boolean inline, String userAgent)
      Deprecated, for removal: This API element is subject to removal in a future version.