|
1 |
| -title: Rewrite built in variables |
| 1 | +title: Rewrite Built-in Variables |
2 | 2 | ---
|
3 | 3 |
|
4 |
| -> 如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢! |
5 |
| -> |
6 | 4 | > If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!
|
7 | 5 |
|
8 |
| -hiproxy的rewrite规则配置文件中,我们可以自己定义全局变量(在全局作用域中使用`set $var value`),也可以在其他作用域中定义变量; |
| 6 | +You can define your own global variables (use `set $var value` in global scope) in rewrite rules configuration file of hiproxy, as well as you can define variables in other scopes. |
9 | 7 |
|
10 |
| -hiproxy内置了一些变量,这些内置变量可以在相应的作用域中直接使用,不需要去定义并赋值,而且这些内置变量也不能被用户重新定义覆盖。 |
| 8 | +Hiproxy has some built-in variables so that you can use them directly in corresponding scopes without neither defining nor assigning. Particularly, user cannot redefine the variables to overwrite them. |
11 | 9 |
|
12 |
| -## 全局变量 |
| 10 | +## Global variables |
13 | 11 |
|
14 |
| -这些全局变量,在配置文件的**任何地方都可以使用**。 |
| 12 | +Global variables can **be used in everywhere of configuration files**. |
15 | 13 |
|
16 |
| -> 提示:hiproxy暂时没有内置的全局变量。将来会添加! |
| 14 | +> Hint: hiproxy currently has not built-in variables. Some would be added in the furture. |
17 | 15 |
|
18 |
| -## location块级变量 |
| 16 | +## Location block scope variables |
19 | 17 |
|
20 |
| -这些变量,只能在`location`块中使用,这些变量主要是存储与请求相关的一些信息,比如请求的参数(`$query_string`)、Cookie(`$cookie_name`)和host(`$host`)等。现在支持的所有内置变量: |
| 18 | +You can use the variables only in `location` blocks. Then are used to store information about request, such as query string(`$query_string`), Cookie(`$cookie_name`), and host(`$host`), etc. Here are all the variables that are currently supported: |
21 | 19 |
|
22 | 20 | ### $host
|
23 |
| -当前请求的URL对应的`host`或者请求头部的`Host`字段。 |
| 21 | + |
| 22 | +The `host` correlative to the current request URL, or the `Host` field in request headers. |
24 | 23 |
|
25 | 24 | ### $hostname
|
26 |
| -当前请求的URL对应的`hostname`或者请求头部的`Host`字段对应的`hostname`。 |
| 25 | + |
| 26 | +The `hostname` correlative to the current request URL, or correlative to the `Host` field in request headers. |
27 | 27 |
|
28 | 28 | ### $server_port
|
29 |
| -请求的服务端口号,默认`80`。 |
| 29 | + |
| 30 | +The server port number of the request, default `80`. |
30 | 31 |
|
31 | 32 | ### $search
|
32 |
| -请求的参数字符串(包括`?`),比如`?from=app&v=19482848253`。 |
| 33 | + |
| 34 | +The query string (with `?`) of the request, such as `?from=app&v=19482848253`. |
33 | 35 |
|
34 | 36 | ### $query_string
|
35 |
| -请求的参数字符串(**不包括`?`**),比如`from=app&v=19482848253`。 |
| 37 | + |
| 38 | +The query string (**without `?`**), such as `from=app&v=19482848253`. |
36 | 39 |
|
37 | 40 | ### $scheme
|
38 |
| -请求的协议,`http`或者`https`。 |
| 41 | + |
| 42 | +The request protocol, it's either `http` or `https`. |
39 | 43 |
|
40 | 44 | ### $request_uri
|
41 |
| -请求的完整地址,比如`http://hiproxy.org:8081/docs/index.html?from=google&v=_1847295727524#get-started`。 |
| 45 | + |
| 46 | +The entire request URL, such as `http://hiproxy.org:8081/docs/index.html?from=google&v=_1847295727524#get-started`. |
42 | 47 |
|
43 | 48 | ### $path
|
44 |
| -请求的`path`(包括参数),比如`/docs/index.html?from=google&v=_1847295727524#get-started`。 |
| 49 | + |
| 50 | +The request `path` (with query string), such as `/docs/index.html?from=google&v=_1847295727524#get-started`. |
45 | 51 |
|
46 | 52 | ### $path_name
|
47 |
| -请求的`path_name`(不包括参数),比如`/docs/index.html`。 |
| 53 | + |
| 54 | +The request `path_name` (without query string), such as `/docs/index.html`. |
48 | 55 |
|
49 | 56 | ### $base_name
|
50 |
| -请求path的最后一部分,比如path为`/docs/index.html`,则$base_name为`index.html`。 |
| 57 | + |
| 58 | +The last part of the path. For exampke, let's say the path is `/docs/index.html`, so that $base_name is `index.html`. |
51 | 59 |
|
52 | 60 | ### $dir_name
|
53 |
| -请求path的目录名称,比如path为`/docs/index.html`,则$dir_name为`/docs/`。 |
| 61 | + |
| 62 | +The directory names of the path. For example, let's say path is `/docs/index.html`, so that $dir_name is `/docs/`. |
54 | 63 |
|
55 | 64 | ### $hash
|
56 |
| -请求url中的`hash`(包括`#`),比如'#get-started'。 |
| 65 | + |
| 66 | +The `hash` (with `#`) of request URL, such as `#get-started`. |
57 | 67 |
|
58 | 68 | ### $hash_value
|
59 |
| -请求url中的`hash`值(不包括`#`),比如'get-started'。 |
| 69 | + |
| 70 | +The `hash` value (without `#`) of request URL, such as `get-started`. |
60 | 71 |
|
61 | 72 | ### $uri
|
62 |
| -同`$request_uri`。 |
| 73 | + |
| 74 | +Same as `$request_uri`. |
63 | 75 |
|
64 | 76 | ### $cookie_*name*
|
65 |
| -`cookie`的值,`name`表示字段名称,这个名称中的大写字母都改成了小写,`-`替换成了`_`。比如`$cookie_userId`表示`cookie`中`useId`的值。 |
| 77 | + |
| 78 | +A `cookie` value. The `name` stands field name whose capital letters have been changed to lower ones and `-` characters have been changed to `_`. For example, `$cookie_userId` is for the value of `userId` in the `cookie`. |
66 | 79 |
|
67 | 80 | ### $http_*name*
|
68 |
| -请求头(request)中的字段值,`name`表示字段名称,这个名称中的大写字母都改成了小写,`-`替换成了`_`。比如请求头信息中包含`User-Agent: user agent`,可以使用变量`$http_user_agent`来获取这个值。 |
| 81 | + |
| 82 | +The value of a request header field. The `name` stands field name whose capital letters have been changed to lower ones and `-` characters have been changed to `_`. For example, let's say `User-Agent: user agent` is a valid request header, then `$http_user_agent` can get its value. |
69 | 83 |
|
70 | 84 | ### $arg_*name*
|
71 |
| -请求参数的值,`name`表示字段名称,这个名称中的大写字母都改成了小写,`-`替换成了`_`。比如请求参数为`?from=google&v=_1847295727524`,可以通过`$arg_from`来获取`from`的值。 |
| 85 | + |
| 86 | +The value of a request query parameter. The `name` stands field name whose capital letters have been changed to lower ones and `-` characters have been changed to `_`. For example, let's say the query string is ``?from=google&v=_1847295727524`, then `$arg_from` can get value of `from`. |
72 | 87 |
|
0 commit comments