decodeRequest

decodeRequest

§Signature

§Description

Decompresses the incoming request if it is gzip or deflate compressed. Uncompressed requests are passed through untouched. If the request encoded with another encoding the request is rejected with an UnsupportedRequestEncodingRejection.

§Example

  1. val route =
  2. decodeRequest {
  3. entity(as[String]) { content: String =>
  4. complete(s"Request content: '$content'")
  5. }
  6. }
  7.  
  8. // tests:
  9. Post("/", helloGzipped) ~> `Content-Encoding`(gzip) ~> route ~> check {
  10. responseAs[String] shouldEqual "Request content: 'Hello'"
  11. }
  12. Post("/", helloDeflated) ~> `Content-Encoding`(deflate) ~> route ~> check {
  13. responseAs[String] shouldEqual "Request content: 'Hello'"
  14. }
  15. Post("/", "hello uncompressed") ~> `Content-Encoding`(identity) ~> route ~> check {
  16. responseAs[String] shouldEqual "Request content: 'hello uncompressed'"
  17. }