cloudflare / cloudflare/pingora
Enable Pigora HttpServer Apps to stream Http Body.
- Dominant language
- Rust
- Stars
- 27.4k
- Forks
- 1.7k
- Avg merge
- 6h 22m
- Merged PRs (30d)
- 3
Description
## What is the problem your feature solves, or the need it fulfills?
Current implementation of ServeHttp has the Limitation that body cannot be streamed. This imposes a limitation for applications that need to stream a huge amount of data, or connect to other APIs that streams data.
Check: https://github.com/cloudflare/pingora/blob/main/pingora-core/src/apps/http_app.rs#L37
## Describe the solution you'd like
I'm proposing make the HttpServer trait more flexible by introducing an associate type to representing the Body type which would allow HttpServer developer come up with the type that better suit its application:
```
pub trait HttpBody: Send + Sync {
fn is_full_body(&self) -> bool;
async fn next_chunk(&mut self) -> pingora::Result>;
}
#[async_trait]
pub trait ServeHttp {
type BODY: HttpBody;
async fn response(&self, http_session: &mut ServerSession) -> Response;
}
```
I actually have this implemented on our project, and have some spare time to work on a PR.
Contributor guide
Assessment
This issue has not been assessed yet.