Skip to content

Commit

Permalink
filter supplied headers (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
baked-dev authored Dec 12, 2022
1 parent 9afc305 commit 37bcc17
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "whop-sdk-ts",
"version": "0.0.4-canary.0",
"version": "0.0.4-canary.1",
"private": true,
"workspaces": [
"apps/*",
Expand Down
12 changes: 11 additions & 1 deletion packages/core/request/browser/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,20 @@ const getHeaders = async (
const password = await resolve(options, config.PASSWORD);
const additionalHeaders = await resolve(options, config.HEADERS);

const suppliedHeaders = Object.entries(options.headers || {})
.filter(([_, value]) => isDefined(value))
.reduce(
(headers, [key, value]) => ({
...headers,
[key]: String(value),
}),
{} as Record<string, string>
);

const headers = Object.entries({
Accept: "application/json",
...additionalHeaders,
...options.headers,
...suppliedHeaders,
})
.filter(([_, value]) => isDefined(value))
.reduce(
Expand Down
12 changes: 11 additions & 1 deletion packages/core/request/node/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,20 @@ const getHeaders = async (
const password = await resolve(options, config.PASSWORD);
const additionalHeaders = await resolve(options, config.HEADERS);

const suppliedHeaders = Object.entries(options.headers || {})
.filter(([_, value]) => isDefined(value))
.reduce(
(headers, [key, value]) => ({
...headers,
[key]: String(value),
}),
{} as Record<string, string>
);

const headers = Object.entries({
Accept: "application/json",
...additionalHeaders,
...options.headers,
...suppliedHeaders,
})
.filter(([_, value]) => isDefined(value))
.reduce(
Expand Down

0 comments on commit 37bcc17

Please sign in to comment.