This topic describes the syntax, features, parameters, and return values of request processing functions. This topic also provides examples of these functions.
add_req_header | del_req_header | add_rsp_header | del_rsp_header | encode_args | decode_args | rewrite | say | print | exit
add_req_header
Item | Description |
---|---|
Syntax | add_req_header(name, value [, append])
|
Feature | Adds a request header to requests before they are redirected to the origin server. |
Parameter |
|
Return value | true is returned by default. If the specified request header is invalid, false is returned.
|
Example | Request headers:
Note The
USER-DEFINED-REQ-2 header is added and then deleted. Therefore, the USER-DEFINED-REQ-2 header is not included in the responses.
|
del_req_header
Item | Description |
---|---|
Syntax | del_req_header(name)
|
Feature | Deletes a request header from requests before they are redirected to the origin server. |
Parameter | name : the name of the request header that you want to delete. Data type: string.
|
Return value | true is returned by default. If the specified request header is invalid, false is returned.
|
Example | Headers:
Note The
USER-DEFINED-REQ-2 header is added and then deleted. Therefore, the USER-DEFINED-REQ-2 header is not included in the responses.
|
add_rsp_header
Item | Description |
---|---|
Syntax | add_rsp_header(name, value [, append])
|
Feature | Adds a response header. |
Parameter |
|
Return value | true is returned by default. If the specified response header is invalid, false is returned.
|
Example | Response headers:
Note The
USER-DEFINED-RSP-2 header is added and then deleted. Therefore, the USER-DEFINED-RSP-2 header is not included in the responses.
|
del_rsp_header
Item | Description |
---|---|
Syntax | del_rsp_header(name)
|
Feature | Deletes a response header. |
Parameter | name : the name of the response header that you want to delete. Data type: string.
|
Return value | true is returned by default. If the specified response header is invalid, false is returned.
|
Example | Response headers:
Note The
USER-DEFINED-RSP-2 header is added and then deleted. Therefore, the USER-DEFINED-RSP-2 header is not included in the responses.
|
encode_args
Item | Description |
---|---|
Syntax | encode_args(d)
|
Feature | Converts the key-value pair in the dictionary specified by d to a URI-encoded string in the format of k1=v1&k2=v2 .
|
Parameter | d: the dictionary that you want to convert. |
Return value | A URI-encoded string. |
Example | Response headers:
|
decode_args
Item | Description |
---|---|
Syntax | decode_args(s)
|
Feature | Converts a URI-encoded string in the format of k1=v1&k2=v2 to a string of dictionary type.
|
Parameter | s: the string that you want to convert. |
Return value | A dictionary object converted from the specified string. |
Example | Response headers:
|
rewrite
Item | Description |
---|---|
Syntax | rewrite(url, flag, code)
|
Feature | Performs a rewrite or redirect. |
Parameter |
|
Return value |
|
Example |
|
say
Item | Description |
---|---|
Syntax | say(arg)
|
Feature | Prints a response body and appends a newline character at the end of the output. |
Parameter | arg: the content of the response body. Data type: any type. |
Return value | N/A |
Example | Output:
|
Item | Description |
---|---|
Syntax | print(arg)
|
Feature | Prints a response body. This function is different from the say() function. This function does not append a newline at the end of the output.
|
Parameter | arg: the content of the response body. Data type: any type. |
Return value | N/A |
Example | Output:
|
exit
Item | Description |
---|---|
Syntax | exit(code [, body])
|
Feature | Ends the current request with the specified HTTP status code . If you also set the body parameter, a response that includes the specified response body is returned.
|
Parameter |
|
Return value | N/A |
Example |
|