Skip to content

Commit

Permalink
feat(headers): allow headers to be array per new undici behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
djMax committed Apr 7, 2024
1 parent 8167773 commit 0f71813
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
plugins
user_trunk.yaml
user.yaml
tmp
24 changes: 12 additions & 12 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface FetchRequest {
method: string;
origin: string;
path: string;
headers: string;
headers: string | string[];
}

interface FetchResponse {
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 0f71813

Please sign in to comment.