encodeResponse

encodeResponse

§Signature

§Description

Encodes the response with the encoding that is requested by the client via the Accept-Encoding header 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 or empty or specifies an encoding other than identity, gzip or deflate then no encoding is used.

§Example

  1. val route = encodeResponse { complete("content") }
  2.  
  3. // tests:
  4. Get("/") ~> route ~> check {
  5. response should haveContentEncoding(identity)
  6. }
  7. Get("/") ~> `Accept-Encoding`(gzip, deflate) ~> route ~> check {
  8. response should haveContentEncoding(gzip)
  9. }
  10. Get("/") ~> `Accept-Encoding`(deflate) ~> route ~> check {
  11. response should haveContentEncoding(deflate)
  12. }
  13. Get("/") ~> `Accept-Encoding`(identity) ~> route ~> check {
  14. response should haveContentEncoding(identity)
  15. }