TransformResponse in Gatling 3?

Hi guys.

I am using the response transformation in my requests, in 2.3 I did it this way:

.transformResponse {
  case response if response.statusCode.contains(200) =>
    new ResponseWrapper(response) {
      override val body: ByteArrayResponseBody = getResponsePayload(response)
    }
}

response.statusCode was null safe, as far as I can tell; in Gatling 3 I made this construct, according to the documentation (https://gatling.io/docs/current/http/http_request/#response-transformers):

.transformResponse {
  (_, response) =>
    if (response.status.code == 200) {
      response.copy(body = getResponsePayload(response))
    }
    else {
      response
    }
}

Is this approach null safe? Is there a better way?

Thanks.

P.S. Stephane, if you happen to read this, you have a typo in the documentation link above - surely you guys meant “ignore when code is not 200”?

  // ignore when response status code is 200
  .transformResponse {
    (session, response) =>
      if (response.status.code == 200) {
        response.copy(body = new ByteArrayResponseBody(Base64.getDecoder.decode(response.body.string), UTF_8))
      } else {
        response
      }
  }

Is this approach null safe?

Yes

P.S. Stephane, if you happen to read this, you have a typo in the documentation link above - surely you guys meant “ignore when code is not 200”?

Absolutely.
Thanks for reporting.

Stéphane Landelle

GatlingCorp CTO
slandelle@gatling.io