Skip to content

Commit

Permalink
remove warning in get_compression_type
Browse files Browse the repository at this point in the history
  • Loading branch information
ducaale committed Apr 14, 2022
1 parent 5c78ddc commit a51509f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/printer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::borrow::Cow;
use std::env;
use std::io::{self, BufRead, BufReader, Read, Write};
use std::str::FromStr;

Expand Down Expand Up @@ -577,6 +576,7 @@ impl FromStr for CompressionType {
}
}

// See https://github.com/seanmonstar/reqwest/blob/9bd4e90ec3401c2c5bc435c58954f3d52ab53e99/src/async_impl/decoder.rs#L150
fn get_compression_type(headers: &HeaderMap) -> Option<CompressionType> {
let mut compression_type = headers
.get_all(CONTENT_ENCODING)
Expand All @@ -590,14 +590,9 @@ fn get_compression_type(headers: &HeaderMap) -> Option<CompressionType> {
.find_map(|value| value.to_str().ok().and_then(|value| value.parse().ok()));
}

if let Some(compression_type) = &compression_type {
if compression_type.is_some() {
if let Some(content_length) = headers.get(CONTENT_LENGTH) {
if content_length == "0" {
eprintln!(
"{}: warning: {:?} response with content-length of 0",
env!("CARGO_PKG_NAME"),
compression_type,
);
return None;
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2846,7 +2846,6 @@ fn empty_response_with_content_encoding() {
get_command()
.arg(server.base_url())
.assert()
.stderr("xh: warning: Gzip response with content-length of 0\n")
.stdout(indoc! {r#"
HTTP/1.1 200 OK
Content-Encoding: gzip
Expand Down

0 comments on commit a51509f

Please sign in to comment.