This topic describes the syntax, description, parameters, and return values of request processing functions. This topic also provides examples of these functions.
add_req_header
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | add_req_header(name, value [, append])
|
Description | Adds a request header to requests before they are redirected to the origin server. |
Parameter |
|
Return value | Returns true by default and returns false if the specified request header is invalid.
|
Example |
|
del_req_header
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | del_req_header(name)
|
Description | 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 | Returns true by default and returns false if the specified request header is invalid.
|
Example |
|
add_rsp_header
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | add_rsp_header(name, value [, append])
|
Description | Adds a response header. |
Parameter |
|
Return value | Returns true by default and returns false if the specified response header is invalid.
|
Example |
|
del_rsp_header
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | del_rsp_header(name)
|
Description | Deletes a response header. |
Parameter | name : the name of the response header that you want to delete. Data type: string.
|
Return value | Returns true by default and returns false if the specified response header is invalid.
|
Example |
|
encode_args
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | encode_args(d)
|
Description | Converts the k/v pairs 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 | Returns a URI-encoded string. |
Example |
|
decode_args
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | decode_args(s)
|
Description | 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 | Returns a dictionary object converted from the specified string. |
Example |
|
rewrite
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | rewrite(url, flag, code)
|
Description | Performs a rewrite or redirect operation. |
Parameter |
|
Return value |
|
Example |
|
say
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | say(arg)
|
Description | 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 | None. |
Example |
|
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | print(arg)
|
Description | 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 | None. |
Example |
|
exit
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | exit(code [, body])
|
Description | Ends the current request with the specified code . If you also set the body parameter, a response that includes the specified response body is returned.
|
Parameter |
|
Return value | None. |
Example |
|
get_rsp_header
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | get_rsp_header(str)
|
Description | Obtains a response header. |
Parameter | str: the response header that you want to obtain. Data type: string. |
Return value | Returns the specified response header of string, number, dictionary, or Boolean data
type.
|
Example |
|
add_rsp_cookie
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | add_rsp_cookie(k, v [,properties])
|
Description | Sets the response cookie. Each time the function is called, a new Set-Cookie response header is generated. |
Parameter |
|
Return value | A value of true is returned if the specified cookie is set and a value of false is returned if the specified cookie failed to be set. |
Example | Response:
|