All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.touk.nussknacker.ui.server.HeadersSupport.scala Maven / Gradle / Ivy

There is a newer version: 1.17.0
Show newest version
package pl.touk.nussknacker.ui.server

object HeadersSupport {
  final case class FileName(value: String)

  final case class ContentDisposition(fileName: Option[FileName]) {
    private val doubleQuote = '"'
    def headerValue(): Option[String] =
      fileName.map(v => s"Content-Disposition: attachment; filename=$doubleQuote${v.value}$doubleQuote")
  }

  object ContentDisposition {
    private val filenameRegex = "filename=\"(.+?)\"".r

    def apply(headerValue: String): ContentDisposition =
      new ContentDisposition(
        filenameRegex
          .findFirstMatchIn(headerValue)
          .map(_.group(1))
          .map(FileName)
      )

    def fromFileNameString(fileName: String): ContentDisposition =
      new ContentDisposition(Some(FileName(fileName)))
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy