From a261f983c1eb12e51386b602b3e98a19c23eaa90 Mon Sep 17 00:00:00 2001 From: Jose Antonio Delgado Alfonso Date: Wed, 8 May 2024 14:55:31 +0200 Subject: [PATCH] chore: make function upstream_response_body_filter async --- pingora-proxy/src/lib.rs | 12 +++++++----- pingora-proxy/src/proxy_h1.rs | 2 +- pingora-proxy/src/proxy_h2.rs | 2 +- pingora-proxy/src/proxy_trait.rs | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pingora-proxy/src/lib.rs b/pingora-proxy/src/lib.rs index 268a927f..d52edbf2 100644 --- a/pingora-proxy/src/lib.rs +++ b/pingora-proxy/src/lib.rs @@ -224,22 +224,24 @@ impl HttpProxy { } } - fn upstream_filter( + async fn upstream_filter( &self, session: &mut Session, task: &mut HttpTask, ctx: &mut SV::CTX, ) -> Result<()> where - SV: ProxyHttp, + SV: ProxyHttp + Send + Sync, { match task { HttpTask::Header(header, _eos) => { self.inner.upstream_response_filter(session, header, ctx) } - HttpTask::Body(data, eos) => self - .inner - .upstream_response_body_filter(session, data, *eos, ctx), + HttpTask::Body(data, eos) => { + self.inner + .upstream_response_body_filter(session, data, *eos, ctx) + .await + } HttpTask::Trailer(Some(trailers)) => self .inner .upstream_response_trailer_filter(session, trailers, ctx)?, diff --git a/pingora-proxy/src/proxy_h1.rs b/pingora-proxy/src/proxy_h1.rs index b53fa86f..715b8f66 100644 --- a/pingora-proxy/src/proxy_h1.rs +++ b/pingora-proxy/src/proxy_h1.rs @@ -693,7 +693,7 @@ impl HttpProxy { { // skip caching if already served from cache if !from_cache { - self.upstream_filter(session, &mut task, ctx)?; + self.upstream_filter(session, &mut task, ctx).await?; // cache the original response before any downstream transformation // requests that bypassed cache still need to run filters to see if the response has become cacheable diff --git a/pingora-proxy/src/proxy_h2.rs b/pingora-proxy/src/proxy_h2.rs index 8f0dffac..97937224 100644 --- a/pingora-proxy/src/proxy_h2.rs +++ b/pingora-proxy/src/proxy_h2.rs @@ -381,7 +381,7 @@ impl HttpProxy { SV::CTX: Send + Sync, { if !from_cache { - self.upstream_filter(session, &mut task, ctx)?; + self.upstream_filter(session, &mut task, ctx).await?; // cache the original response before any downstream transformation // requests that bypassed cache still need to run filters to see if the response has become cacheable diff --git a/pingora-proxy/src/proxy_trait.rs b/pingora-proxy/src/proxy_trait.rs index fba2bd63..5aa101a1 100644 --- a/pingora-proxy/src/proxy_trait.rs +++ b/pingora-proxy/src/proxy_trait.rs @@ -223,7 +223,7 @@ pub trait ProxyHttp { /// /// This function will be called every time a piece of response body is received. The `body` is /// **not the entire response body**. - fn upstream_response_body_filter( + async fn upstream_response_body_filter( &self, _session: &mut Session, _body: &mut Option,