mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Make sure the decompress option is preserved
This commit is contained in:
parent
14197d9398
commit
f5993c6505
2 changed files with 16 additions and 5 deletions
|
@ -22,6 +22,7 @@ use crate::{
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct Request {
|
||||
inner: HyperRequest<Full<Bytes>>,
|
||||
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<Response> {
|
||||
|
@ -85,7 +89,7 @@ impl Request {
|
|||
.await
|
||||
.map_err(LuaError::external)?;
|
||||
|
||||
Response::from_incoming(incoming).await
|
||||
Response::from_incoming(incoming, self.decompress).await
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,14 @@ use crate::shared::headers::header_map_to_table;
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct Response {
|
||||
inner: HyperResponse<Bytes>,
|
||||
decompressed: bool,
|
||||
}
|
||||
|
||||
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 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()));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue