aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEdward Wang <[email protected]>2024-10-11 13:44:39 -0700
committerKevin Guthrie <[email protected]>2024-10-28 11:51:38 -0400
commit1db55fc5f6d5fa3e61a5ceb8263e4aee66649fa9 (patch)
tree6c338c7242ae0022450c608dc7f6507de3369731
parent04d7cfeef6205d2cf33ad5704a363ee107250771 (diff)
downloadpingora-1db55fc5f6d5fa3e61a5ceb8263e4aee66649fa9.tar.gz
pingora-1db55fc5f6d5fa3e61a5ceb8263e4aee66649fa9.zip
Apply response_body_filter when serving from cache
Previously the response header filter was applied when serving from cache (using `proxy_cache_hit`), but not the response body filter.
-rw-r--r--.bleep2
-rw-r--r--pingora-proxy/src/proxy_cache.rs18
2 files changed, 18 insertions, 2 deletions
diff --git a/.bleep b/.bleep
index 0c316c3..6c2c495 100644
--- a/.bleep
+++ b/.bleep
@@ -1 +1 @@
-a4032182c556d6fee5f22d0b56b99b03c8fc6868 \ No newline at end of file
+c9b2323f5cb8843bd0c24c82df577cd7a419ff6d \ No newline at end of file
diff --git a/pingora-proxy/src/proxy_cache.rs b/pingora-proxy/src/proxy_cache.rs
index 77b7384..e9914cf 100644
--- a/pingora-proxy/src/proxy_cache.rs
+++ b/pingora-proxy/src/proxy_cache.rs
@@ -309,7 +309,23 @@ impl<SV> HttpProxy<SV> {
}
loop {
match session.cache.hit_handler().read_body().await {
- Ok(body) => {
+ Ok(mut body) => {
+ let end = body.is_none();
+ match self
+ .inner
+ .response_body_filter(session, &mut body, end, ctx)
+ {
+ Ok(Some(duration)) => {
+ trace!("delaying response for {duration:?}");
+ time::sleep(duration).await;
+ }
+ Ok(None) => { /* continue */ }
+ Err(e) => {
+ // body is being sent, don't treat downstream as reusable
+ return (false, Some(e));
+ }
+ }
+
if let Some(b) = body {
// write to downstream
if let Err(e) = session