Skip to content

Instantly share code, notes, and snippets.

@markoutso
Created August 7, 2018 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markoutso/b7abd5102ec63530174a677b8084aae4 to your computer and use it in GitHub Desktop.
Save markoutso/b7abd5102ec63530174a677b8084aae4 to your computer and use it in GitHub Desktop.
import akka.http.scaladsl.coding.Gzip
import akka.http.scaladsl.model._
object GzipBinEncoder extends Gzip(GzipBinEncoderFilter)
object GzipBinEncoderFilter extends (HttpMessage => Boolean) {
override def apply(message: HttpMessage): Boolean =
message match {
case req: HttpRequest ⇒ req.entity.contentType.mediaType.isCompressible
case res@HttpResponse(status, _, _, _) =>
val mediaType = res.entity.contentType.mediaType
(mediaType == MediaTypes.`application/octet-stream` || mediaType.isCompressible) && status.allowsEntity
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment