grafana / k6-jslib-aws

Javascript Library allowing to interact with AWS resources from k6 scripts
Apache License 2.0
18 stars 29 forks source link

Disregard `K6_DISCARD_RESPONSE_BODIES` #114

Closed oleiade closed 1 week ago

oleiade commented 1 month ago

What

This Pull Request addresses #45, namely ignoring k6's discardResponseBodies and always returning response bodies obtained from jslib-aws HTTP calls.

How

In this PR, we introduce a baseRequestParams member in the AWSClient class, which we add to every request made by children class implementations.

Using the baseRequestParams we set the default responseType for children implementation, allowing us to effectively disregard the http discardResponseBodies option. We can still, locally, override it where necessary, as in S3Client.getObject, for instance.

Demo

The following script:

//... 

export default async function () {
    // List the buckets the AWS authentication configuration
    // gives us access to.
    const buckets = await s3.listBuckets()

    console.log(JSON.stringify(buckets))

    const responseWithBody = http.get('https://httpbin.org/get')
    console.log(responseWithBody.body)
}

Will display something along the lines of:

[INFO] {"some": "content"}
[INFO] []

References

closes #45