如何将 Fiddler 的自动回复器配置为 "map" 主机到文件夹?

How to configure Fiddler's Autoresponder to "map" a host to a folder?

我正在使用 Fiddler 拦截对特定远程文件的请求(这样我就可以在不触及已发布内容的情况下在本地调整它们)。

即我使用了很多这样的规则

match:    regex:(?insx).+/some_file([?a-z0-9-=&]+\.)*
respond:  c:\somepath\some_file

这非常有效。

我现在想做的是更进一步,像这样

match:    regex:http://some_dummy_domain/(anything)?(anything)
respond:  c:\somepath\(anything)?(anything)

或者,在纯文本中,

Intercept any http request to 'some_dummy_domain', go inside 'c:\somepath' and grab the file with the same path and name that was requested originally. Query string should pass through.

需要进一步说明的一些场景:

http://some_domain/somefile       --> c:\somepath\somefile
http://some_domain/path1/somefile --> c:\somepath\path1\somefile
http://some_domain/path1/somefile?querystring --> c:\somepath\path1\somefile?querystring

我试图利用我已有的东西:

match:    regex:(?insx).+//some_dummy_domain/([?a-z0-9-=&]+\.)*
respond:  ...

基本上,我在请求中寻找 //some_dummy_domain/。这在测试时似乎匹配正确,但我不知道如何回应。

Fiddler 可以在响应中使用匹配项吗?我该如何正确设置它?

我试图回应 c:\somepath$1 但 Fiddler 似乎逐字处理:

match:   regex:(?insx).+//some_domain/([?a-z0-9-=&]+\.)*
respond: c:\somepath$1

request:  http://some_domain/index.html
response: c:\somepath$1html        <-----------

问题是你在表达式前面使用了 insxn 表示您需要 explicitly-named capture groups,这意味着不会自动创建组 </code>。您可以省略 <code>n 或显式命名捕获组。

来自 Fiddler 书:

在动作文本中使用 RegEx 替换

Fiddler 的 AutoResponder 允许您使用正则表达式组替换将匹配条件中的文本映射到操作文本中。例如,规则:

匹配文本:REGEX:.+/assets/(.*)
操作文本:http://example.com/mockup/

...将 http://example.com/assets/Test1.gif 的请求映射到 http://example.com/mockup/Test1.gif

以下规则:

匹配文本:REGEX:.+example\.com.*

操作文本:http://proxy.webdbg.com/p.cgi?url=[=19=]

...重写入站 URL,以便所有包含 example.com 的 URL 都作为 URL 参数传递到 proxy.webdbg.com 上的页面.

匹配文本:REGEX:(?insx).+/assets/(?'fname'[^?]*).*

操作文本 C:\src${fname}

...将 http://example.com/‌assets/img/1.png?bunnies 的请求映射到 C:\src\‌img\‌1.png