Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Set x-throttle header if config is true (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxolofsson1 authored Nov 30, 2023
1 parent d4ba9d8 commit 8920176
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
},
"livesInGcp": [
"some"
]
],
"setXThrottle": true
}
3 changes: 3 additions & 0 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ function buildHeaders(params, headers = {}) {
if (params.correlationId) {
defaults["x-correlation-id"] = params.correlationId;
}
if (config.setXThrottle) {
defaults["x-throttle"] = "yes";
}
return { ...defaults, ...headers };
}

Expand Down
7 changes: 7 additions & 0 deletions test/lib/http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ describe("http", () => {
result.should.eql({ ok: true });
});
});
describe("x-throttle", () => {
it("should append x-throttle header", async () => {
fakeApi.get("/some/path").matchHeader("x-throttle", "yes").reply(200, { ok: true });
const result = await http.asserted.get({ path: "/some/path" });
result.should.eql({ ok: true });
});
});
describe("google auth other base url with audience", () => {
it("should append auth header", async () => {
fakeApiOld.get("/not-some/path").matchHeader("Authorization", "Bearer some-gcp-token").reply(200, { ok: true });
Expand Down

0 comments on commit 8920176

Please sign in to comment.