Question: why gatling doesn't redirect to link pointed within 302 response header

Hello,

Would someone help me as seems I’m stuck. Any help or idea would be highly appreciated.

Gatling script looks simple:

Enter code here...

import io.gatling.core.Predef._
import io.gatling.http.Predef._

import scala.concurrent.duration._

class Authorize extends Simulation with SimulationConfig {

  val feeder = jsonFile("users.json").random
  val httpProtocol = http.baseURL(getHostURL("idpHost"))
    .disableResponseChunksDiscarding

  val scn = scenario("authorizeWithIdentity").repeat(requests) {
    feed(feeder)
      .exec(addCookie(Cookie("IDENTITY",  "${identity}")))
      .exec(addCookie(Cookie("IDENTITY-HTTPS",  "${identity-https}")))
      .exec(
        http("Authorize")
          .get(getApiLink).basicAuth("${login}", "${password}")
          .headers(getHeadersMap)
          .queryParamMap(getQueryAndSubstituteParamMap)
      )
  }

  setUp(
    scn.inject(
      rampUsers(maxUsers) over (rampTime minutes)
    )
  ).maxDuration(timeLimit minutes).protocols(httpProtocol)

...

}

It is very hard to provide the full log on public place but I will try to explain the gatling behavior so maybe someone gives me idea what’s wrong with my script or setup.

Flow is following:

  1. Gatling sends request to URL1 and get 301 response with Location = URL2
  2. Gatling follows by URL2 and receive 302 response with URL1 within Location header
  3. Gatling instead of URL1 continuously (here I got into an infinite loop) sends requests to URL2

Hopefully I have explained enough to figure out my mistake :slight_smile:

BR/Dmitry.

Sorry, I have forgotten to specify gatling version:

gatling-charts-highcharts = 2.1.7
gatling-maven-plugin = 2.1.7

So it’s the last version.

In case gatling literally proceeding by the specification - is there any way to tell to gatling to treat 301 response in the same way as 302?

PS: I cannot change the application under test.

BR/D

Hi,

So Gatling stops following redirects at some point, right?
It seems weird: there’s a way to set a limit on redirects as a protection against infinite redirect loops (HttpProtocol.maxRedirects) but it’s disabled by default.

Go in debug mode and check the actually HTTP responses if the Location header is indeed there.

Otherwise, I’m afraid you’ll have to provide a reproducer.

Cheers,

Actually, Gatling is doing what 301 response expecting by the specification - requested URL permanently moved to location specified in Location header. That’s how I’m understanding the actual Gatling behavior.

But… other clients respond in different way. So the 301 → 302 chain still able to redirect to the initial location. But seems as Gatling substituting the initial location by the location specified within 301 response.

In case such behavior is not what expected then I would be happy to provide more details but privately. In case 301 response from the server does permanently trigger the substitution mechanism on Gatling side then is there any way how to customize Gatling behavior so 301 response from the server will be treated in the same way as 302 one?

BR/D

A 301 is permanent, so it can be cached.
Once a virtual has already experienced a 301 from URL1 to URL2, it’s expected that later requests to URL1 would directly jump to URL2.
Then, it’s possible that we take some shortcuts in computing the key (should be the whole entity, but we probably only use method + URI).

The question is “how does a standard web browser” behave in your case?
And then, please provide a reproducer, even privately.

Cheers,

Hello, thank you for the help.

The question is “how does a standard web browser” behave in your case?

This is where the problem comes from :slight_smile: The standard browsers some how do not follow the obvious rules and able to redirect to the initial URL1. To reproduce it you just have to have any server which does following pages:

Page1 (URL1): responds with 301 with Location = URL2 (Page2)
Page2 (URL2): responds with 302 with Location = URL1 (Page1)

And you will come to infinite loop in Gatling but some Firefox for example will show to you Page1 after 2 redirects.

I have double checked log and see that each redirect request contains Location values which cross referencing (in the same way as I explained before).

BR/D

As I said, I won’t be able to do anything without being able to access such a system.
I don’t have time to try and build one myself and shoot in the dark.