Commit 3f3d67d9 authored by Guillaume Quintard's avatar Guillaume Quintard Committed by Dridi Boukelmoune

builtin: Introduce vcl_builtin_* subs

Provide a set of predictable subroutines that will be called by the
built-in vcl. Only transactional built-in subroutines are concerned,
which excludes vcl_init and vcl_fini.

Closes #3548
parent 762a52de
...@@ -36,11 +36,15 @@ vcl 4.0; ...@@ -36,11 +36,15 @@ vcl 4.0;
# Client side # Client side
sub vcl_recv { sub vcl_recv {
call vcl_builtin_recv;
return (hash);
}
sub vcl_builtin_recv {
call vcl_req_host; call vcl_req_host;
call vcl_req_method; call vcl_req_method;
call vcl_req_authorization; call vcl_req_authorization;
call vcl_req_cookie; call vcl_req_cookie;
return (hash);
} }
sub vcl_req_host { sub vcl_req_host {
...@@ -92,6 +96,7 @@ sub vcl_req_cookie { ...@@ -92,6 +96,7 @@ sub vcl_req_cookie {
} }
sub vcl_pipe { sub vcl_pipe {
call vcl_builtin_pipe;
# By default "Connection: close" is set on all piped requests, to stop # By default "Connection: close" is set on all piped requests, to stop
# connection reuse from sending future requests directly to the # connection reuse from sending future requests directly to the
# (potentially) wrong backend. If you do want this to happen, you can # (potentially) wrong backend. If you do want this to happen, you can
...@@ -100,40 +105,72 @@ sub vcl_pipe { ...@@ -100,40 +105,72 @@ sub vcl_pipe {
return (pipe); return (pipe);
} }
sub vcl_builtin_pipe {
}
sub vcl_pass { sub vcl_pass {
call vcl_builtin_pass;
return (fetch); return (fetch);
} }
sub vcl_builtin_pass {
}
sub vcl_hash { sub vcl_hash {
call vcl_builtin_hash;
return (lookup);
}
sub vcl_builtin_hash {
hash_data(req.url); hash_data(req.url);
if (req.http.host) { if (req.http.host) {
hash_data(req.http.host); hash_data(req.http.host);
} else { } else {
hash_data(server.ip); hash_data(server.ip);
} }
return (lookup);
} }
sub vcl_purge { sub vcl_purge {
call vcl_builtin_purge;
return (synth(200, "Purged")); return (synth(200, "Purged"));
} }
sub vcl_builtin_purge {
}
sub vcl_hit { sub vcl_hit {
call vcl_builtin_hit;
return (deliver); return (deliver);
} }
sub vcl_builtin_hit {
}
sub vcl_miss { sub vcl_miss {
call vcl_builtin_miss;
return (fetch); return (fetch);
} }
sub vcl_builtin_miss {
}
sub vcl_deliver { sub vcl_deliver {
call vcl_builtin_deliver;
return (deliver); return (deliver);
} }
sub vcl_builtin_deliver {
}
# #
# We can come here "invisibly" with the following errors: 500 & 503 # We can come here "invisibly" with the following errors: 500 & 503
# #
sub vcl_synth { sub vcl_synth {
call vcl_builtin_synth;
return (deliver);
}
sub vcl_builtin_synth {
set resp.http.Content-Type = "text/html; charset=utf-8"; set resp.http.Content-Type = "text/html; charset=utf-8";
set resp.http.Retry-After = "5"; set resp.http.Retry-After = "5";
set resp.body = {"<!DOCTYPE html> set resp.body = {"<!DOCTYPE html>
...@@ -151,20 +188,28 @@ sub vcl_synth { ...@@ -151,20 +188,28 @@ sub vcl_synth {
</body> </body>
</html> </html>
"}; "};
return (deliver);
} }
####################################################################### #######################################################################
# Backend Fetch # Backend Fetch
sub vcl_backend_fetch { sub vcl_backend_fetch {
call vcl_builtin_backend_fetch;
return (fetch);
}
sub vcl_builtin_backend_fetch {
if (bereq.method == "GET") { if (bereq.method == "GET") {
unset bereq.body; unset bereq.body;
} }
return (fetch);
} }
sub vcl_backend_response { sub vcl_backend_response {
call vcl_builtin_backend_response;
return (deliver);
}
sub vcl_builtin_backend_response {
if (bereq.uncacheable) { if (bereq.uncacheable) {
return (deliver); return (deliver);
} }
...@@ -172,7 +217,6 @@ sub vcl_backend_response { ...@@ -172,7 +217,6 @@ sub vcl_backend_response {
call vcl_beresp_cookie; call vcl_beresp_cookie;
call vcl_beresp_control; call vcl_beresp_control;
call vcl_beresp_vary; call vcl_beresp_vary;
return (deliver);
} }
sub vcl_beresp_stale { sub vcl_beresp_stale {
...@@ -208,6 +252,11 @@ sub vcl_beresp_hitmiss { ...@@ -208,6 +252,11 @@ sub vcl_beresp_hitmiss {
} }
sub vcl_backend_error { sub vcl_backend_error {
call vcl_builtin_backend_error;
return (deliver);
}
sub vcl_builtin_backend_error {
set beresp.http.Content-Type = "text/html; charset=utf-8"; set beresp.http.Content-Type = "text/html; charset=utf-8";
set beresp.http.Retry-After = "5"; set beresp.http.Retry-After = "5";
set beresp.body = {"<!DOCTYPE html> set beresp.body = {"<!DOCTYPE html>
...@@ -225,7 +274,6 @@ sub vcl_backend_error { ...@@ -225,7 +274,6 @@ sub vcl_backend_error {
</body> </body>
</html> </html>
"}; "};
return (deliver);
} }
####################################################################### #######################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment