From 1db55fc5f6d5fa3e61a5ceb8263e4aee66649fa9 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Fri, 11 Oct 2024 13:44:39 -0700 Subject: 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. --- .bleep | 2 +- pingora-proxy/src/proxy_cache.rs | 18 +++++++++++++++++- 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 HttpProxy { } 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 -- cgit v1.2.3