Skip to content

Commit

Permalink
fix: add user-agent header (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Meyerowitz authored Aug 1, 2023
1 parent 9008324 commit 90e93ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/api/request-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ describe("getHeaders", () => {
it("should always add json Content-Type header", () => {
expect(getHeaders({})).toEqual({
"Content-Type": "application/json; charset=utf-8",
"User-Agent": "commonbase-js/0.0.0",
});
});

it("should add _extraHeaders from ClientOptions", () => {
expect(getHeaders(mockClientOptions)).toEqual({
...mockClientOptions._extraHeaders,
"Content-Type": "application/json; charset=utf-8",
"User-Agent": "commonbase-js/0.0.0",
});
});
});
2 changes: 2 additions & 0 deletions client/api/request-util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { version } from "../../package.json";
import type {
ClientOptions,
CompletionConfig,
Expand All @@ -13,6 +14,7 @@ export function getUrl(path: string, options?: ClientOptions) {
export function getHeaders(options: ClientOptions) {
return {
...options._extraHeaders,
"User-Agent": `commonbase-js/${version}`,
"Content-Type": "application/json; charset=utf-8",
};
}
Expand Down

0 comments on commit 90e93ae

Please sign in to comment.