### VCL Return with VCL Call Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/return.txt Shows how to use the 'return (vcl(...))' construct to call another VCL subroutine. This allows for modularity and reuse of VCL logic. ```vcl sub vcl_recv { return (vcl(www_vg_no)); } ``` -------------------------------- ### VCL Basic Return Methods (hit, pass) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/return.txt Demonstrates the use of basic VCL return methods like 'hit' and 'pass' within the vcl_recv subroutine. These are fundamental for Varnish request handling. ```vcl sub vcl_recv { return(hit); return(pass); } ``` -------------------------------- ### Development Setup: Build varnishls Source: https://github.com/m4r7inp/varnishls/blob/main/README.md These make commands are used during the development of varnishls. 'make tree-sitter-vcl tree-sitter-vtc' compiles the tree-sitter grammars for VCL and VTC, and 'make build' compiles the main varnishls application. ```shell make tree-sitter-vcl tree-sitter-vtc make build ``` -------------------------------- ### VCL Real-World Binary Expression Precedence Example Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/binary-expression.txt Illustrates binary expression precedence in a practical VCL scenario, checking HTTP method and URL with the AND operator. ```vcl sub vcl_recv { if (req.http.method == "GET" && req.http.url ~ "/api") { } } ``` -------------------------------- ### Setup: Unzip Varnish VCC Files Source: https://github.com/m4r7inp/varnishls/blob/main/README.md This command downloads and extracts the Varnish Compiler (VCC) files, which are necessary for varnishls to understand Varnish configurations. These files are typically placed in a specific directory for the language server to access. ```shell mkdir $HOME/.varnishls cd $HOME/.varnishls unzip varnish-vcc-files.zip ``` -------------------------------- ### Setup: Export Varnish VCC Paths Source: https://github.com/m4r7inp/varnishls/blob/main/README.md This command sets the VARNISHLS_VCC_PATHS environment variable, which informs varnishls where to find Varnish Compiler (VCC) files and VMOD definition files. Multiple paths can be specified, separated by colons. ```shell export VARNISHLS_VCC_PATHS="./lib:./vcc:/usr/share/varnish/vcc:/opt/homebrew/opt/varnish/share/varnish/vcc:$HOME/.varnishls/vcc/" ``` -------------------------------- ### Neovim: Configure Tree-sitter Grammar for VCL/VTC Source: https://github.com/m4r7inp/varnishls/blob/main/README.md This Lua configuration for Neovim's tree-sitter plugin allows for syntax highlighting of VCL and VTC files by pointing to the local tree-sitter grammar. It requires the grammar to be compiled and installed in the specified path. ```lua local parser_config = require "nvim-treesitter.parsers".get_parser_configs() for _, lang in pairs({ "vcl", "vtc" }) do parser_config[lang] = { install_info = { url = "//vendor/tree-sitter-" .. lang, files = {"src/parser.c"}, } } end ``` -------------------------------- ### VCL: HTTP Method Handling (vcl_req_method) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Validates and handles different HTTP methods. It rejects unsupported methods like 'PRI', allows standard methods, and defaults to 'pass' for methods other than GET or HEAD. ```vcl sub vcl_req_method { if (req.method == "PRI") { # This will never happen in properly formed traffic. return (synth(405)); } 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); } } ``` -------------------------------- ### Configuration Override: varnishls.toml Example Source: https://github.com/m4r7inp/varnishls/blob/main/README.md This TOML configuration file allows users to override default settings for varnishls, such as specifying the main VCL file, VMOD paths, VCC paths, and VCL paths. It also includes settings for linting rules and formatting. ```toml # .varnishls.toml in your workspace dir main_vcl = "vg/varnish.vcl" # path to the main vcl file varnish uses vmod_paths = ["/usr/lib/varnish-plus/vmods/"] # paths to directories containing your vmods (.so binaries) vcc_paths = ["/usr/src/varnish-cache/lib/"] # paths to directories containing vcc files (vmod definition files) vcl_paths = ["./", "/usr/share/varnish-plus/vcl/"] # paths to directories containing vcl (default ./) [lint] prefer_else_if = "hint" prefer_lowercase_headers = "hint" prefer_custom_headers_without_prefix = false [formatter] indent_size = 4 format_large_ifs_style = "loose" # loose or tight ``` -------------------------------- ### VCL Initialization and Finalization Functions Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt The `vcl_init` function is executed when Varnish loads a VCL configuration, and `vcl_fini` is executed when it unloads. These functions typically return 'ok' to indicate successful execution. ```vcl sub vcl_init { return (ok); } sub vcl_fini { return (ok); } ``` -------------------------------- ### Neovim: Configure varnishls LSP Client Source: https://github.com/m4r7inp/varnishls/blob/main/README.md This Lua configuration snippet sets up varnishls as a language server client in Neovim using the nvim-lspconfig plugin. It specifies the command to run varnishls, the file types it applies to, and root markers for identifying project roots. ```lua return { -- Point to varnishls (add --debug for debug log) cmd = { "varnishls", "lsp", "--stdio" }, filetypes = { "vcl", "vtc" }, root_markers = { ".varnishls.toml", ".git" }, settings = {}, } ``` -------------------------------- ### VCL Declarations and Return Statements Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt This snippet demonstrates VCL top-level and sub-declarations, including a block with a return statement using internal Varnish methods. It highlights the hierarchical structure of VCL configurations. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (ret_stmt (varnish_internal_return_methods)))))) (toplev_declaration (sub_declaration (ident) (block (stmt (ret_stmt (varnish_internal_return_methods))))))) ``` -------------------------------- ### VCL: Client Request Reception (vcl_recv) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Handles the initial reception of client requests. It calls other VCL subroutines to process the request and determines the next action, typically returning 'hash' to initiate cache lookup. ```vcl vcl 4.0; ####################################################################### # Client side sub vcl_recv { call vcl_builtin_recv; return (hash); } sub vcl_builtin_recv { call vcl_req_host; call vcl_req_method; call vcl_req_authorization; call vcl_req_cookie; } ``` -------------------------------- ### VCL Subroutine Declaration and Return Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Defines a subroutine with a block of statements and a return statement using Varnish internal methods. This is a fundamental building block for VCL logic. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (call_stmt (ident))) (stmt (ret_stmt (varnish_internal_return_methods)))))) ``` -------------------------------- ### VCL: Deliver Response Handling (vcl_deliver) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Handles the delivery of a response to the client, whether from cache or from the backend. It calls the builtin deliver subroutine. ```vcl sub vcl_deliver { call vcl_builtin_deliver; return (deliver); } sub vcl_builtin_deliver { } ``` -------------------------------- ### VCL Backend Fetch and Response Handling Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt This VCL snippet defines the main logic for fetching data from a backend server and processing the response. It includes calls to built-in functions and custom subroutines to manage cache behavior, set TTL, and handle various response conditions like uncachable content or specific headers. ```vcl sub vcl_backend_fetch { call vcl_builtin_backend_fetch; return (fetch); } sub vcl_builtin_backend_fetch { if (bereq.method == "GET") { unset bereq.body; } } sub vcl_backend_response { call vcl_builtin_backend_response; return (deliver); } sub vcl_builtin_backend_response { if (bereq.uncacheable) { return (deliver); } call vcl_beresp_stale; call vcl_beresp_cookie; call vcl_beresp_control; call vcl_beresp_vary; } sub vcl_beresp_stale { if (beresp.ttl <= 0s) { call vcl_beresp_hitmiss; } } sub vcl_beresp_cookie { if (beresp.http.Set-Cookie) { call vcl_beresp_hitmiss; } } sub vcl_beresp_control { if (beresp.http.Surrogate-control ~ "(?i)no-store" || (!beresp.http.Surrogate-Control && beresp.http.Cache-Control ~ "(?i:no-cache|no-store|private)")) { call vcl_beresp_hitmiss; } } sub vcl_beresp_vary { if (beresp.http.Vary == "*") { call vcl_beresp_hitmiss; } } sub vcl_beresp_hitmiss { set beresp.ttl = 120s; set beresp.uncacheable = true; return (deliver); } ``` -------------------------------- ### VCL Simple Binary Expression Precedence Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/binary-expression.txt Demonstrates the basic precedence of binary expressions in VCL using simple numeric comparisons with the logical OR operator. ```vcl sub vcl_recv { if (1 == 1 || 3 == 3) { } } ``` -------------------------------- ### VCL: Pass Request Handling (vcl_pass) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Handles requests that are passed directly to the backend. It calls the builtin pass subroutine and then proceeds to fetch the response. ```vcl sub vcl_pass { call vcl_builtin_pass; return (fetch); } sub vcl_builtin_pass { } ``` -------------------------------- ### Neovim: Enable varnishls and Filetype Detection Source: https://github.com/m4r7inp/varnishls/blob/main/README.md This Lua code enables the varnishls language server in Neovim and sets up filetype detection for '.vcl' and '.vtc' files. It ensures that Neovim correctly identifies and applies the language server to these file types. ```lua vim.filetype.add({ extension = { vcl = 'vcl', vtc = 'vtc' } }) vim.lsp.enable('varnishls') ``` -------------------------------- ### VCL Subroutine Declaration and Execution Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Defines a VCL subroutine with a sequence of statements, including a call to another function and a return statement. This structure is fundamental for organizing VCL logic. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (call_stmt (ident))) (COMMENT) (COMMENT) (COMMENT) (COMMENT) (COMMENT) (stmt (ret_stmt (varnish_internal_return_methods)))))) ``` -------------------------------- ### VCL Subroutine with Conditional Call and Return Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Illustrates a VCL subroutine containing a conditional call to an identifier, followed by a return statement. This pattern is useful for executing code blocks based on specific conditions. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (call_stmt (ident))) (stmt (ret_stmt (varnish_internal_return_methods)))))) ``` -------------------------------- ### Vim: Register varnishls LSP Server Source: https://github.com/m4r7inp/varnishls/blob/main/README.md This Vimscript command registers varnishls as a language server with the vim-lsp plugin. It specifies the server name, the command to execute, and the file types for which the server should be active. ```vim au User lsp_setup call lsp#register_server({ \ 'name': 'varnishls', \ 'cmd': {server_info->['/path/to/varnishls',"lsp","--stdio"]}, \ 'allowlist': ['vcl','vtc'], \ }) ``` -------------------------------- ### Emacs: Configure varnishls LSP Server with Eglot Source: https://github.com/m4r7inp/varnishls/blob/main/README.md This Emacs Lisp code configures the Eglot package to use varnishls as a language server for VCL mode. It adds the necessary program command to Eglot's server list, enabling language server features for VCL files. ```lisp (with-eval-after-load 'eglot (add-to-list 'eglot-server-programs '(vcl-mode . ("varnishls" "lsp" "--stdio")))) ``` -------------------------------- ### VCL: Authorization Header Handling (vcl_req_authorization) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Checks for the presence of an 'Authorization' header. If found, it returns 'pass' to prevent caching of the response, as authenticated content is typically not cacheable. ```vcl sub vcl_req_authorization { if (req.http.Authorization) { # Not cacheable by default. return (pass); } } ``` -------------------------------- ### VCL Return with Internal Methods, Numbers, and Strings Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Represents a VCL subroutine that returns a value constructed from Varnish internal methods, a numeric literal, and a string literal. This is often used for setting response headers or manipulating cached content. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (call_stmt (ident))) (stmt (ret_stmt (varnish_internal_return_methods (literal (number)) (literal (string)))))))) ``` -------------------------------- ### VCL Subroutine with Conditional Return Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Defines a subroutine that includes an if statement. If the condition (a nested identifier) is met, it returns using Varnish internal methods. It also includes calls to other identifiers. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (if_stmt (parenthesized_expression (nested_ident)) (block (stmt (ret_stmt (varnish_internal_return_methods)))))) (stmt (call_stmt (ident))) (stmt (call_stmt (ident))) (stmt (call_stmt (ident))) (stmt (call_stmt (ident)))))) ``` -------------------------------- ### VCL: Cache Hit Handling (vcl_hit) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Executes when a requested object is found in the Varnish cache. It calls the builtin hit subroutine and then proceeds to deliver the cached content to the client. ```vcl sub vcl_hit { call vcl_builtin_hit; return (deliver); } sub vcl_builtin_hit { } ``` -------------------------------- ### VCL: Purge Request Handling (vcl_purge) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Handles purge requests. It calls the builtin purge subroutine and then returns a synthetic 200 OK response with a 'Purged' message. ```vcl sub vcl_purge { call vcl_builtin_purge; return (synth(200, "Purged")); } sub vcl_builtin_purge { } ``` -------------------------------- ### VCL: Cache Key Generation (vcl_hash) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Generates the cache key for a request. It hashes the request URL and the Host header (if present), or the server IP if the Host header is absent. ```vcl sub vcl_hash { call vcl_builtin_hash; return (lookup); } sub vcl_builtin_hash { hash_data(req.url); if (req.http.host) { hash_data(req.http.host); } else { hash_data(server.ip); } } ``` -------------------------------- ### VCL Set Statements with Literals and Return Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Defines a subroutine that uses set statements to assign values to nested identifiers. These values can be duration literals (number and unit) or boolean literals. The subroutine concludes with a return statement. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (set_stmt (nested_ident) (literal (duration (number) (duration_unit))))) (stmt (set_stmt (nested_ident) (literal (bool)))) (stmt (ret_stmt (varnish_internal_return_methods)))))) ``` -------------------------------- ### VCL Set Statements with String Literals Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt This VCL snippet demonstrates the use of set statements to assign string literal values to nested identifiers. It shows multiple assignments of strings. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (set_stmt (nested_ident) (literal (string)))) (stmt (set_stmt (nested_ident) (literal (string)))) (stmt (set_stmt (nested_ident) (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (literal))))))))))))))))) ``` -------------------------------- ### VCL: Cache Miss Handling (vcl_miss) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Executes when a requested object is not found in the Varnish cache. It calls the builtin miss subroutine and then proceeds to fetch the object from the backend. ```vcl sub vcl_miss { call vcl_builtin_miss; return (fetch); } sub vcl_builtin_miss { } ``` -------------------------------- ### VCL Subroutine with Empty Block Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Represents a VCL subroutine declaration that contains an empty block. This might be used as a placeholder or for subroutines that do not require any specific logic. ```vcl (toplev_declaration (sub_declaration (ident) (block))) ``` -------------------------------- ### VCL: Synthetic Error Response Generation (vcl_synth) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Generates a synthetic HTML error page for responses like 500 or 503. It sets the content type, retry-after header, and constructs a basic HTML error message including the status, reason, and request XID. ```vcl # # We can come here "invisibly" with the following errors: 500 & 503 # 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.Retry-After = "5"; set resp.body = {" "} + resp.status + " " + resp.reason + {"

Error "} + resp.status + " " + resp.reason + {"

"} + resp.reason + {"

Guru Meditation:

XID: "} + req.xid + {"


Varnish cache server

"}; } ####################################################################### ``` -------------------------------- ### VCL Custom Backend Error Page Generation Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt This VCL snippet defines a custom error handling routine for backend errors. It sets specific HTTP headers (Content-Type, Retry-After) and generates a dynamic HTML error page that includes the HTTP status, reason, and a unique XID for the request. ```vcl 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.Retry-After = "5"; set beresp.body = {" "} + beresp.status + " " + beresp.reason + {"

Error "} + beresp.status + " " + beresp.reason + {"

"} + beresp.reason + {"

Guru Meditation:

XID: "} + bereq.xid + {"


Varnish cache server

"}; } ``` -------------------------------- ### VCL: Host Header Processing (vcl_req_host) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Processes the 'Host' header in client requests. It converts the Host header to lowercase and checks for its presence, returning a 400 error if it's missing for HTTP/1.1 requests without ESI. ```vcl sub vcl_req_host { if (req.http.host ~ "[[:upper:]]") { set req.http.host = req.http.host.lower(); } if (!req.http.host && req.esi_level == 0 && req.proto == "HTTP/1.1") { # In HTTP/1.1, Host is required. return (synth(400)); } } ``` -------------------------------- ### VCL Conditional Logic with Duration Literal Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Demonstrates an if statement with a complex binary expression involving nested identifiers and a duration literal (number and unit). If the condition is met, it executes a call statement. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (if_stmt (parenthesized_expression (binary_expression (nested_ident) (literal (duration (number) (duration_unit))))) (block (stmt (call_stmt (ident))))))))) ``` -------------------------------- ### VCL Conditional Function Call with Else Block Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Defines a VCL subroutine with an if-else structure that conditionally calls a function. This allows for different function executions based on whether a condition is met. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (ident_call_stmt (ident_call_expr (ident) (func_call_args (nested_ident))))) (stmt (if_stmt (parenthesized_expression (nested_ident)) (block (stmt (ident_call_stmt (ident_call_expr (ident) (func_call_args (nested_ident)))))) (else_stmt (block (stmt (ident_call_stmt (ident_call_expr (ident) (func_call_args (nested_ident)))))))))))) ``` -------------------------------- ### VCL Subroutine with Nested Function Call Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Shows a VCL subroutine that includes a nested function call with arguments. This is used for invoking functions within the VCL environment, potentially passing identifiers as arguments. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (ident_call_stmt (ident_call_expr (ident) (func_call_args (nested_ident)))))))) ``` -------------------------------- ### VCL Set Statement with Complex Expression Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Shows a VCL 'set' statement involving a deeply nested binary expression. This illustrates how VCL allows for complex computations and string concatenations to be assigned to identifiers. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (set_stmt (nested_ident) (literal (string)))) (stmt (set_stmt (nested_ident) (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (binary_expression (literal (string))) (nested_ident)) (literal (string))) (nested_ident)) (literal (string))) (nested_ident)) (literal (string))) (nested_ident)) (literal (string))) (nested_ident)) (literal (string))) (nested_ident)))))))) ``` -------------------------------- ### VCL Set Statement with String Literal Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Demonstrates a VCL 'set' statement that assigns a string literal to a nested identifier. This is a fundamental operation for configuring variables within VCL. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (set_stmt (nested_ident) (literal (string)))))))) ``` -------------------------------- ### VCL: Pipe Request Handling (vcl_pipe) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Handles requests that are piped directly to the backend without Varnish processing the response. By default, it sets 'Connection: close' to prevent connection reuse issues. ```vcl sub vcl_pipe { call vcl_builtin_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_builtin_pipe { } ``` -------------------------------- ### VCL Complex Binary Expression Precedence Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/binary-expression.txt Shows a more complex use of binary expression precedence in VCL, combining nested expressions with AND and OR operators. ```vcl sub vcl_recv { if ((req.http.method == "GET" && req.http.url == "/api") || 1 == 2) { } } ``` -------------------------------- ### VCL: Cookie Header Handling (vcl_req_cookie) Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Checks for the presence of a 'Cookie' header. If a cookie is present, it returns 'pass' to avoid caching, as responses with cookies are often personalized and not suitable for general caching. ```vcl sub vcl_req_cookie { if (req.http.Cookie) { # Risky to cache by default. return (pass); } } ``` -------------------------------- ### VCL Conditional Logic with Internal Methods Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Demonstrates an if statement within a VCL subroutine that checks a condition and returns a Varnish internal method. This is commonly used for request routing or response manipulation. ```vcl (stmt (if_stmt (parenthesized_expression (nested_ident)) (block (COMMENT) (stmt (ret_stmt (varnish_internal_return_methods)))))))) ``` -------------------------------- ### VCL Literal and Nested Identifiers Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt This snippet showcases the parsing of literal strings and nested identifiers within VCL. It represents a portion of a VCL configuration that deals with string literals and potentially nested data structures. ```vcl ((string)) (nested_ident)) (literal (string))) (nested_ident)) (literal (string))) (nested_ident)) (literal (string))) (nested_ident)) (literal (string))) (nested_ident)) (literal (string))) (nested_ident)) (literal (string)))))))) ``` -------------------------------- ### VCL Conditional Call Statement Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt An if statement that checks a binary expression between a nested identifier and a string literal. If the condition is true, it executes a call statement. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (if_stmt (parenthesized_expression (binary_expression (nested_ident) (literal (string)))) (block (stmt (call_stmt (ident))))))))) ``` -------------------------------- ### VCL Complex Conditional Expression Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt An if statement with a deeply nested binary expression involving string literals, negated expressions, and nested identifiers. If the condition evaluates to true, a call statement is executed. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (if_stmt (parenthesized_expression (binary_expression (binary_expression (nested_ident) (literal (string))) (parenthesized_expression (binary_expression (neg_expr (nested_ident)) (binary_expression (nested_ident) (literal (string))))))) (block (stmt (call_stmt (ident))))))))) ``` -------------------------------- ### VCL Conditional Logic with Unset Statement Source: https://github.com/m4r7inp/varnishls/blob/main/vendor/tree-sitter-vcl/test/corpus/builtin.txt Implements an if statement that checks a condition involving nested identifiers and string literals. If the condition is true, it executes an unset statement on a nested identifier. ```vcl (toplev_declaration (sub_declaration (ident) (block (stmt (if_stmt (parenthesized_expression (binary_expression (nested_ident) (literal (string)))) (block (stmt (unset_stmt (nested_ident))))))))) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.