Make sure the decompress option is preserved

This commit is contained in:
Filip Tibell 2025-04-26 21:06:34 +02:00
parent 14197d9398
commit f5993c6505
2 changed files with 16 additions and 5 deletions

View file

@ -22,6 +22,7 @@ use crate::{
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Request { pub struct Request {
inner: HyperRequest<Full<Bytes>>, inner: HyperRequest<Full<Bytes>>,
decompress: bool,
} }
impl Request { impl Request {
@ -67,8 +68,11 @@ impl Request {
// 6. Finally, attach the body, verifying that the request // 6. Finally, attach the body, verifying that the request
// is valid, and attach a user agent if not already set // is valid, and attach a user agent if not already set
let mut inner = builder.body(body).into_lua_err()?; let mut inner = builder.body(body).into_lua_err()?;
add_default_headers(&lua, inner.headers_mut())?; 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<Response> { pub async fn send(self, lua: Lua) -> LuaResult<Response> {
@ -85,7 +89,7 @@ impl Request {
.await .await
.map_err(LuaError::external)?; .map_err(LuaError::external)?;
Response::from_incoming(incoming).await Response::from_incoming(incoming, self.decompress).await
} }
} }

View file

@ -13,10 +13,14 @@ use crate::shared::headers::header_map_to_table;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Response { pub struct Response {
inner: HyperResponse<Bytes>, inner: HyperResponse<Bytes>,
decompressed: bool,
} }
impl Response { impl Response {
pub async fn from_incoming(incoming: HyperResponse<Incoming>) -> LuaResult<Self> { pub async fn from_incoming(
incoming: HyperResponse<Incoming>,
decompressed: bool,
) -> LuaResult<Self> {
let (parts, body) = incoming.into_parts(); let (parts, body) = incoming.into_parts();
let body = BodyStream::new(body) let body = BodyStream::new(body)
@ -32,7 +36,10 @@ impl Response {
let bytes = Bytes::from(body); let bytes = Bytes::from(body);
let inner = HyperResponse::from_parts(parts, bytes); let inner = HyperResponse::from_parts(parts, bytes);
Ok(Self { inner }) Ok(Self {
inner,
decompressed,
})
} }
pub fn status_ok(&self) -> bool { pub fn status_ok(&self) -> bool {
@ -64,7 +71,7 @@ impl LuaUserData for Response {
lua.create_string(this.status_message()) lua.create_string(this.status_message())
}); });
fields.add_field_method_get("headers", |lua, this| { 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())); fields.add_field_method_get("body", |lua, this| lua.create_string(this.body()));
} }