Cookies not saved to client/browser

0 Answers 571 Views
Fiddler Classic
Peter
Top achievements
Rank 1
Peter asked on 06 Dec 2021, 01:46 AM | edited on 06 Dec 2021, 01:46 AM

Hi there,

I have a browser application running on localhost:4200 (Angular) which is calling API methods on a remote host.

Using fiddler 4 I am intercepting the response and adding a cookie. I am also logging all the headers.

static function OnPeekAtResponseHeaders(oSession: Session) {
    oSession.oResponse.headers.Add("Set-Cookie","Test=MyCustomValue;");
    FiddlerObject.log(oSession.oResponse.headers);
}

In the logs I can see my Test cookie. I can also see a variety of other Set-Cookie headers being returned by the remote host.

However, none of them are being set in the browser, including my test cookie.

I have tried with different combinations of Domain, Path, SameSite, Secure etc, including removing these altogether, and I cannot get any cookies to be stored by the browser.

Any idea?

Nick Iliev
Telerik team
commented on 06 Dec 2021, 08:55 AM

Try to set the cookie in an earlier event like onBeforeRequest
Peter
Top achievements
Rank 1
commented on 06 Dec 2021, 08:25 PM

Thanks for the reply.

Unfortunately that will not work. What I am trying to do is intercept the *response* cookies from the remote service. These are not available before the request. 

My example above is me trying to simplify as much as possible to see why I cannot set cookies at all.  This is what I am actually trying to do:

static function OnPeekAtResponseHeaders(oSession: Session) {
    // Step through all cookies
    for (var x:int = 0; x < oSession.oResponse.headers.Count(); x++) {
        // If it's a cookie
        if(oSession.oResponse.headers[x].Name.Contains("Set-Cookie")) {
            // Grab the cookie
            var cookie : Fiddler.HTTPHeaderItem = oSession.oResponse.headers[x];
            // Now do something with the cookie
            // ...
            // ...
            // Now put the cookie back
            oSession.oResponse.headers[x] = cookie;
        }
    }
}

But what happens is that none of the cookies in oSession.oResponse.headers are being set in the browser at all.

Nick Iliev
Telerik team
commented on 09 Dec 2021, 10:16 AM

Check if you are streaming the response and note that depending don't that, that would change when Fiddler has received the response and when it can be modified (and when it is too late). Refer to this thread related to FiddlerCore but it is pretty much valid for FiddlerScript code.

https://groups.google.com/g/httpfiddler/c/QsbegBlc-RA

 

No answers yet. Maybe you can help?

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