Home > Net >  How to avoid sending null headers in gatling http request?
How to avoid sending null headers in gatling http request?

Time:01-06

I'm trying to setup a HTTP request using feeders in Gatling, but I'm struggling not to send headers if the value of a property is null.

For example, given I have the following CSV file where the second record for prop_2 is null:

prop_1,prop_2
val_1,val_1
val_2,
val_3,val_3

And the given Gatling test config (part of it at least):

val feeder = csv("values.csv").random

val req1 =
  feed(feeder)
  .exec(
    http("Request 1")
      .get("/endpoint")
      .headers(Map(
        "prop_1", "#{prop_1}",
        "prop_2", "#{prop_2}" // Header not to send when value is null
      ))
  )

When there are null values I don't want to send the headers with empty values as part of the request, because the Back-end only expects headers with values. For while I have to create two CSV files with different properties (not mixing records with null values) and two requests, this is cumbersome and complex do handle.

Is there a better way to handle this use case?

CodePudding user response:

It's currently not possible to define a dynamic set of headers, only dynamic header values.

Please explain your actual use case. Why do you have optional headers?

because the Back-end only expects headers with values

Note: HTTP headers with an empty value (that's what you have, not a null value) are perfectly valid according to the HTTP spec. Your back-end not being able to handle them is a bug on its side.

  • Related