This is a migrated thread and some comments may be shown as answers.

How to intercept Websocket request and respond with mocked response

3 Answers 4070 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
Malleswari
Top achievements
Rank 1
Malleswari asked on 16 Jul 2019, 08:38 AM

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

3 Answers, 1 is accepted

Sort by
0
Eric R | Senior Technical Support Engineer
Telerik team
answered on 18 Jul 2019, 08:36 PM
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
0
Malleswari
Top achievements
Rank 1
answered on 19 Jul 2019, 12:07 PM

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

0
Eric R | Senior Technical Support Engineer
Telerik team
answered on 19 Jul 2019, 08:41 PM
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
Tags
Fiddler Classic
Asked by
Malleswari
Top achievements
Rank 1
Answers by
Eric R | Senior Technical Support Engineer
Telerik team
Malleswari
Top achievements
Rank 1
Share this question
or