diff options
author | Edward Wang <[email protected]> | 2024-10-11 13:44:39 -0700 |
---|---|---|
committer | Kevin Guthrie <[email protected]> | 2024-10-28 11:51:38 -0400 |
commit | 1db55fc5f6d5fa3e61a5ceb8263e4aee66649fa9 (patch) | |
tree | 6c338c7242ae0022450c608dc7f6507de3369731 | |
parent | 04d7cfeef6205d2cf33ad5704a363ee107250771 (diff) | |
download | pingora-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-- | .bleep | 2 | ||||
-rw-r--r-- | pingora-proxy/src/proxy_cache.rs | 18 |
2 files changed, 18 insertions, 2 deletions
@@ -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 |