How can I convert oSession.Timers.ClientBeginRequest to unix time

0 Answers 128 Views
Fiddler Classic
Roger
Top achievements
Rank 1
Roger asked on 09 May 2022, 01:55 PM | edited on 09 May 2022, 05:07 PM

I like to grab the ClientBeginRequest and convert that to UNIX epoch time in the Fiddler scripts, however, I cant seem to get the known methods to work like Math.floor. 

var iat = oSession.Timers.ClientBeginRequest; -> this does not give me unix time in sec

The idea is to generate json data with iat, exp and convert it to base64 and add it to the header

        if (oSession.HostnameIs("my-host.com") && oSession.uriContains("/value/"))
        {
            // Take ClientBeginRequest and convert it to unix
            //    var iat = oSession.Timers.ClientBeginRequest;
            //    var iat2 = Math.floor(iat / 1000);
            
            // Take the // Take ClientBeginRequest and convert it to unix + 30 mins
            //    var minutesToAdd=30;
            //    var exp = new Date(iat + minutesToAdd*60000);


            // convert json data to base64
            //    var obj = {iat: 'iat', exp: 'exp'};
            //    objJsonStr = JSON.stringify(obj);
    //    objJsonB64 = Buffer.from(objJsonStr).toString("base64");

            //Add the value to header
            oSession.oRequest["new-header-name"] = "headerValue in base64";
        }

 

Update:

I have iat and exp working, just need some help with converting the value to base64. 

        import Microsoft.JScript;

        var iat = Math.round((new Date()).getTime() / 1000);
        oSession.oRequest["iat"] = iat
        
        var exp = (iat + 1800);
        oSession.oRequest["exp"] = exp
                
        var data = {iat: 'iat', exp: 'exp'};

            

Nick Iliev
Telerik team
commented on 10 May 2022, 06:40 AM

Check the following threads for more information on how to handle JSON and Base64 in FIddlerScript

https://www.telerik.com/forums/how-to-use-fiddler-webformats-json-jsondecode

https://www.telerik.com/forums/getting-responsebody-as-base64-string

 

 

No answers yet. Maybe you can help?

Tags
Fiddler Classic
Asked by
Roger
Top achievements
Rank 1
Share this question
or