From e73994d010527a8e05247eedee273b4b0dd79d6e Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Mon, 22 May 2023 11:48:11 -0400 Subject: [PATCH] Update HTTP header attr matching config --- docs/config/routing.md | 14 ++++++-------- docs/en/config/routing.md | 14 ++++++-------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/docs/config/routing.md b/docs/config/routing.md index e221bac..c260445 100644 --- a/docs/config/routing.md +++ b/docs/config/routing.md @@ -69,7 +69,7 @@ "user": ["love@xray.com"], "inboundTag": ["tag-vmess"], "protocol": ["http", "tls", "bittorrent"], - "attrs": "attrs[':method'] == 'GET'", + "attrs": { ":method": "GET" }, "outboundTag": "direct", "balancerTag": "balancer" } @@ -155,19 +155,17 @@ 必须开启入站代理中的 `sniffing` 选项, 才能嗅探出连接所使用的协议类型. ::: -> `attrs`: string +> `attrs`: object -一段脚本,用于检测流量的属性值。当此脚本返回真值时,此规则生效。 - -脚本语言为 [Starlark](https://github.com/bazelbuild/starlark),它的语法是 Python 的子集。脚本接受一个全局变量 `attrs`,其中包含了流量相关的属性。 +一个 json object,键名字和值皆为字符串,用于检测流量的属性值。当 HTTP headers 包含所有指定的键,并且值包含指定的子字符串,则命中此规则。大小写不敏感。 目前只有 http 入站代理会设置这一属性。 示例: -- 检测 HTTP GET:`"attrs[':method'] == 'GET'"` -- 检测 HTTP Path:`"attrs[':path'].startswith('/test')"` -- 检测 Content Type:`"attrs['accept'].index('text/html') >= 0"` +- 检测 HTTP GET:`{":method": "GET"}` +- 检测 HTTP Path:`{":path": "/test"}"` +- 检测 Content Type:`{"accept": "text/html"}"` > `outboundTag`: string diff --git a/docs/en/config/routing.md b/docs/en/config/routing.md index f89ca28..d99d367 100644 --- a/docs/en/config/routing.md +++ b/docs/en/config/routing.md @@ -72,7 +72,7 @@ When a rule points to a load balancer, Xray selects an outbound through this loa "user": ["love@xray.com"], "inboundTag": ["tag-vmess"], "protocol": ["http", "tls", "bittorrent"], - "attrs": "attrs[':method'] == 'GET'", + "attrs": { ":method": "GET" }, "outboundTag": "direct", "balancerTag": "balancer" } @@ -162,19 +162,17 @@ An array where each item represents a protocol. This rule will take effect when The `sniffing` option in the inbound proxy must be enabled to detect the protocol type used by the connection. ::: -`attrs`: string +`attrs`: object -A script used to detect the attribute values of the traffic. When this script returns a truthy value, this rule takes effect. - -The script language is [Starlark](https://github.com/bazelbuild/starlark), which is a subset of Python syntax. The script accepts a global variable `attrs`, which contains traffic-related attributes. +A json object with string keys and values, used to detect the HTTP headers of the traffic. It matches when all specified keys exist in the header and corresponding values are a substring of the header value, case in-sensitive. Currently, only the inbound HTTP proxy sets this attribute. Examples: -- Detect HTTP GET: `"attrs[':method'] == 'GET'"` -- Detect HTTP Path: `"attrs[':path'].startswith('/test')"` -- Detect Content Type: `"attrs['accept'].index('text/html') >= 0"` +- Detect HTTP GET:`{":method": "GET"}` +- Detect HTTP Path:`{":path": "/test"}"` +- Detect Content Type:`{"accept": "text/html"}"` > `outboundTag`: string