Hi, I'm trying to proxy and cache some responses that are being redownloaded over and over.
To do that I wrote this simple customization in FiddlerScript:
static function OnBeforeResponse(oSession: Session) { var captureRequests = false; var targetHost = "api.nuget.org"; var captureFolder = "c:\\Projects\\Fiddler\\api.nuget.org"; // Capture traffic if (captureRequests && oSession.host.toLowerCase() == targetHost) { var targetFile = captureFolder + oSession.PathAndQuery.Split('?')[0].Replace('/','\\'); oSession.oResponse["X-oSession-PathAndQuery"] = targetFile; var fi = new FileInfo(targetFile); Directory.CreateDirectory(fi.DirectoryName) if(!File.Exists(fi.FullName)) { File.WriteAllBytes(fi.FullName, oSession.ResponseBody); } }// // Replay captured var replayRequests = true; if (replayRequests&& oSession.host.toLowerCase() == targetHost) { var targetFile = captureFolder +"\\" + oSession.PathAndQuery.Split('?')[0].Replace('/','\\'); var fi = new FileInfo(targetFile); if(!File.Exists(fi.FullName)) { oSession["x-replywithfile"] = fi.FullName; } } }
And presumably it should work - when captureRequests=true - fiddler captures requests from a particular domain into a folder, preserving path and file name
When replayRequests = true - it simply replays existing files.
The problem here that even if I just capturing the data (I suspect I may be replaying too late - fiddler would call http already by that time...) - fiddler throws a lot of errors with this text:
---------------------------FiddlerScript OnBeforeResponse() failed.---------------------------There was a problem with your FiddlerScript.The given path's format is not supported. at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath) at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath) at System.IO.FileInfo.Init(String fileName, Boolean checkHost) at Fiddler.ScriptNamespace.Handlers.OnBeforeResponse(Session oSession) at Fiddler.ScriptBase.(Session ) in C:\JenkinsHome\jobs\FiddlerReleaseBuild\workspace\Fiddler2\Common\Application\Scripting\ScriptBase.cs:line 919---------------------------OK ---------------------------
I tried to investigate it by playing with code and identified that for some reason a typical file path like `c:\Projects\Fiddler\api.nuget.org\v3\registration1-gz\analytics\index.json` causes an error. Or that code is somehow not thread safe and competing requests simply break it (and visual studio starts them in parallel so there is a high chance of some kind of race).
Can anyone suggest what am I doing wrong here or maybe advice on better solution to the problem.