快速上手
安装完成后
- 客户端版本:直接启动桌面应用程序
- 命令行版本:在浏览器中访问 http://local.whistlejs.com
即可进入操作界面:

操作界面主要功能:
- Network:实时抓包分析与请求重放/编辑等界面
- Rules:修改请求/响应的规则配置界面
- Values:操作内容配置界面(支持规则变量调用)
- Plugins:插件管理界面
界面操作示例
重放请求
点击请求并点击顶部
Replay
按钮,或请求列表右键菜单 Actions -> Replay编辑或构造请求
点击请求并点击顶部
Edit
按钮,或请求列表右键菜单 Actions -> Edit Request
完整功能参见:界面功能
规则配置示例

Whistle 通过简单的规则配置修改请求/响应,基本语法结构如下:
txt
pattern operation [includeFilter://pattern1 ... excludeFilter://patternN ...]
规则由三个核心组件构成:
- 匹配模式 (
pattern
),匹配请求 URL 的表达式,支持多种格式:- 域名匹配:
www.test.com
(匹配该域名所有请求,含端口) - 路径匹配:
www.test.com/path
- 正则表达式:
/^https?://test\.com//i
- 通配符:
*.test.com
、**.test.com/path
Whistle 有三种 URL 类型:
- 隧道代理:
tunnel://domain[:port]
- WebSocket:
ws[s]://domain[:port]/path/to
- 普通 HTTP/HTTPS:
http[s]://domain[:port]/path/to
- 域名匹配:
- 操作指令 (
operation
),格式:protocol://value
protocol
:操作类型,如:reqHeaders
:修改请求头resHeaders
:修改响应头
value
:操作内容,支持多种数据源:- 内联值:
reqHeaders://x-proxy-by=whistle
(直接添加请求头) - 本地文件:
file://path/to/file
- 远程资源:
https://example.com/data.json
- 预设变量:
{key}
(从 Rules 里面的内嵌值 或 Values 读取)
- 内联值:
operation 里面的
protocol://
在以下两种场景时可以省略:ip
或ip:port
:等价于host://ip
或host://ip:port
D:\path\to
、/path/to
或{key}
:等价于file://D:\path\to
、file:///path/to
或file://{key}
- 过滤条件(可选) (
includeFilter/excludeFilter
)- 逻辑关系:多条件间为「或」匹配,只要匹配其中一个过滤条件就成立
- 匹配范围:
- 请求:URL、方法(GET/POST等)、头部字段、内容、客户端 IP
- 响应:状态码、头部字段、内容、服务端 IP
示例1:修改 DNS(设置 Hosts)
域名匹配
txtwww.test.com 127.0.0.1 # 支持带端口 www.test.com 127.0.0.1:8080 # CNAME 功能(端口可选) www.test.com host://www.example.com:8181
路径匹配
txtwww.test.com/path/to 127.0.0.1:8080 # 支持带协议 https://www.test.com/path/to 127.0.0.1:8080 # 只作用于隧道代理请求 tunnel://* 127.0.0.1:8080
通配符匹配
txt# 域名通配符,匹配 test.com 的所有子代域名 **.test.com 127.0.0.1:8080 # 支持带协议域名通配符 https://**.test.com 127.0.0.1:8080 # 路径通配符(* 是路径的合法字符,所以前面要加 ^ 告诉 Whistle 是通配符) ^**.test.com/*/path/to 127.0.0.1:8080 # 支持带协议路径通配符 ^https://**.test.com/*/path/to 127.0.0.1:8080
*
、**
、***
匹配的范围不同,参见文档:pattern正则匹配
txt# 规则正则表达式里面的 `/` 转不转义都可以 /^https?://\w+\.test\.com/ 127.0.0.1:8080
/regexp/x
等价于new RegExp(regexp, x)
过滤匹配
txt# 请求 URL 匹配 `pattern` 且请求头 `cookie` 包含 `env=test` pattern 127.0.0.1:8080 includeFilter://reqH.cookie=/env=test/ # 只对 iPhone 发起的该请求生效 https://www.test.com/path/to 127.0.0.1:8080 includeFilter://reqH.user-agent=/iPhone/i
示例2:修改表单数据
txt
# 修改表单里面的 `test` 字段的值
pattern reqMerge://test=123
# 删除表单里面的 `abc` 字段
pattern delete://reqBody.abc
示例3:设置跨域响应头
txt
# 设置跨域响应头 Access-Control-Allow-Origin: *,且排除 OPTION 请求
pattern resCors://* excludeFilter://m:option
# 非 `*` 的跨域请求头
pattern resCors://enable
规则高级配置
组合配置
txtpattern operation1 operation2 ... [includeFilter://pattern1 ... excludeFilter://patternN ...]
位置调换(
pattern1
和operation
不同时为 URL 或域名)即不同时为形如
https://test.com/path
、//test.com/path
、test.com/path
、test.com
的 URL 或域名txtoperation pattern1 pattern2 ... [includeFilter://pattern1 ... excludeFilter://patternN ...]
换行配置
txtline` operation pattern1 pattern2 ... [includeFilter://pattern1 ... excludeFilter://patternN ...] `
Whistle 会自动将代码块里面的换行符自动替换成空格
完整功能参见:规则配置