关于whistle
whistle(读音[ˈwɪsəl],拼音[wēisǒu])基于Node实现的跨平台web调试代理工具,类似的工具有Windows平台上的Fiddler,主要用于查看、修改HTTP、HTTPS、Websocket的请求、响应,也可以作为HTTP代理服务器使用,不同于Fiddler通过断点修改请求响应的方式,whistle采用的是类似配置系统hosts的方式,一切操作都可以通过配置实现
whistle的所有操作都可以通过类似如下配置方式实现:
pattern operatorURI
pattern 为匹配请求url的表达式
域名匹配
www.example.com
带端口的域名
www.example.com:6666
带协议的域名,支持:http、https、ws、wss、tunnel
http://www.example.com
# 路径匹配,同样支持带协议、端口
https:/www.exapmle.com:6666/test
# 正则匹配
/^https?://www\.example\.com\/test/(.*)/
# 通配符匹配
^www.example.com/test/***
operatorURI 为对应的操作,可以是域名或路径,也可以由操作协议+操作值组成(operatorURI = opProtocol://opValue)
m.hutaojie.com 127.0.0.1:3000 filter:///proxy/ filter:///login.html #excludeFilter:///garden_home.html/
界面介绍
network
rules
www.example.com res://{index.html}
www.example.com res://({"delay":6000,"body":"1234567890"})
www.example.com xfile://</Users/index.html>
匹配模式
- 域名匹配
- 路径匹配
-
精准匹配
$符号开头 $http://www.test.com operatorURI
-
正则匹配
支持子匹配,$0代表整个请求url,$1——$9代表子匹配的字符串 /[^?#]\/([^\/]+)\.html/ protocol://...$1...
-
通配符匹配
^符号开头 ^www.example.com/test/*** referer://http://www.test.com/$1
插件使用
npm i -g whistle.your-plugin-name
协议
-
请求替换
m.hutaojie.com 127.0.0.1:3000
-
file AND xfile
将请求的内容替换成指定的文件的内容
www.test.com/abc file://filpath
则请求http://www.test.com/abc/index...,如果不想自动补全可以使用操作符<>:
www.test.com/abc file://<filepath>
- rawfile
完全自定义http的报文,包括header和body,一般不用这个,除非有完整的http报文。
- filter
excludeFilter:表示排除匹配的请求
includeFilter:只保留匹配的请求 -
method
m.hutaojie.com method://post
-
statusCode
设置状态码,不会发起请求,要配合resBody等使用
statusCode://200
- replaceStatus
覆盖响应的状态码
- ua
设置请求头的user-agent - reqDelay/resDelay
设置延迟请求/响应的时间
-
reqHeaders/resHeaders
设置请求/响应的额外头部
m.hutaojie.com reqHeaders://{test-reqHeaders.json}
test-reqHeaders.json:
x-test1: value1 x-test2: value2 x-testN: valueN
- reqPrepend/resPrepend,reqAppend/resAppend
在请求/响应里前/后插入内容 - reqBody/resBody
替换请求/响应的内容
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。