Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global headers to the client #218

Merged
merged 7 commits into from
Dec 10, 2024
Merged

Add global headers to the client #218

merged 7 commits into from
Dec 10, 2024

Conversation

ytkimirti
Copy link
Contributor

@ytkimirti ytkimirti commented Dec 4, 2024

Example usecase:

import { Client } from "@upstash/qstash"

const client = new Client({
  token: "token",
  headers: {
    "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET,
  }
})

Copy link

linear bot commented Dec 4, 2024

@ytkimirti ytkimirti changed the title feat: add global headers to the client Add global headers to the client Dec 4, 2024
@CahidArda
Copy link
Contributor

can we add more tests? Here is what I would like to see:

  • create a client with headers: {"undefined-header": undefined, "TEST-HEADER": "override-value", "test-header": "override-value-ignored", "TEST-HEADER-2": "override-value-2"}. We should see that the headers are case insensitive, and batch shouldn't have two headers for test-header for instance.
  • for every method (publishJSON, batchJSON, enqueue, schedule): call the methods with headers like {"stays-the-same": "same", "test-header": "overridden-value"} and check the values of every header.

Comment on lines 287 to 296
private wrapWithGlobalHeaders(headers: Headers) {
const finalHeaders = new Headers(this.headers);

// eslint-disable-next-line unicorn/no-array-for-each
headers.forEach((value, key) => {
finalHeaders.set(key, value);
});

return finalHeaders;
}
Copy link
Collaborator

@fahreddinozcan fahreddinozcan Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private wrapWithGlobalHeaders(headers: Headers) {
const finalHeaders = new Headers(this.headers);
// eslint-disable-next-line unicorn/no-array-for-each
headers.forEach((value, key) => {
finalHeaders.set(key, value);
});
return finalHeaders;
}
private wrapWithGlobalHeaders(headers: Headers) {
const finalHeaders = new Headers(this.headers);
// eslint-disable-next-line unicorn/no-array-for-each
headers.forEach((key, value) => {
finalHeaders.set(key, value);
});
return finalHeaders;
}

Why do we even have this function? Are we trying to reverse the headers' key value? The user should already give them as

    const clientWithHeaders = new Client({
      token: process.env.QSTASH_TOKEN!,
      headers: {
        "test-header": "value",
        "test-header-2": "value-2",
      },
    });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is reversed in the api for no reason. It seemed weird to me too

@CahidArda
Copy link
Contributor

how about schedules & enqueue?

@CahidArda CahidArda merged commit 02394bb into main Dec 10, 2024
6 checks passed
@CahidArda CahidArda deleted the DX-1451 branch December 10, 2024 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants