mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-07-07 10:16:43 +03:00
Simplify response body decoding when there is no content encoding.
This commit is contained in:
parent
1ed0b4e29c
commit
3141e344cd
|
@ -67,12 +67,17 @@ impl ContentEncoding {
|
|||
impl Response {
|
||||
/// Returns response body as text.
|
||||
pub fn text(&self) -> Result<String, HttpError> {
|
||||
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(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user