mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-10-05 19:49:04 +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 {
|
impl Response {
|
||||||
/// Returns response body as text.
|
/// Returns response body as text.
|
||||||
pub fn text(&self) -> Result<String, HttpError> {
|
pub fn text(&self) -> Result<String, HttpError> {
|
||||||
let encoding = self.headers.character_encoding()?;
|
let content_encodings = self.headers.content_encoding()?;
|
||||||
let body = &self.uncompress_body()?;
|
let body = if content_encodings.is_empty() {
|
||||||
match encoding.decode(body, DecoderTrap::Strict) {
|
&self.body
|
||||||
|
} else {
|
||||||
|
&self.uncompress_body()?
|
||||||
|
};
|
||||||
|
let character_encoding = self.headers.character_encoding()?;
|
||||||
|
match character_encoding.decode(body, DecoderTrap::Strict) {
|
||||||
Ok(s) => Ok(s),
|
Ok(s) => Ok(s),
|
||||||
Err(_) => Err(HttpError::InvalidDecoding {
|
Err(_) => Err(HttpError::InvalidDecoding {
|
||||||
charset: encoding.name().to_string(),
|
charset: character_encoding.name().to_string(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user