Using autoresponder without internet

13 posts, 1 answers
  1. coolBlue
    coolBlue avatar
    9 posts
    Member since:
    Aug 2015

    Posted 17 Nov 2015 Link to this post

    I use Fiddler to redirect the browser to local resources to test my library components before I push them up to github.  This works really great using localhost while working in webstorm.  

     

    If I want to work without internet though (e.g. on a plane), the redirect fails.  I get net::ERR_TUNNEL_CONNECTION_FAILED errors in the browser for resources that I would normally redirect to local versions.  

     

     I thought that Fiddler would intercept these requests and just respond with the local resource, but the browser is trying to GET from the remote resource.  

    Why is this and how can I fix it?

  2. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 18 Nov 2015 Link to this post

    Hello, coolBlue--

    You didn't say how you're using Fiddler to achieve what you're doing.

    Fiddler's AutoResponder can absolutely be used to "offline" a website or service; this is commonly used for big company demos where the Internet access is less than 100% reliable (e.g. teams used to do this in the Microsoft Company Meeting at Safeco Field). 

    If I had to guess, I'd guess that, in whatever approach you're using, you've failed to handle CONNECT tunnels (which are created before HTTPS traffic is sent). If you're using the Fiddler AutoResponder, the simplest way to handle this is to uncheck the "Unmatched requests passthrough" checkbox, which will cause Fiddler to automatically indicate "Success" for all CONNECT tunnels without even hitting the network.

    To achieve the same thing from FiddlerScript, you'd do something like:

       // Add to OnBeforeRequest
       if (bWorkingOffline && oSession.HTTPMethodIs("CONNECT"))
       {
          oSession["X-ReplyWithTunnel"] = "Work offline; generate a fake tunnel...";
       } 


    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. coolBlue
    coolBlue avatar
    9 posts
    Member since:
    Aug 2015

    Posted 18 Nov 2015 in reply to Eric Lawrence Link to this post

    Eric Lawrence said:Hello, coolBlue--
    You didn't say how you're using Fiddler to achieve what you're doing.

    coolBlue said: I use Fiddler to redirect the browser to local resources to test my library components before I push them up to github.  This works really great using localhost while working in webstorm.

    the thread title also contained a small clue...

    Eric Lawrence said:

    ...the simplest way to handle this is to uncheck the "Unmatched requests passthrough" checkbox

    ...To achieve the same thing from FiddlerScript, you'd do something like:

       // Add to OnBeforeRequest
       if (bWorkingOffline && oSession.HTTPMethodIs("CONNECT"))
       {
          oSession["X-ReplyWithTunnel"] = "Work offline; generate a fake tunnel...";
       } 

    If I un-check the "Unmatched requests passthrough" checkbox, then I have to have an explicit rule for localhost interaction as well.

    I found this worked...

    regex:http://localhost:(?'resource'.*)

    http://localhost:${resource}

    If I want to automate it with fiddler script, how do I resolve bWorkingOffline?  I couldn't find a flag anywhere when researching your book.

    Regards,

    Cool Blue

  4. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 19 Nov 2015 Link to this post

    I have to have an explicit rule for localhost interaction as well.

    Sure, that rule would be simply:

      MatchCondition:  //localhost:
      Action:                   *exit

    >If I want to automate it with fiddler script, how do I resolve bWorkingOffline? 

    That would be a variable you create to track whether or not you want this behavior enabled. E.g. you'd add something like 

      public static RulesOption("Work Offline")
      var bWorkingOffline: boolean = false; 


    ...inside your Handlers class.

    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. coolBlue
    coolBlue avatar
    9 posts
    Member since:
    Aug 2015

    Posted 19 Nov 2015 in reply to Eric Lawrence Link to this post

    OK, thanks for that, the AutoResponder rule is much better like that.

    With regard to the script, I don't understand the syntax at all.  When I enter it like you suggest - in the Handlers class, below the other RulesOption declarations - the option appears but the boolean is always true regardless of the menu item state (as evidenced by the session behaviour).  The examples in the book have a different syntax but neither is Javascript or as far as I can tell C# (I'm no expert).  Are you simply parsing the text and binding the menu item and the var by dint of co-location and why is the flag always true regardless of the menu setting?  

  6. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 19 Nov 2015 Link to this post

    >the option appears but the boolean is always true regardless of the menu item state

    Not if entered correctly. You can do an even simpler test; add the following just inside OnBeforeRequest

         FiddlerApplication.UI.SetStatusText(bWorkingOffline.ToString());

    >The examples in the book have a different syntax

    There are many different examples in the book; see the Extend the Rules Menu section around page 209 (depending on which edition you're reading) for discussion.

      public static RulesOption("Work Offline")
      var bWorkingOffline: boolean = false; 

    Just to break this down: these two lines create a public static boolean field with an initial value of false. The field is decorated with a RulesOption attribute (which is constructed using a string argument of "Work Offline"). When Fiddler compiles the FiddlerScript, it enumerates the public static fields, notes any that have a RulesOption attribute, and binds each as the backing value field for a new menu item on the Rules menu whose name is the text specified in the attribute.

    The location of the attribute is somewhat flexible, you can write, for instance

      RulesOption("Work Offline")
      public static var bWorkingOffline: boolean = false; 

    ... if you prefer.

    >but neither is Javascript or as far as I can tell C# (I'm no expert).

    From the book:
    About FiddlerScript
    As each Session flows through Fiddler, methods in the CustomRules.js script file are run, enabling you to hide, flag, or modify Sessions based on criteria of arbitrary complexity. Your rules script can be modified and recompiled dynamically at runtime without restarting Fiddler. This book does not provide a comprehensive reference to the JScript.NET language upon which FiddlerScript is based. If you plan to code especially powerful or complicated FiddlerScript, you should consider finding a copy of Microsoft JScript.NET Programming

    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. coolBlue
    coolBlue avatar
    9 posts
    Member since:
    Aug 2015

    Posted 19 Nov 2015 in reply to Eric Lawrence Link to this post

    OK, thanks, that all seems to make sense now, I was confused by the persistent state in the browser (cache) and maybe in Fiddler also: not sure...

    There is an Online status indicator in the UI, just to confirm: that's not exposed in your API right?  If it was then I could automate the whole thing without having to worry about selecting a menu item...

     

    Regarding your RulesOption attribute: yes, of course I was referring to the examples in the chapter you mentioned, but, what is the genealogy of that "scripted specifier" syntax?  I guess I can understand why you did it like that but, I would have thought a global rulesOptions object would be more idiomatic? Either way, for me anyway, it would be good to have that explained in the book.  You second standard terms like "annotate" and "attribute" in non-standard ways and that's very confusing and the different syntax used in the book c.f. the default script file adds to the confusion.

     

  8. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 20 Nov 2015 Link to this post

    .NET exposes the network state via NetworkInterface.GetIsNetworkAvailable(); it also offers events when the status changes. There's a little subtlety to it because those events typically fire a few times when network connections are established and parameters negotiated, etc.

    Attributes are a first-class citizen in .NET programming, and you apply them to a field, method or class by annotating that field, method, or class.

    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  9. coolBlue
    coolBlue avatar
    9 posts
    Member since:
    Aug 2015

    Posted 20 Nov 2015 in reply to Eric Lawrence Link to this post

    Eric Lawrence said:.NET exposes the network state via NetworkInterface.GetIsNetworkAvailable(); it also offers events when the status changes. There's a little subtlety to it because those events typically fire a few times when network connections are established and parameters negotiated, etc.

    Great, how do I query that in FiddlerScript?

    Eric Lawrence said:.Attributes are a first-class citizen in .NET programming, and you apply them to a field, method or class by annotating that field, method, or class.

    OK, thanks, I read up on metaprogramming in .NET and it's clear now. Might be worth mentioning that you opted not to use the square brackets just to clarify the syntax difference.
  10. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 23 Nov 2015 Link to this post

    You'd query the  NetworkInterface.GetIsNetworkAvailable() value like any other property, e.g.

      var bOnNet = NetworkInterface.GetIsNetworkAvailable();

    You should add import System.Net; to the top of your script.

    Unlike in C#, in JScript.NET, attributes are not wrapped in square brackets.

    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  11. coolBlue
    coolBlue avatar
    9 posts
    Member since:
    Aug 2015

    Posted 23 Nov 2015 Link to this post

    Eric Lawrence said:.You'd query the  NetworkInterface.GetIsNetworkAvailable() value like any other property, e.g.

      var bOnNet = NetworkInterface.GetIsNetworkAvailable();

    You should add import System.Net; to the top of your script./quote]

     I have .NET v4.5 installed om my system, I added the header file like this...

      import System;
      import System.Windows.Forms;
      import System.Net;
      import Fiddler;

    declared the variable as you suggested like this...

      var bOnNet = NetworkInterface.GetIsNetworkAvailable();

    but it throws a compiler error saying that NetworkInterface has not been declared

     

    Eric Lawrence said:.Unlike in C#, in JScript.NET, attributes are not wrapped in square brackets.

    I mean mention it in your book or in the FiddlerScript file.

  12. Answer
    Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 24 Nov 2015 Link to this post

    MSDN is helpful for questions about .NET framework APIs. https://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface(v=vs.110).aspx suggests that the namespace to import is actually System.Net.NetworkInformation.

    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  13. coolBlue
    coolBlue avatar
    9 posts
    Member since:
    Aug 2015

    Posted 24 Nov 2015 in reply to Eric Lawrence Link to this post

    Thanks, yes I did search that and found the namespace and entered like...

     import System.Net 

      NetworkInformation.NetworkInterface.GetIsNetworkAvailable();

    which generated a compiler error, then, after seeing your reply I tried like...

      import System.Net.NetworkInformation;

      NetworkInterface.GetIsNetworkAvailable();

     and it finally worked!

Back to Top