LOG IN SIGN UP
Documentation

Miscellaneous VCL features

Fastly has added several miscellaneous features to Varnish that don't easily fit into specific categories.

Functions

Variables

Miscellaneous features

Feature Description
goto Performs a one-way transfer of control to another line of code. See the example for more information.
return Returns (with no return value) from a custom subroutine to exit early. See the example for more information.

Examples

Use the following examples to learn how to implement the features.

Goto

Similar to some programming languages, goto statements in VCL allow you perform a one-way transfer of control to another line of code. When using goto, jumps must always be forward, rather than to an earlier part of code.

This act of "jumping" allows you to do things like perform logical operations or set headers before returning lookup, error, or pass actions. These statements also make it easier to do things like jump to common error handling blocks before returning from a function. The goto statement works in custom subroutines.

sub vcl_recv {
  if (!req.http.Foo) {
    goto foo;
  }

foo:
  set req.http.Foo = "1";
}

Return

You can use return to exit early from a custom subroutine.

sub custom_subroutine {
  if (req.http.Cookie:user_id) {
    return;
  }

  # do a bunch of other stuff
}