From 54702b967d41ad5ec98b2257edef1b182fefa3ae Mon Sep 17 00:00:00 2001 From: oleiade Date: Tue, 30 Jul 2024 15:58:42 +0200 Subject: [PATCH] Add baseRequestParams to AWSClient This allow us to ignore k6's discardResponseBodies in the context of jslib-aws. As it is mostly a utility library, users have been mostly about having the ability available. See #45 for details. 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. --- src/internal/client.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/internal/client.ts b/src/internal/client.ts index 5122647..bc4cde5 100644 --- a/src/internal/client.ts +++ b/src/internal/client.ts @@ -1,4 +1,4 @@ -import { RefinedResponse, ResponseType } from 'k6/http' +import { RefinedResponse, ResponseType, Params } from 'k6/http' import { AWSConfig } from './config' import { Endpoint } from './endpoint' @@ -27,6 +27,22 @@ export class AWSClient { readonly awsConfig: AWSConfig readonly serviceName: string + // Because jslib-aws is mostly used as a way to setup or feed k6 tests, and + // we want the jslib-aws to be able to disregard k6's discardResponseBodies: meaning + // that for instance, even when setting discardResponseBodies to true in the k6 options, using + // s3.getObject still receives the underlying response body and returns data to the user. + // + // To achieve this, we set the responseType to 'text' in the baseRequestParams, as it + // will lead the http module to ignore the discardResponseBodies option. + // + // AWS Client classes can override this value if they want to receive the response body + // as a different type ('binary' for instance, e.g. S3Client.getObject). + // + // See #45: import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js' + readonly baseRequestParams: Params = { + responseType: 'text', + } + private _endpoint?: Endpoint /**