23

I'm trying to find a tool that will allow non-programmers to test files on a live server.

For example, they could modify an image on their computer, reload a webpage, then see the results of their work immediately.

I've tried finding a tool for this, because it seems obvious enough that someone must've thought of it, but a lot of software I see doesn't quite fit. A tool called Fiddler does this (they call it autoresponding) but it's Windows-only. I could change the hosts file to redirect to a local instance of nginx or something, but that seems difficult to maintain when all I really want is a simple tool that will something like this...

http://someserver.com/css/(.*) -> /home/user/localcss/$1

Does anybody have any recommendations?

Edit: Redirect clarification

max
  • 676
  • 1
  • 5
  • 10

6 Answers6

23

Fiddler has this feature; just click the AutoResponder tab and map URLs to local files. Thousands of people do this every day.

See also video #5 here: http://www.fiddlerbook.com/fiddler/help/video/default.asp

EricLaw
  • 56,563
  • 7
  • 151
  • 196
  • 2
    Charles works better for me as I am on Linux. Fiddler works well for windows and is free! – ghostCoder Aug 11 '11 at 15:30
  • Does this work for pages/files served via https? I can't seem to generate the proper rule for the page i want to modify by copy the URL for the rule, which, starts with https – gogogadgetinternet May 23 '13 at 21:46
  • Of course it works for HTTPS, as well as FTP and HTTP. Post your question to the Fiddler forum or open a new question with details if you need help. – EricLaw May 23 '13 at 23:03
  • The video is no longer available, but here's the page showing how to map a local file: http://docs.telerik.com/fiddler/generate-traffic/tasks/modifyautoresponder (in the 'rule editor' section, open the second dropdown and choose 'find a file...'). – Tilt Apr 02 '14 at 08:19
  • Do you know if I can map all files in a directory using just one rule like that? Or would I have to map every single file individually? – Andy Jul 29 '15 at 06:09
  • @Andy: On StackOverflow, it's a best practice to ask new questions as questions. But the answer is yes: you'd use a regular expression rule for this. See e.g. http://blogs.msdn.com/b/fiddler/archive/2012/01/09/fiddler-2.3.8.2-beta-views-woff-mp3-h264-datauris-and-autoresponder-supports-regular-expression-groups.aspx – EricLaw Jul 29 '15 at 15:59
  • @ghostCoder how can you use charles to filter out unwanted scripts? – SuperUberDuper Aug 05 '15 at 10:04
8

I found Charles Proxy very useful for this http://www.charlesproxy.com/documentation/tools/map-local/

ghostCoder
  • 1
  • 9
  • 49
  • 72
4

Max's PAC solution was a life-saver so I'm providing more details (can't yet up vote)

To use a local version of, say, css files, create a file 'proxy.pac', which contains this function:

function FindProxyForURL(url, host)
{
    // use regex to match requests ending with '.css'
    // and redirect them to localhost
    var regexpr = /.**\.css/;
    if(regexpr.test(url))
    {
        return "PROXY localhost";
    }

    // Or else connect directly:
    return "DIRECT";
}

Save 'proxy.pac' and point your browser to this file. In Firefox this is in Options > Advanced > Connection > Settings > Automatic Proxy Configuration URL

For best practice, also add a MIME type to your web server: map '.pac' to type 'application/x-ns-proxy-autoconfig'.

All requests to .css files will now be routed to localhost. Don't forget to ensure the file structure is the same on the proxy server.

In the case of CSS, it may well be easier to override CSS by using a local chrome. For example in Firefox, chrome/userContent.css. See http://kb.mozillazine.org/UserContent.css

Joey Ciechanowicz
  • 3,345
  • 3
  • 24
  • 48
LambethWalk
  • 106
  • 6
1

It's been a while since I asked this question and I have an good technique that wasn't suggested.

PAC files are supported by all major browsers, and allow you to write a script that can redirect any individual request to a proxy server. So for example the proxy server could serve a PAC file, have the PAC file redirect whitelisted URLs to the proxy server, and return the local versions of these files. It can even support HTTPS.

Beware of one gotcha - Internet Explorer. It helpfully "caches" the results of this script incorrectly, so that if one URL on a domain is proxied, all URLs at that domain will be proxied. This feature can be disabled, however.

max
  • 676
  • 1
  • 5
  • 10
1

You can do this with the modify response rule in Requestly.

Using the local file option you can specify any file to be used as the response for the intercepted request.
According to their documentation it also supports hot reloading, i.e., as long as the file path remains the same, the rule will pick up the changes that you made.

As for the dynamic URL matching, they have support for regex and wildcards in their source filters

Note: This is currently only available in their desktop app.
If you want to implement this using their chrome extension ,which is what I personally did, you can use the Redirect rule paired with a mock server. Here is a page explaining this
You can setup a mock server / mock files endpoint within Requestly instead of using something nginx or a local server to do so. But this works only for text based content, not images

This would also bypass any setup on the tester's local machine. They would only need to install the extension. All you would have to do is send them the endpoint for your mock server and the redirect rule that you created.

nsrCodes
  • 625
  • 10
  • 25
-11

Actually you can't do this because browsers don't allow files over http:// to access file on the local machine (just think a moment about it... What would happen if, for example, a malicious webpage loads some private files from your computer?).
Some browsers (e.g. Safari) allows files over file:// to access other file:// files, others don't, but no browser allows http:// to access file://.

Firefox has a feature called "Signed scripts", which are scripts digitally signed with a trusted certificate. They can ask the user to grant them access to the local hard drive. Look at this: http://www.mozilla.org/projects/security/components/signed-scripts.html

Do you mean the Fiddler Web Proxy (www.fiddler2.com)? There is a commercial Java-based alternative named Charles Web Proxy that may fit your needs.

MrMagic
  • 54
  • 4
  • I'm not looking to use file:// urls in a browser, I'm looking for some kind of proxy that will allow me to replace files silently with local versions. I modified my question for clarity. Charles is cost-prohibitive, unfortunately. – max Jan 27 '11 at 20:31
  • I misunderstood your question, sorry. Anyway, you can install something like LAMP, WAMP or MAMP, put the files to test in the htdocs directory and then refer to them as http://localhost/ – MrMagic Jan 27 '11 at 20:38