Skip to content

Commit 8aad640

Browse files
committed
wg_webclient/wg_client: handle deflate encoding and dont crash on decompression errors
1 parent af4c991 commit 8aad640

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

wg-webclient/src/wg_client.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,20 @@ fn poll_response(
589589
if encoding == "gzip" {
590590
let mut gz = GzDecoder::new(&result[..]);
591591
let mut s = String::new();
592-
gz.read_to_string(&mut s).unwrap();
592+
if let Err(err) = gz.read_to_string(&mut s) {
593+
log::error!("Error decoding gzip: {}", err);
594+
}
595+
s.as_bytes().to_vec()
596+
} else if encoding == "deflate" {
597+
let mut gz = flate2::read::ZlibDecoder::new(&result[..]);
598+
let mut s = String::new();
599+
if let Err(err) = gz.read_to_string(&mut s) {
600+
log::error!("Error decoding deflate: {}", err);
601+
}
593602
s.as_bytes().to_vec()
594603
} else {
595-
// FIXME: handle other encodings and throw exception instead of panic
596-
panic!("unknown encoding: {}", encoding.to_str().unwrap());
604+
log::error!("Unknown encoding: {}", encoding.to_str().unwrap());
605+
result.clone()
597606
}
598607
} else {
599608
result.clone()

0 commit comments

Comments
 (0)