This topic describes the syntax, features, parameters, and return values of request logic functions. This topic also provides examples of these functions.
server_addr
| Item | Description |
| Syntax | server_addr() |
| Parameters | None |
| Examples | |
| Return value | Returns the IP addresses of the servers in a string. |
server_port
| Item | Description |
| Syntax | server_port() |
| Parameters | None |
| Examples | |
| Return value | Returns the server port that receives the current request. Data type: numeric. |
client_addr
| Item | Description |
| Syntax | client_addr() |
| Parameters | None |
| Examples | |
| Return value | Returns the IP address of the specified client in a string. |
client_port
| Item | Description |
| Syntax | client_port() |
| Parameters | None |
| Examples | |
| Return value | Returns the port of the specified client. Data type: numeric. |
client_region
This function queries the administrative division code of a client. The following table describes the details about this function.
Item | Description |
Syntax | client_region() |
Parameter | None |
Examples | |
Return values | Returns the administrative division code of the specified client in a string. For more information about administrative division codes, see Administrative division codes of prefectural-level subdivisions of China. |
client_isp
The return value may not be accurate because the client address may be changed by the NAT rules of the Internet service provider (ISP) or the IP address is not in the address pool of Alibaba Cloud CDN. Proceed with caution.
This function queries the ISP code of a client. The following table describes the details about this function.
Item | Description |
Syntax | client_isp() |
Parameter | None |
Examples | |
Return values | Returns the ISP code of the specified client in a string. For more information about ISP codes, see ISP codes. |
ip_region
The return value may not be accurate because the client address may be changed by the NAT rules of the Internet service provider (ISP) or the IP address is not in the address pool of Alibaba Cloud CDN. Proceed with caution.
This function queries the administrative division code of the city or province to which a specified IP address belongs. The following table describes the details about this function.
Item | Description |
Syntax | ip_region(ipaddr) |
Parameter | ipaddr: specifies an IP address in dotted decimal notation. |
Examples | |
Return values | Returns the administrative division code of the city or province to which the specified IP address belongs in a string. For more information about region codes, see Administrative division codes of prefectural-level subdivisions of China. |
ip_isp
The return value may not be accurate because the client address may be changed by the NAT rules of the Internet service provider (ISP) or the IP address is not in the address pool of Alibaba Cloud CDN. Proceed with caution.
This function queries the ISP code of a specified IP address. The following table describes the details about this function.
Item | Description |
Syntax | ip_isp(ipaddr) |
Parameter | ipaddr: specifies an IP address in dotted decimal notation. |
Examples | |
Return values | Returns the ISP code of the specified IP address in a string. For more information about ISP codes, see ISP codes. |
req_uri
- If the pattern parameter is not included in the request, the URI of the request is returned, excluding the parameters.
- If the pattern parameter is included in the request, the URI of the request is compared with the match conditions.
| Item | Description |
| Syntax | req_uri([pattern]) |
| Parameters | pattern: compared with the match conditions. The following match types are supported:
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_uri_basename
- Returns the file name in the request URI if the pattern parameter is not included in the request.
- Compares the file name in the request URI with the match conditions if the pattern parameter is included in the request.
- Example 1: For /document_detail/30360.html, the file name is 30360.
- Example 2: For /M604/guopei_mp4/ZYJY2017BJGL0101/2-1_g.mp4, the file name is 2-1_g.
- Example 3: For /tarball/foo.tar.bz2, the file name is foo.
| Item | Description |
| Syntax | req_uri_basename([pattern]) |
| Parameters | pattern: compared with the match conditions. The following match types are supported:
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_uri_ext
- Returns the extension in the request URI if the pattern parameter is not included in the request.
- Compares the extension in the request URI with the match conditions if the pattern parameter is included in the request.
- Example 1: For /document_detail/30360.html, the extension is .html.
- Example 2: For /M604/guopei_mp4/ZYJY2017BJGL0101/2-1_g.mp4, the extension is .mp4.
- Example 3: For /tarball/foo.tar.bz2, the extension is .tar.bz2.
| Item | Description |
| Syntax | req_uri_ext([pattern]) |
| Parameters | pattern: compared with the match conditions. The following match types are supported:
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_uri_seg
- In response parameters, the segments are separated by forward slashes (/).
- Returns all segments if the idx parameter is not included in the request.
- Returns the segments (including the index) that follow the specified index if the idx parameter is included in the request.
- Indexes for paragraphs: the index starts from 1 and increases from the leftmost index when more paragraphs are added.
- Paragraph limit: A paragraph can contain up to 128 characters. Characters that exceed this limit are dropped.
| Item | Description |
| Syntax | req_uri_seg([idx]) |
| Parameters | idx: specifies the start index. This parameter is optional. |
| Examples | |
| Return value | Data type: dictionary. The relevant paragraphs are included. Note When the function retrieves the paragraph from the returned dictionary based on the specified index, the function checks whether the paragraph is empty. In this example, the following values are returned: |
req_uri_arg
| Item | Description |
| Syntax | req_uri_arg(name, [pattern]) |
| Parameters |
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_uri_query_string
- If the pattern parameter is not included in the request, the parameters in the request are returned, excluding the question mark (?).
- If the pattern parameter is included in the request, the parameters in the requests are compared with the match conditions.
| Item | Description |
| Syntax | req_uri_query_string([pattern]) |
| Parameters | pattern: compared with the match conditions. The following match types are supported:
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_scheme
- Returns the request scheme if the pattern parameter is not included in the request.
- Compares the request scheme with the match conditions if the pattern parameter is included in the request.
| Item | Description |
| Syntax | req_scheme([pattern]) |
| Parameters | pattern: compared with the match conditions. The following match types are supported:
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_method
- Returns the request method if the pattern parameter is not included in the request.
- Compares the request method with the match conditions if the pattern parameter is included in the request.
| Item | Description |
| Syntax | req_method([pattern]) |
| Parameters | pattern: compared with the match conditions. The following match types are supported:
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_host
- Returns the value of the Host request header if the pattern parameter is not included in the request.
- Compares the value of the Host request header with the match conditions if the pattern parameter is included in the request.
| Item | Description |
| Syntax | req_host([pattern]) |
| Parameters | pattern: compared with the match conditions. The following match types are supported:
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_user_agent
- Returns the value of the User-Agent request header if the pattern parameter is not included in the request.
- Compares the value of the User-Agent request header with the match conditions if the pattern parameter is included in the request.
| Item | Description |
| Syntax | req_user_agent([pattern]) |
| Parameters | pattern: compared with the match conditions. The following match types are supported:
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_referer
- Returns the value of the Referer request header if the pattern parameter is not included in the request.
- Compares the value of the Referer request header with the match conditions if the pattern parameter is included in the request.
| Item | Description |
| Syntax | req_referer([pattern]) |
| Parameters | pattern: compared with the match conditions. The following match types are supported:
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_cookie
| Item | Description |
| Syntax | req_cookie(name, [pattern]) |
| Parameters |
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_first_x_forwarded
- Returns the first address in the X-Forwarded-For request header if the pattern parameter is not included in the request.
- Compares the first address in the X-Forwarded-For request header with the match conditions if the pattern parameter is included in the request.
| Item | Description |
| Syntax | req_first_x_forwarded_addr([pattern]) |
| Parameters | pattern: compared with the match conditions. The following match types are supported:
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_header
| Item | Description |
| Syntax | req_header(name, [pattern]) |
| Parameters |
|
| Examples | |
| Return value |
In this example, the following values are returned: |
req_id
| Item | Description |
| Syntax | req_id() |
| Parameters | None |
| Examples | |
| Return value | Returns the request ID in a string. In this example, the ID of the request is req_id: 6451c43d15815890089411000e. |