Check body length in VCL
T. Pascal
t_pascal at zennet.com
Wed Aug 11 20:11:32 CEST 2010
It is sometimes useful to use the following rule to make decisions in VCL,
based on Content-Length:
vcl_fetch() {
# Cache objects larger than 3000 bytes
if ((beresp.status == 200) && (beresp.http.Content-Length ~
"^([3-9]|\d\d)\d\d\d")) {
set beresp.ttl = 10d;
} else {
set beresp.ttl = 10m;
} }
The use case is an XML feed that we heuristically know is "well formed" if
it's more then 3K; if the response is shorter, it often means the result set
was empty for whatever reason (even if it's an HTTP-200 response), so we
cache the short requests for a small time until the full result is ready and
then cache it for a long time.
This is a horrible hack that works fine, until we get some chunked responses
and the above regexp fails.
So I would prefer:
if ((beresp.status == 200) && (length(body) > 3000)) {
# Cache a long time
}
Does this exist without in-line C, is it a valuable feature, etc. so forth?
-T.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20100811/a7c59fd4/attachment-0003.html>
More information about the varnish-dev
mailing list