guardian / play-brotli-filter

Brotli filter for the playframework

Github

Brotli filter for play

Maven Central Build Status License

A Brotli filter for the playframework

Install

Add jbrotli bintray as a resolver:

resolvers += "JBrotli Bintray Repository" at "https://dl.bintray.com/nitram509/jbrotli/"

Add play-brotli-filter as a dependency:

libraryDependencies ++= Seq(
 "com.gu" %% "play-brotli-filter" % "0.1",
 "org.meteogroup.jbrotli" % brotliNativeArtefact % "0.5.0",
)

brotliNativeArtefact is dependent of your target platform and can not be resolved transparently as sbt does not support activating maven profile (as far as I am aware).

Below is a workaround that should allow to have the correct artefact name depending on your platform:

val brotliNativeArtefact = {

  val osName = System.getProperty("os.name").toLowerCase
  val osArch = System.getProperty("os.arch").toLowerCase
  
  val family = if (osName.startsWith("linux")) {
    "linux"
    } else if (osName.startsWith("mac os x") || osName.startsWith("darwin")) {
      "darwin"
    } else {
      "win32"
  }

  val arch = if (family == "darwin") {
      "x86-amd64"
    } else if (osArch == "i386" || osArch == "i486" || osArch == "i586" || osArch == "i686") {
      "x86"
    } else if (osArch == "amd64" || osArch == "x86-64" || osArch == "x64") {
      "x86-amd64"
    } else if (family == "linux" && osArch.startsWith("arm")) {
      "arm32-vfp-hflt"
  }

  s"jbrotli-native-$family-$arch"
}

Configure

Currently the only parameter you can configure is quality, which defaults to 5.

play.filters {

  # Brotli filter configuration
  brotli {

    # The compression-speed vs compression-density tradeoffs. The higher the quality, the slower the compression. Range is 0 to 11
    quality = 5

  }
}