From e0bb6a3a78763fac3a7b3656bc0128e33f47657b Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Wed, 3 Jan 2024 18:25:30 +0000 Subject: [PATCH] Only attempt ump decoding when response is successful. --- src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 36588b1..b92edcc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -464,9 +464,7 @@ async fn index(req: HttpRequest) -> Result> { response.no_chunking(content_length.to_str().unwrap().parse::().unwrap()); } - let resp = resp.bytes_stream(); - - if is_ump { + if is_ump && resp.status().is_success() { if let Some(mime_type) = mime_type { response.content_type(mime_type); } @@ -480,6 +478,7 @@ async fn index(req: HttpRequest) -> Result> { } } } + let resp = resp.bytes_stream(); let resp = resp.map_err(|e| io::Error::new(ErrorKind::Other, e)); let transformed_stream = UmpTransformStream::new(resp); // print errors @@ -506,5 +505,5 @@ async fn index(req: HttpRequest) -> Result> { } // Stream response - Ok(response.streaming(resp)) + Ok(response.streaming(resp.bytes_stream())) }