LoginSignup
2
1

More than 5 years have passed since last update.

Akka HTTPでgzip圧縮を有効にする方法

Last updated at Posted at 2017-03-01

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")
}

よく見たらちゃんとドキュメントに書いてあった…

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1