Skip to content

Commit a37224b

Browse files
gumpteaufavor
authored andcommitted
add range_header_filter to proxy trait
This makes the `range_header_filter` overridable. The new default implementation is what we were doing instead of calling a hook.
1 parent 2a94183 commit a37224b

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

.bleep

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0875924524a7338c15784029df5306dd08e981dd
1+
9df2f3f6e6b919a632b08af4584a1c1a3bcee0fd

pingora-proxy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub mod subrequest;
7878

7979
use subrequest::Ctx as SubReqCtx;
8080

81+
pub use proxy_cache::range_filter::{range_header_filter, RangeType};
8182
pub use proxy_purge::PurgeStatus;
8283
pub use proxy_trait::ProxyHttp;
8384

pingora-proxy/src/proxy_cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl<SV> HttpProxy<SV> {
279279

280280
// process range header if the cache storage supports seek
281281
let range_type = if seekable && !session.ignore_downstream_range {
282-
range_header_filter(req, &mut header)
282+
self.inner.range_header_filter(req, &mut header, ctx)
283283
} else {
284284
RangeType::None
285285
};
@@ -826,7 +826,7 @@ fn cache_hit_header(cache: &HttpCache) -> Box<ResponseHeader> {
826826
}
827827

828828
// https://datatracker.ietf.org/doc/html/rfc7233#section-3
829-
pub(crate) mod range_filter {
829+
pub mod range_filter {
830830
use super::*;
831831
use http::header::*;
832832
use std::ops::Range;

pingora-proxy/src/proxy_h1.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,9 @@ impl<SV> HttpProxy<SV> {
492492
ctx,
493493
);
494494
if !session.ignore_downstream_range {
495-
let range_type = proxy_cache::range_filter::range_header_filter(
496-
session.req_header(),
497-
&mut header,
498-
);
495+
let range_type =
496+
self.inner
497+
.range_header_filter(session.req_header(), &mut header, ctx);
499498
range_body_filter.set(range_type);
500499
}
501500
}

pingora-proxy/src/proxy_h2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ impl<SV> HttpProxy<SV> {
445445
ctx,
446446
);
447447
if !session.ignore_downstream_range {
448-
let range_type =
449-
proxy_cache::range_filter::range_header_filter(req, &mut header);
448+
let range_type = self.inner.range_header_filter(req, &mut header, ctx);
450449
range_body_filter.set(range_type);
451450
}
452451
}

pingora-proxy/src/proxy_trait.rs

+18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use pingora_cache::{
1818
CacheKey, CacheMeta, ForcedInvalidationKind,
1919
RespCacheable::{self, *},
2020
};
21+
use proxy_cache::range_filter::{self};
2122
use std::time::Duration;
2223

2324
/// The interface to control the HTTP proxy
@@ -216,6 +217,23 @@ pub trait ProxyHttp {
216217
)
217218
}
218219

220+
/// This filter is called when cache is enabled to determine what byte range to return (in both
221+
/// cache hit and miss cases) from the response body. It is only used when caching is enabled,
222+
/// otherwise the upstream is responsible for any filtering. It allows users to define the range
223+
/// this request is for via its return type `range_filter::RangeType`.
224+
///
225+
/// It also allow users to modify the response header accordingly.
226+
///
227+
/// The default implementation can handle a single-range as per [RFC7232].
228+
fn range_header_filter(
229+
&self,
230+
req: &RequestHeader,
231+
resp: &mut ResponseHeader,
232+
_ctx: &mut Self::CTX,
233+
) -> range_filter::RangeType {
234+
proxy_cache::range_filter::range_header_filter(req, resp)
235+
}
236+
219237
/// Modify the request before it is sent to the upstream
220238
///
221239
/// Unlike [Self::request_filter()], this filter allows to change the request headers to send

0 commit comments

Comments
 (0)