mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Dont unnecessarily clone the entire response in http server
This commit is contained in:
parent
37da9a39ec
commit
b41980d6e1
3 changed files with 25 additions and 3 deletions
|
@ -99,7 +99,7 @@ async fn handle_request(
|
||||||
let config = ResponseConfig::from_lua_multi(thread_res, &lua)?;
|
let config = ResponseConfig::from_lua_multi(thread_res, &lua)?;
|
||||||
let response = Response::try_from(config)?;
|
let response = Response::try_from(config)?;
|
||||||
|
|
||||||
Ok(response.as_full())
|
Ok(response.into_full())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_websocket(
|
async fn handle_websocket(
|
||||||
|
|
|
@ -105,9 +105,10 @@ impl Request {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the inner `hyper` request with its body
|
Clones the inner `hyper` request with its body
|
||||||
type modified to `Full<Bytes>` for sending.
|
type modified to `Full<Bytes>` for sending.
|
||||||
*/
|
*/
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn as_full(&self) -> HyperRequest<Full<Bytes>> {
|
pub fn as_full(&self) -> HyperRequest<Full<Bytes>> {
|
||||||
let mut builder = HyperRequest::builder()
|
let mut builder = HyperRequest::builder()
|
||||||
.version(self.inner.version())
|
.version(self.inner.version())
|
||||||
|
@ -122,6 +123,16 @@ impl Request {
|
||||||
let body = Full::new(self.inner.body().clone());
|
let body = Full::new(self.inner.body().clone());
|
||||||
builder.body(body).expect("request was valid")
|
builder.body(body).expect("request was valid")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Takes the inner `hyper` request with its body
|
||||||
|
type modified to `Full<Bytes>` for sending.
|
||||||
|
*/
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn into_full(self) -> HyperRequest<Full<Bytes>> {
|
||||||
|
let (parts, body) = self.inner.into_parts();
|
||||||
|
HyperRequest::from_parts(parts, Full::new(body))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<RequestConfig> for Request {
|
impl TryFrom<RequestConfig> for Request {
|
||||||
|
|
|
@ -75,9 +75,10 @@ impl Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the inner `hyper` response with its body
|
Clones the inner `hyper` response with its body
|
||||||
type modified to `Full<Bytes>` for sending.
|
type modified to `Full<Bytes>` for sending.
|
||||||
*/
|
*/
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn as_full(&self) -> HyperResponse<Full<Bytes>> {
|
pub fn as_full(&self) -> HyperResponse<Full<Bytes>> {
|
||||||
let mut builder = HyperResponse::builder()
|
let mut builder = HyperResponse::builder()
|
||||||
.version(self.inner.version())
|
.version(self.inner.version())
|
||||||
|
@ -91,6 +92,16 @@ impl Response {
|
||||||
let body = Full::new(self.inner.body().clone());
|
let body = Full::new(self.inner.body().clone());
|
||||||
builder.body(body).expect("request was valid")
|
builder.body(body).expect("request was valid")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Takes the inner `hyper` response with its body
|
||||||
|
type modified to `Full<Bytes>` for sending.
|
||||||
|
*/
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn into_full(self) -> HyperResponse<Full<Bytes>> {
|
||||||
|
let (parts, body) = self.inner.into_parts();
|
||||||
|
HyperResponse::from_parts(parts, Full::new(body))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<ResponseConfig> for Response {
|
impl TryFrom<ResponseConfig> for Response {
|
||||||
|
|
Loading…
Add table
Reference in a new issue