From 0f718137486d24c1c60b8a1a90c36ae012110dd0 Mon Sep 17 00:00:00 2001 From: Max Metral Date: Sun, 7 Apr 2024 11:32:25 -0400 Subject: [PATCH] feat(headers): allow headers to be array per new undici behavior --- .trunk/.gitignore | 1 + .trunk/trunk.yaml | 24 ++++++++++++------------ src/index.ts | 12 ++++++++---- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.trunk/.gitignore b/.trunk/.gitignore index 1e24652..15966d0 100644 --- a/.trunk/.gitignore +++ b/.trunk/.gitignore @@ -6,3 +6,4 @@ plugins user_trunk.yaml user.yaml +tmp diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 8a993f9..256c1e1 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -2,11 +2,11 @@ # To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml version: 0.1 cli: - version: 1.17.2 + version: 1.21.0 plugins: sources: - id: trunk - ref: v1.2.6 + ref: v1.4.5 uri: https://github.com/trunk-io/plugins runtimes: enabled: @@ -15,18 +15,18 @@ runtimes: - python@3.10.8 lint: enabled: - - actionlint@1.6.26 - - checkov@3.0.29 - - eslint@8.53.0 + - actionlint@1.6.27 + - checkov@3.2.53 + - eslint@8.57.0 - git-diff-check - - markdownlint@0.37.0 - - osv-scanner@1.4.3 - - prettier@3.0.3 - - shellcheck@0.9.0 + - markdownlint@0.39.0 + - osv-scanner@1.7.0 + - prettier@3.2.5 + - shellcheck@0.10.0 - shfmt@3.6.0 - - trivy@0.47.0 - - trufflehog@3.62.1 - - yamllint@1.32.0 + - trivy@0.50.1 + - trufflehog@3.71.0 + - yamllint@1.35.1 ignore: - linters: [ALL] paths: diff --git a/src/index.ts b/src/index.ts index 0c705ff..218c0cb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,7 +34,7 @@ interface FetchRequest { method: string; origin: string; path: string; - headers: string; + headers: string | string[]; } interface FetchResponse { @@ -179,9 +179,13 @@ export class FetchInstrumentation implements Instrumentation { this.config.onRequest({ request, span, additionalHeaders: addedHeaders }); } - request.headers += Object.entries(addedHeaders) - .map(([k, v]) => `${k}: ${v}\r\n`) - .join(''); + if (Array.isArray(request.headers)) { + request.headers.push(...Object.entries(addedHeaders).flat()); + } else { + request.headers += Object.entries(addedHeaders) + .map(([k, v]) => `${k}: ${v}\r\n`) + .join(''); + } this.spanFromReq.set(request, span); }