encodeResponseWith
を使いましょう。公式ドキュメントはこちら。
import akka.http.scaladsl.coding.Gzip
import akka.http.scaladsl.server.Directives._
encodeResponseWith(Gzip) {
complete("content")
}
ただこれだとAccept-Encoding
を見てくれなくて常にGzip圧縮されてしまう。curlとかでそのままアクセスすると悲惨なことになります。そういう挙動が嫌な場合は次のようにすれば解決です。
import akka.http.scaladsl.coding.{ Gzip, NoCoding }
import akka.http.scaladsl.server.Directives._
encodeResponseWith(NoCoding, Gzip) {
complete("content")
}
よく見たらちゃんとドキュメントに書いてあった…