Search code examples
regexproxyfiddler

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


I'm already using Fiddler to intercept requests for specific remote files while I'm working on them (so I can tweak them locally without touching the published contents).

i.e. I use many rules like this

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

This works perfectly.

What I'd like to do now is taking this a step further, with something like this

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

or, in plain text,

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.

Some scenarios to further clarify:

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

I tried to leverage what I already had:

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

Basically, I'm looking for //some_dummy_domain/ in requests. This seems to match correctly when testing, but I'm missing how to respond.

Can Fiddler use matches in responses, and how could I set this up properly ?

I tried to respond c:\somepath\$1 but Fiddler seems to treat it verbatim:

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

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

Solution

  • The problem is your use of insx at the front of your expression; the n means that you want to require explicitly-named capture groups, meaning that a group $1 isn't automatically created. You can either omit the n or explicitly name the capture group.

    From the Fiddler Book:

    Use RegEx Replacements in Action Text

    Fiddler’s AutoResponder permits you to use regular expression group replacements to map text from the Match Condition into the Action Text. For instance, the rule:

    Match Text: REGEX:.+/assets/(.*)
    Action Text: http://example.com/mockup/$1

    ...maps a request for http://example.com/assets/Test1.gif to http://example.com/mockup/Test1.gif.

    The following rule:

    Match Text: REGEX:.+example\.com.*

    Action Text: http://proxy.webdbg.com/p.cgi?url=$0

    ...rewrites the inbound URL so that all URLs containing example.com are passed as a URL parameter to a page on proxy.webdbg.com.

    Match Text: REGEX:(?insx).+/assets/(?'fname'[^?]*).*

    Action Text C:\src\${fname}

    ...maps a request for http://example.com/‌assets/img/1.png?bunnies to C:\src\‌img\‌1.png.