encodeResponseWith

encodeResponseWith

Signature

Description

Encodes the response with the encoding that is requested by the client via the Accept-Encoding if it is among the provided encoders or rejects the request with an UnacceptedResponseEncodingRejection(supportedEncodings).

The response encoding is determined by the rules specified in RFC7231.

If the Accept-Encoding header is missing then the response is encoded using the first encoder.

If the Accept-Encoding header is empty and NoCoding is part of the encoders then no response encoding is used. Otherwise the request is rejected.

Example

val route = encodeResponseWith(Gzip) { complete("content") }

// tests:
Get("/") ~> route ~> check {
  response should haveContentEncoding(gzip)
}
Get("/") ~> `Accept-Encoding`(gzip, deflate) ~> route ~> check {
  response should haveContentEncoding(gzip)
}
Get("/") ~> `Accept-Encoding`(deflate) ~> route ~> check {
  rejection shouldEqual UnacceptedResponseEncodingRejection(gzip)
}
Get("/") ~> `Accept-Encoding`(identity) ~> route ~> check {
  rejection shouldEqual UnacceptedResponseEncodingRejection(gzip)
}

Contents