SignatureCalculator in 3.7

Hello

i try to reproduce this exec ( old SignatureCalculator) and i have 2 questions

https://github.com/gatling/gatling/blob/main/gatling-http/src/test/scala/io/gatling/http/compile/HttpCompileTest.scala

.exec(
http(“Request”)
.get("/foo/bar?baz=qix")
.sign((request, session) => {
import java.util.Base64
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
val mac = Mac.getInstance(“HmacSHA256”)
mac.init(new SecretKeySpec(“THE_SECRET_KEY”.getBytes(“UTF-8”), “HmacSHA256”))
val rawSignature = mac.doFinal(request.getUri.getQuery.getBytes(“UTF-8”))
val authorization = Base64.getEncoder.encodeToString(rawSignature)
request.getHeaders.add(“Authorization”, authorization)
}) )

  1. But it seems that the Authorization is not add to Headers when analyzing the log of the complete request

  2. if i want to use a json request to be encoded and add the to Authorization headers , how can i do it ?

Thanks in advance for the help

Regards

Hi again
Maybe can someone tell me if i don’t use it correctly ?
When i execut it , only the content-type header is send , the Authorization is not add to the request as expected

val httpProtocol = http
.disableCaching
.header(“content-type” , “application/json”)
.baseUrl(“https://google.com”)

val scn = scenario(“Scenario Name”)
.exec(http(“Name”)
.post("/")
.sign((request, session) => {
import java.util.Base64
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
val mac = Mac.getInstance(“HmacSHA256”)
mac.init(new SecretKeySpec(“MYSECRETKEY”.getBytes(“UTF-8”), “HmacSHA256”))
val rawSignature = mac.doFinal(request.getUri.getQuery.getBytes(“UTF-8”))
val authorization = Base64.getEncoder.encodeToString(rawSignature)

request.getHeaders.add(“Authorization”, authorization)
})
)

regards