@ Nonnull public final UnifiedResponse setContentDispositionFilename ( @ Nonnull @ Nonempty final String sFilename ) { ValueEnforcer . notEmpty ( sFilename , "Filename" ) ; // Ensure that a valid filename is used // -> Strip all paths and replace all invalid characters final String sFilenameToUse = FilenameHelper . getWithoutPath ( FilenameHelper . getAsSecureValidFilename ( sFilename ) ) ; if ( ! sFilename . equals ( sFilenameToUse ) ) logWarn ( "Content-Dispostion filename was internally modified from '" + sFilename + "' to '" + sFilenameToUse + "'" ) ; // Disabled because of the extended UTF-8 handling (RFC 5987) if ( false ) { // Check if encoding as ISO-8859-1 is possible if ( m_aContentDispositionEncoder == null ) m_aContentDispositionEncoder = StandardCharsets . ISO_8859_1 . newEncoder ( ) ; if ( ! m_aContentDispositionEncoder . canEncode ( sFilenameToUse ) ) logError ( "Content-Dispostion filename '" + sFilenameToUse + "' cannot be encoded to ISO-8859-1!" ) ; } // Are we overwriting? if ( m_sContentDispositionFilename != null ) logInfo ( "Overwriting Content-Dispostion filename from '" + m_sContentDispositionFilename + "' to '" + sFilenameToUse + "'" ) ; // No URL encoding necessary. // Filename must be in ISO-8859-1 // See http://greenbytes.de/tech/tc2231/ m_sContentDispositionFilename = sFilenameToUse ; return this ; }
Set the content disposition filename for attachment download .