Skip to content

Quantil Documentation

Built-in Variables permalink

The table below lists all the built-in variables supported by the CDN Pro servers. You can use them in Edge Logic and the real-time log. If you use the CDN Pro portal to edit the property, typing $ at a position where a variable is allowed will list all the supported variables. Some variables are Nginx native taken from the open source version of Nginx, while the other variables are CDN Pro proprietary. Most variables here are read-only. The writable ones are indicated by R/W. The variables with numerical values are tagged with #.

To use the variables properly, it is important to understand the request processing lifecycle. When Nginx processes a request, it goes through several stages. As the stages progress, Nginx variables are populated or updated dynamically. Accessing variables prematurely can lead to unexpected outcomes. For instance, upstream-related variables $upstream_* should not be accessed before a request is even passed to the upstream. Similarly, variables like $bytes_sent, $body_bytes_sent and $sc_completed, which are available only after the response is fully completed, should not be accessed before completion of the response (not even by add_header which is executed when response header is being constructed). These variables should only be accessed at log phase by custom_log_field or in realtime logs. In addition, variables like $request_time are updated continuously throughout the request lifecycle. If the variables are accessed before they are finalized, the values obtained early will differ from the ones at the request's completion.

Note: Most variables were previously also available in Load Balancer Logic. However, following the upgrade of the edge node structure, Load Balancer Logic has been deprecated. The Load Balancer Logic should no longer be used.

Variable NameDescriptionNginx Native
$arg_namequery parameter with the specified nameYes
$argsthe full query string from clientYes
$body_bytes_sent# body bytes sent to clientYes
$bytes_sent# total response bytes to clientYes
$cache_misca R/W writable variable to add parameters to the cache keyNo
$cdn_cache_statuscache status: HIT, MISS, BYPASS, EXPIRED, STALE, UPDATING, REVALIDATED.No
$client_country_codeclient’s ISO 3166 country codeNo
$client_http_versionclient's HTTP version, like "HTTP/1.1"No
$client_ip_version# client's IP version: 4 for IPv4; 6 for IPv6No
$client_ispclient's ISP informationNo
$client_province_codeclient's China province codeNo
$client_real_ipclient's IP addressNo
$connection_requests# current number of requests in the connectionYes
$content_codea R/W writable variable to assign a code to content for reporting and billing purposesNo
$content_length# request's Content-Length headerYes
$content_typerequest's Content-Type headerYes
$cookie_namecookie with the specified name received from the client. The dot character (.) is allowed in this variable name to support cookie names that contain dots. You may need to use curly braces to separate this variable from a trailing literal dot. For example: $cookie_abc.test or ${cookie_abc.test} both refer to the value of the cookie "abc.test", but ${cookie_abc}.test gives you the value of the cookie "abc" followed by the literal ".test".Yes
$cpu_time_ns# CPU time in nanoseconds(1e-9s) spent on processing the request, before transferring the response body.No
$dollar_signa literal dollar signNo
$download_time# the time in seconds from when CDN Pro receives the client request until CDN Pro sends the response body to the system buffer. The value should be equal to the sum of $request_end_time/$turn_around_time/$transfer_time. Another variable, $download_time_ms, shares the same meaning but is measured in milliseconds. The meaning of $download_time is the same as another variable, $request_time.No
$error_codeerror about client and originNo
$extra_deliver_time_ms# the estimated time in milliseconds needed to flush the TCP send buffer.No
$hosthost header, same as $http_hostYes
$hostnameserver's hostnameYes
$http_namerequest header with the specified nameYes
$http_hostrequest's Host headerYes
$ignored_body_in_cache_keyempty string when proxy_request_body_in_cache_key is off, '0' when the request body hash is included in the cache, or '1' otherwiseNo
$invalid_refererempty string if the “Referer” request header field value is considered valid; otherwise “1”Yes
$is_argsempty or "?", when query string existsYes
$msec# current Unix time in seconds with milliseconds resolutionYes
$origin_hostorigin's hostnameNo
$origin_ipIP and port of the origin. The format is IP:portNo
$origin_status_codeorigin's status codeNo
$pidprocess ID of the serviceYes
$pipe"p" if request is pipelined, or "." otherwise.Yes
$property_ver# the property version numberNo
$qtl_cpu_cycleDeprecated. Please use $cpu_time_ns instead.No
$qtl_req_idDeprecated. Please use $unique_req_id instead.No
$qtl_upstream_cache_statusDeprecated. Please use $cdn_cache_status instead.No
$random_N# A random integer uniformly distributed in [0, N-1]. N can be an integer in [2, 1e9].No
$realtime_log_ds_factor# RT log downsample factor. A value N means one log entry for every N requests. Users can use the directive realtime_log_downsample to override the default sample rate.No
$realtime_log_ds_ratio# RT log downsample ratio, the reciprocal of $realtime_log_ds_factor. The value should be a decimal number between 0 and 1.No
$remote_useruser name extracted from the Authorization header if Basic authentication is used.Yes
$requestfull HTTP request lineYes
$request_cpu_time# CPU time in nanoseconds(1e-9s) spent on processing the request, before transferring the response body. Another variable $cpu_time_ns shares the same meaning.No
$request_end_time# the time in seconds it takes to receive the request header from the client and be ready to process or forward it. Another variable request_end_time_ms shares the same meaning but in milliseconds.No
$request_length# length of request line, header and bodyYes
$request_methodHTTP method: GET, POST, etc.Yes
$request_scheme"http" or "https"No
$request_ssl_handshake_time# CPU time, in nanoseconds, spent on TLS handshakeNo
$request_start_time# the Unix time (in seconds with milliseconds resolution) when the first byte of the request is received from the client.No
$request_time# request processing time in seconds with a milliseconds resolution; time elapsed since the first bytes were read from the client. The value is equal to the sum of the values of 3 variables: $request_end_time, $turn_around_time and $transfer_time. When the request and response sizes are small, $request_end_time and $transfer_time may be 0 and $request_time may have the same value as $turn_around_time.Yes
$request_urirequest URI from the client, beginning with '/' and including the query stringYes
$sc_completed# Value is 1 if the last byte was served to the client; 0 otherwise.No
$sc_initial# Value is 1 if the first byte was served to the client; 0 otherwise.No
$sec# current Unix time in integer secondsNo
$sent_http_nameheader with the specified name sent to clientYes
$sent_http_content_length# Content-Length to clientYes
$sent_http_content_typeContent-Type to clientYes
$served_from_cache# Value is 1 for a HIT on edge; 0 for a MISS.No
$server_addrIP address of the edge serverYes
$server_level# Level of the cache server. 1 means edge, and 2 means intermediate.No
$server_nameThe value specified in the property's hostnames that matched the incoming request.Yes
$server_regionCountry code of the edge server, e.g. CN, USNo
$server_province_codeThe edge server's China province codeNo
$server_protocolHTTP/1.1, HTTP/2.0 or HTTP/3.0Yes
$service_port# port number that received the requestNo
$sorted_querystring_argsvariable providing an ASCII-based sorted list of input query parameters; it can be modified by the "sorted_querystring_filter_parameter" directiveNo
$ssl_cipherTLS cipher suite usedYes
$ssl_client_escaped_certclient certificate in PEM format (urlencoded)Yes
$ssl_client_fingerprintSHA1 fingerprint of the client certificateYes
$ssl_client_i_dn"issuer DN" string of the client certificateYes
$ssl_client_raw_certclient certificate in PEM formatYes
$ssl_client_s_dn"subject DN" string of the client certificateYes
$ssl_client_serialserial number of the client certificateYes
$ssl_client_v_endend date of the client certificateYes
$ssl_client_v_remain# the number of days until the client certificate expiresYes
$ssl_client_v_startstart date of the client certificateYes
$ssl_client_verifyresult of client certificate verificationYes
$ssl_protocolreturns protocol name like "TLSv1.1"Yes
$ssl_server_nameTLS SNI servernameYes
$statusHTTP status code to clientYes
$tcpinfo_delivery_rate# the rate, in bytes/s, at which the sent data is acknowledged by the client.No
$tcpinfo_min_rtt# minimum RTT, in microseconds, observed by TCP stack for the connectionNo
$tcpinfo_rtt# latest RTT, in microseconds, observed by TCP stack for the connectionYes
$time_httpcurrent time in RFC 7231 format that can be used for HTTP Date headerNo
$transfer_time# the time needed for CDN Pro to send the full requested object ( up to last byte ) to system buffer, in seconds. Another variable transfer_time_ms shares the same meaning but in milliseconds.No
$turn_around_time# the time needed for CDN Pro to receive first byte of response of origin, in seconds. Another variable turn_around_time_ms shares the same meaning but in milliseconds.No
$unique_req_ida unique ID for the requestNo
$upstream_bytes_received# number of bytes received from a parent or origin serverYes
$upstream_bytes_sent# number of bytes sent to a parent or origin serverYes
$upstream_connect_time# time spent in seconds with millisecond resolution establishing a connection with a parent or origin serverYes
$upstream_cookie_namecookie with the specified name received from the upstream server in the “Set-Cookie” response header field. May be served from the cache. The dot character (.) is allowed in this variable name to support cookie names that contain dots. You may need to use curly braces to separate this variable from a trailing literal dot. For example: $upstream_cookie_abc.test or ${upstream_cookie_abc.test} both refer to the value of the cookie "abc.test", but ${upstream_cookie_abc}.test gives you the value of the cookie "abc" followed by the literal ".test".Yes
$upstream_header_time# time spent in seconds with millisecond resolution receiving the response header from a parent or origin serverYes
$upstream_http_nameheader with the specified name received from the upstream server. May be served from the cache.Yes
$upstream_response_statusstatus code from a parent or origin server. Value will be 0 for a cache HIT.No
$upstream_response_time# time spent in seconds with millisecond resolution receiving the complete response from a parent or origin serverYes
$upstream_server_type'O' for origin server; 'C' for parent cache server.No
$upstream_trailer_nametrailer with the specified name passed from the Edge Logic with the add_trailer directive. This variable is deprecated.Yes
$urinormalized request URI beginning with '/' and excluding the query string. The value may be modified by the "rewrite" directive in the Edge Logic.Yes