From 3141e344cd865d3ffb00380f974e2534f6278d75 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Amiel Date: Thu, 4 Jul 2024 13:20:48 +0200 Subject: [PATCH] Simplify response body decoding when there is no content encoding. --- packages/hurl/src/http/response_decoding.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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(), }), } }