inferHtmlResources() with disableFollowRedirect()

I disabled the redirects on a global level for a simulation because i need to extract things from non-redirected responses.

But I would also like to use the option “inferHtmlResources()”. This seems only to work if redirects are not disabled.

How can i let Gatling inver HTLM resources and still be able to extract the things from non-redirected responses?

Maybe I can intercept an immediate response and extract something from the response before it is redirected? But I have no idea if that can be done with Gatling or if there is another solution.

Can you please give me an advice how to solve that issue?

How can i let Gatling inver HTLM resources and still be able to extract the things from non-redirected responses?

You can’t.
Then, I would argue that if you need to do that, the requests are probably not dumb static resources but important requests that should be top level.

I disabled the redirects on a global level for a simulation because i need to extract things from non-redirected responses.

Are you sure about this?
Pretty sure you don’t need this:

  • don’t try to parse cookies, Gatling will handle them for you. And if you really need to access cookies, use the getCookieValue Gatling feature for this: Gatling - HTTP Helpers
  • don’t parse the Location response header to get information from the landing page, use the currentLocationRegex feature for this: Gatling - HTTP Checks

The load simulation is for a login/logout scenario which is not based on a common well known login mechanism.

For example when I the first request for the login, if I do not disable to follow redirects then the response will be a HTML page which contains nothing which I need for the next login request in the requests sequence.

But if i disable following redirects, then I can extract something specific from its response headers or JSON body which I need for the next request. The login is a sequence of requests.

I do not parse cookies, Gatling does that. Cookies are not my problem.

The location response header I do parse, so I can do that with the way you mentioned obviously. But I also need to extract something from the JSON response bodies before redirection and in one case even to save the status code, because depending on if it is 200 or 302 i need to call an additional request.

My next idea was not to disable follwoing redirects on a global level but to disable it for each request and then to add an additional requests before or after the requests which follows redirecs, just to let Gatling download the HTML resources. But then the test would not be so realistic anymore because these requests are called only once in a real sequence. But there should be a better way to do that I hope.

After this additonal information, do you have more suggestions?

What are your actual user-agents? Unless I’m mistaken, Web browsers won’t let even your JavaScript see the intermediate requests/responses in a redirect chain so you won’t be able to see the response JSON body there either. A redirect should be performed automatically. I really have the feeling that your custom process is not following the standard.

Anyway, you can disable redirect at request level: Gatling - HTTP Request

Just don’t do that in resources, which you’re login process definitely isn’t.

I set as user agent: “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36”

I cannot see the redirects in Chrome developer tools in the network tab, probably because of the reason you wrote.

I think I will try to use Gatling Recorder with HTTP proxy, enable follow redirects and infer HTML resources and see what Java classes it produces and if it can help me to find a good solution for my case.

I think i found a good solution for my issue.

In the sequence for login there are only a few requests where I need to disable following redirects. So I disable following redirects them only for these requests.

These requests contain in a header the URI to which it shall be redirected. So I execute a get request to that redirect URI after the request where I have disabled following redirects.

And of course I have to configure inferHtmlResources() for the HTTP protocol object.

The icing on the cake is to have a switch for all of that, for the load test with or without HTML resources, which i implemented, for the requests with the “doIf(…).then(…)” fluent methods.

Hi @thorin.bondy , I’m also interested in this use case, could you share an example code for studying too ? Much appreciated !
Cheers!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.