diff --git a/packages/hurl/src/http/response_decoding.rs b/packages/hurl/src/http/response_decoding.rs index 0980c75d5..531043e34 100644 --- a/packages/hurl/src/http/response_decoding.rs +++ b/packages/hurl/src/http/response_decoding.rs @@ -67,12 +67,17 @@ impl ContentEncoding { impl Response { /// Returns response body as text. pub fn text(&self) -> Result { - let encoding = self.headers.character_encoding()?; - let body = &self.uncompress_body()?; - match encoding.decode(body, DecoderTrap::Strict) { + let content_encodings = self.headers.content_encoding()?; + let body = if content_encodings.is_empty() { + &self.body + } else { + &self.uncompress_body()? + }; + let character_encoding = self.headers.character_encoding()?; + match character_encoding.decode(body, DecoderTrap::Strict) { Ok(s) => Ok(s), Err(_) => Err(HttpError::InvalidDecoding { - charset: encoding.name().to_string(), + charset: character_encoding.name().to_string(), }), } }