For the complete documentation index, see llms.txt. This page is also available as Markdown.

Callable Functions

Subroutines to handle requests

Overview

These functions enhance the functionality of handling HTTP requests in various ways, including automatically redirecting to HTTPS, denying requests or bypassing cache.

NOTE: Deprecated TCDN-Command Header

Previously, tasks were triggered using the HTTP header TCDN-Command. For example:

  • Redirect HTTP to HTTPS: set req.http.TCDN-Command = "redirect_https";

  • Deny a request with a 403 error: set req.http.TCDN-Command = "deny_request";

  • Bypass the cache: set req.http.TCDN-Command = "pass";

  • Apply rate limit: set req.http.TCDN-Command = "limit_rate:<key>:<limit>:<period>[:<block>][:captcha]";

However, this method had drawbacks, such as the risk of the header being overwritten later in the VCL code, leading to bugs.

Available Functions

Deny Request

  • Command: call deny_request;

  • Description: Immediately blocks the request and returns a 403 error. However, certain requests may bypass this block, as described below.

  • Example:

The deny_request command does not override requests that have been explicitly whitelisted or otherwise exempted. For example, requests originating from trusted Googlebot IP ranges may bypass the block.

You can explicitly mark a request as whitelisted by setting tcdn-whitelisted-ip:

Setting tcdn-whitelisted-ip to true marks the request as unblockable and unchallengeable. This also allows the request to bypass Under Attack mode.

Force Deny Request

  • Command: call force_deny_request;

  • Description: Immediately blocks the request and returns a 403 error, regardless of whitelisting or other request exemptions.

  • Example:

Respond 4xx

  • Command: call respond_4xx;

  • Description: The respond_4xx commands return specific HTTP client error responses.

  • Supported responses:

Command
HTTP Status
Reason

call respond_400;

400

Bad Request

call respond_401;

401

Unauthorized

call respond_403;

403

Forbidden

call respond_404;

404

Not Found

call respond_410;

410

Gone

  • Example:

Redirect HTTP to HTTPS

  • Command: call redirect_https;

  • Description: Redirects HTTP requests to HTTPS.

  • Example:

Bypass Cache

  • Command: call bypass_cache;

  • Description: Bypasses/ignores the cache for the current request for both level 1 and level 2 cache (midtier).

  • Example:

Redirect Request

  • Command: call redirect_request;

  • Description: Redirects a request to a specified URL with the given status code. It requires setting a header, req.http.tcdn-location, before the call. The value of this header must follow the format <status_code>, <URL>.

  • Example:

Apply Rate Limit

  • Command: call rate_limit;

  • Description: Applies the rate limit specified, <limit> / <period> , for each <key>. If exceeded, a 429 (Too Many Requests) status code is returned during the <block> time indicated.

  • Example:

Under Attack Mode

  • Command: call under_attack;

  • Description: Enables Under Attack Mode conditionally, allowing to target only a particular URL or any other condition instead of the whole domain.

  • Example:

Show Captcha

  • Command: call show_captcha;

  • Description: This command triggers the display of a CAPTCHA to verify that incoming traffic is from human users.

  • Example:

Show JSChallenge

  • Command: call show_jschallenge;

  • Description: This command initiates an automated JavaScript challenge to verify that incoming traffic originates from consumer browsers and not from automated or other tools. Unlike a CAPTCHA, this challenge is unassisted, meaning the user does not need to perform any actions for the verification to occur.

  • Example:

Last updated

Was this helpful?