From f5993c6505d188e0109aaa5660e958ca28b60d69 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sat, 26 Apr 2025 21:06:34 +0200 Subject: [PATCH] Make sure the decompress option is preserved --- crates/lune-std-net/src/shared/request.rs | 8 ++++++-- crates/lune-std-net/src/shared/response.rs | 13 ++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/lune-std-net/src/shared/request.rs b/crates/lune-std-net/src/shared/request.rs index b39123c..4dcf96a 100644 --- a/crates/lune-std-net/src/shared/request.rs +++ b/crates/lune-std-net/src/shared/request.rs @@ -22,6 +22,7 @@ use crate::{ #[derive(Debug, Clone)] pub struct Request { inner: HyperRequest>, + decompress: bool, } impl Request { @@ -67,8 +68,11 @@ impl Request { // 6. Finally, attach the body, verifying that the request // is valid, and attach a user agent if not already set let mut inner = builder.body(body).into_lua_err()?; + add_default_headers(&lua, inner.headers_mut())?; - Ok(Self { inner }) + + let decompress = config.options.decompress; + Ok(Self { inner, decompress }) } pub async fn send(self, lua: Lua) -> LuaResult { @@ -85,7 +89,7 @@ impl Request { .await .map_err(LuaError::external)?; - Response::from_incoming(incoming).await + Response::from_incoming(incoming, self.decompress).await } } diff --git a/crates/lune-std-net/src/shared/response.rs b/crates/lune-std-net/src/shared/response.rs index e746c68..9332479 100644 --- a/crates/lune-std-net/src/shared/response.rs +++ b/crates/lune-std-net/src/shared/response.rs @@ -13,10 +13,14 @@ use crate::shared::headers::header_map_to_table; #[derive(Debug, Clone)] pub struct Response { inner: HyperResponse, + decompressed: bool, } impl Response { - pub async fn from_incoming(incoming: HyperResponse) -> LuaResult { + pub async fn from_incoming( + incoming: HyperResponse, + decompressed: bool, + ) -> LuaResult { let (parts, body) = incoming.into_parts(); let body = BodyStream::new(body) @@ -32,7 +36,10 @@ impl Response { let bytes = Bytes::from(body); let inner = HyperResponse::from_parts(parts, bytes); - Ok(Self { inner }) + Ok(Self { + inner, + decompressed, + }) } pub fn status_ok(&self) -> bool { @@ -64,7 +71,7 @@ impl LuaUserData for Response { lua.create_string(this.status_message()) }); fields.add_field_method_get("headers", |lua, this| { - header_map_to_table(lua, this.headers().clone(), false) + header_map_to_table(lua, this.headers().clone(), this.decompressed) }); fields.add_field_method_get("body", |lua, this| lua.create_string(this.body())); }