2
votes

I'm trying to find a way to get response headers such as X-RateLimit-Limit, X-RateLimit-Remaining etc. from http call response. Not able to find from online resources or documentation, can someone help? I see these headers in console as I enabled logging but don't know how to retrieve these headers from response.

http("Get API")
      .get("https://hello.com/list")
      .header("Authorization", "${auth}")
      .check(status.is(200))
      .check(bodyString.saveAs("Auth_Response"))

Also is there a way to run this http call multiple times within a timeframe. What in-built methods should i use for looping as well running this specific http call within certain time limit? I tried below but unsuccessful. Ideally I would want to be able to verify this APIs rate limit hence tried this way. Although I'm getting to understand that I can't use repeat() duration() both at the same time however they serve 2 different purpose which I want to achieve. Even just calling http request builder type call in duration() is throwing error - "it doesn't conform to expected type ChainBuilder"

val scn1 =
during (60.seconds) {
  scenario("Setup scenario")
    .repeat(201){
      exec(
      http("Get API")
        .get("https://hello.com/list")
        .header("Authorization", "${auth}")
    )}
  setUp(
    scn1.inject(
      atOnceUsers(1)
    )
  )
}

Whether I put setup () inside during() or outside, its causing error. I am trying to evaluate if I even need during().When using just repeat(201) it causing the API to run 201 times and reducing the count of X-RateLimit-Remaining for api however not enough to reach it to 0 causing the error code response. Kindly provide any suggestions?

1

1 Answers

4
votes

it's in the cheat sheet at https://gatling.io/docs/current/cheat-sheet/

.check(header(headerName)).is(...)