How to intercept Websocket request and respond with mocked response

4 posts, 0 answers
  1. Malleswari
    Malleswari avatar
    3 posts
    Member since:
    Feb 2019

    Posted 16 Jul Link to this post

    Hi,

    Thanks for Fiddler and FiddlerCore.  I have been using them to mock my https requests to a server and send back my customized response.

    (Autoresponder).

     

    Is it possible to achieve the same for websocket requests. 

    I need to intercept the websocket requests, send my own JSON file as a response.

     

    Any leads please?

     

    Thanks,

    Malleswari

  2. Eric R | Technical Support Engineer
    Admin
    Eric R | Technical Support Engineer avatar
    230 posts

    Posted 18 Jul Link to this post

    Hi Malleswari,

    At this time, Fiddler doesn't expose functionality to manually modify WebSocket messages as they pass through. For now, you can modify messages using FiddlerScript and the OnWebSocketMessage handler. Let me provide an example for what this would look like.

    The following logic would append the string  "... bazinga!" to the payload:

    static function OnWebSocketMessage(oMsg: WebSocketMessage) {
        // Conditionally modify message content
        var sPayload = oMsg.PayloadAsString();
        if (sPayload.Contains("time")) {
            oMsg.SetPayload(sPayload + "... bazinga!");
        }
        // FiddlerApplication.Log.LogString(oMsg.ToString());
    }

    We do have existing feature requests for WebSocket message manipulation. These can be viewed at the WebSocket playback and Send Direct Messages threads. Additionally, I have increased the priority of the 2 items and encourage you to cast a vote as well. 

    Please let me know if you have any additional questions and thank you for using Fiddler.

    Regards,

    Eric R
    Progress 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. Malleswari
    Malleswari avatar
    3 posts
    Member since:
    Feb 2019

    Posted 19 Jul in reply to Eric R | Technical Support Engineer Link to this post

    Thanks for the reply Eric.

    The event handler OnWebSocketMessage()  is invoked after we establish a WS connection. 

    My requirement is to write a test method which removes all external dependencies.  

    Hence, I am looking out if there is a way to send a hardcoded response even if the server is not responding, that means, to intercept the request before it reaches the server like OnBeforeRequest() + Autoresponder.

     

    Thanks,

    Malleswari

  4. Eric R | Technical Support Engineer
    Admin
    Eric R | Technical Support Engineer avatar
    230 posts

    Posted 19 Jul Link to this post

    Hi Malleswari,

    At the present time, this feature isn't available for WebSockets. I encourage you to follow the WebSocket playback and Send Direct Messages feedback requests. Additionally, the Release History will provide the most relevant information for releases.

    Please let me know if you have any additional questions. Thank you.

    Regards,
    Eric R
    Progress 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
Back to Top