[master] 4646a5bd7 builtin: Adopt our C code style for the builtin VCL

Nils Goroll nils.goroll at uplex.de
Wed Mar 3 10:15:04 UTC 2021


commit 4646a5bd77bd21aa330a5598016655f56dc7c38e
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Jan 26 11:04:42 2021 +0100

    builtin: Adopt our C code style for the builtin VCL
    
    I removed the else keyword from vcl_backend_response because it doesn't
    add any value.
    
    Better diff with the --ignore-all-space option.

diff --git a/bin/varnishd/builtin.vcl b/bin/varnishd/builtin.vcl
index d0be8021f..3fee28f52 100644
--- a/bin/varnishd/builtin.vcl
+++ b/bin/varnishd/builtin.vcl
@@ -36,88 +36,88 @@ vcl 4.0;
 # Client side
 
 sub vcl_recv {
-    if (req.http.host) {
-        set req.http.host = req.http.host.lower();
-    }
-    if (req.method == "PRI") {
-        # This will never happen in properly formed traffic (see: RFC7540)
-        return (synth(405));
-    }
-    if (!req.http.host &&
-      req.esi_level == 0 &&
-      req.proto ~ "^(?i)HTTP/1.1") {
-        # In HTTP/1.1, Host is required.
-        return (synth(400));
-    }
-    if (req.method != "GET" &&
-      req.method != "HEAD" &&
-      req.method != "PUT" &&
-      req.method != "POST" &&
-      req.method != "TRACE" &&
-      req.method != "OPTIONS" &&
-      req.method != "DELETE" &&
-      req.method != "PATCH") {
-        # Non-RFC2616 or CONNECT which is weird.
-        return (pipe);
-    }
-
-    if (req.method != "GET" && req.method != "HEAD") {
-        # We only deal with GET and HEAD by default
-        return (pass);
-    }
-    if (req.http.Authorization || req.http.Cookie) {
-        # Not cacheable by default
-        return (pass);
-    }
-    return (hash);
+	if (req.http.host) {
+		set req.http.host = req.http.host.lower();
+	}
+	if (req.method == "PRI") {
+		# This will never happen in properly formed traffic (see: RFC7540)
+		return (synth(405));
+	}
+	if (!req.http.host &&
+	    req.esi_level == 0 &&
+	    req.proto ~ "^(?i)HTTP/1.1") {
+		# In HTTP/1.1, Host is required.
+		return (synth(400));
+	}
+	if (req.method != "GET" &&
+	    req.method != "HEAD" &&
+	    req.method != "PUT" &&
+	    req.method != "POST" &&
+	    req.method != "TRACE" &&
+	    req.method != "OPTIONS" &&
+	    req.method != "DELETE" &&
+	    req.method != "PATCH") {
+		# Non-RFC2616 or CONNECT which is weird.
+		return (pipe);
+	}
+
+	if (req.method != "GET" && req.method != "HEAD") {
+		# We only deal with GET and HEAD by default
+		return (pass);
+	}
+	if (req.http.Authorization || req.http.Cookie) {
+		# Not cacheable by default
+		return (pass);
+	}
+	return (hash);
 }
 
 sub vcl_pipe {
-    # By default Connection: close is set on all piped requests, to stop
-    # connection reuse from sending future requests directly to the
-    # (potentially) wrong backend. If you do want this to happen, you can undo
-    # it here.
-    # unset bereq.http.connection;
-    return (pipe);
+	# By default "Connection: close" is set on all piped requests, to stop
+	# connection reuse from sending future requests directly to the
+	# (potentially) wrong backend. If you do want this to happen, you can
+	# undo it here:
+	# unset bereq.http.connection;
+	return (pipe);
 }
 
 sub vcl_pass {
-    return (fetch);
+	return (fetch);
 }
 
 sub vcl_hash {
-    hash_data(req.url);
-    if (req.http.host) {
-        hash_data(req.http.host);
-    } else {
-        hash_data(server.ip);
-    }
-    return (lookup);
+	hash_data(req.url);
+	if (req.http.host) {
+		hash_data(req.http.host);
+	} else {
+		hash_data(server.ip);
+	}
+	return (lookup);
 }
 
 sub vcl_purge {
-    return (synth(200, "Purged"));
+	return (synth(200, "Purged"));
 }
 
 sub vcl_hit {
-    return (deliver);
+	return (deliver);
 }
 
 sub vcl_miss {
-    return (fetch);
+	return (fetch);
 }
 
 sub vcl_deliver {
-    return (deliver);
+	return (deliver);
 }
 
 #
 # We can come here "invisibly" with the following errors: 500 & 503
 #
 sub vcl_synth {
-    set resp.http.Content-Type = "text/html; charset=utf-8";
-    set resp.http.Retry-After = "5";
-    set resp.body = {"<!DOCTYPE html>
+	set resp.http.Content-Type = "text/html; charset=utf-8";
+	set resp.http.Retry-After = "5";
+	set resp.body = {"<!DOCTYPE html>
 <html>
   <head>
     <title>"} + resp.status + " " + resp.reason + {"</title>
@@ -132,39 +132,40 @@ sub vcl_synth {
   </body>
 </html>
 "};
-    return (deliver);
+	return (deliver);
 }
 
 #######################################################################
 # Backend Fetch
 
 sub vcl_backend_fetch {
-    if (bereq.method == "GET") {
-        unset bereq.body;
-    }
-    return (fetch);
+	if (bereq.method == "GET") {
+		unset bereq.body;
+	}
+	return (fetch);
 }
 
 sub vcl_backend_response {
-    if (bereq.uncacheable) {
-        return (deliver);
-    } else if (beresp.ttl <= 0s ||
-      beresp.http.Set-Cookie ||
-      beresp.http.Surrogate-control ~ "(?i)no-store" ||
-      (!beresp.http.Surrogate-Control &&
-        beresp.http.Cache-Control ~ "(?i:no-cache|no-store|private)") ||
-      beresp.http.Vary == "*") {
-        # Mark as "Hit-For-Miss" for the next 2 minutes
-        set beresp.ttl = 120s;
-        set beresp.uncacheable = true;
-    }
-    return (deliver);
+	if (bereq.uncacheable) {
+		return (deliver);
+	}
+	if (beresp.ttl <= 0s ||
+	    beresp.http.Set-Cookie ||
+	    beresp.http.Surrogate-control ~ "(?i)no-store" ||
+	    (!beresp.http.Surrogate-Control &&
+	      beresp.http.Cache-Control ~ "(?i:no-cache|no-store|private)") ||
+	    beresp.http.Vary == "*") {
+		# Mark as "Hit-For-Miss" for the next 2 minutes
+		set beresp.ttl = 120s;
+		set beresp.uncacheable = true;
+	}
+	return (deliver);
 }
 
 sub vcl_backend_error {
-    set beresp.http.Content-Type = "text/html; charset=utf-8";
-    set beresp.http.Retry-After = "5";
-    set beresp.body = {"<!DOCTYPE html>
+	set beresp.http.Content-Type = "text/html; charset=utf-8";
+	set beresp.http.Retry-After = "5";
+	set beresp.body = {"<!DOCTYPE html>
 <html>
   <head>
     <title>"} + beresp.status + " " + beresp.reason + {"</title>
@@ -179,16 +180,16 @@ sub vcl_backend_error {
   </body>
 </html>
 "};
-    return (deliver);
+	return (deliver);
 }
 
 #######################################################################
 # Housekeeping
 
 sub vcl_init {
-    return (ok);
+	return (ok);
 }
 
 sub vcl_fini {
-    return (ok);
+	return (ok);
 }


More information about the varnish-commit mailing list