我使用compressResponse
关键字声明路线:
(compressResponse(Gzip) & respondWithMediaType(`application/json`)) {
super.routes
}
ret.status match {
case ResponseResult.StatSuccess => complete(200, ret.toString)
case _ => complete(InternalServerError, ret.toString)
}
但是,我发现ret
仅在完成200时被编码为Gzip。对于400,500,Spray只返回纯文本。
答案 0 :(得分:0)
object AllGzip {
import MessagePredicate._
val DefaultFilter = (isRequest || responseStatus(ret => ret.isSuccess || ret.isFailure)) && isCompressible
}
object AllEncodedGzip extends Gzip(AllGzip.DefaultFilter) {
def apply(messageFilter: MessagePredicate) = new Gzip(messageFilter)
}
将Gzip更改为AllEncodedGzip,spray将编码任何类型的响应消息给Gzip