From 8920176cb54f1c4e010777ec33208a98abd6a046 Mon Sep 17 00:00:00 2001 From: Max Olofsson Date: Thu, 30 Nov 2023 15:16:40 +0100 Subject: [PATCH] Set x-throttle header if config is true (#44) --- config/test.json | 3 ++- lib/http.js | 3 +++ test/lib/http.test.js | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config/test.json b/config/test.json index 8d8f238..6dacee8 100644 --- a/config/test.json +++ b/config/test.json @@ -14,5 +14,6 @@ }, "livesInGcp": [ "some" - ] + ], + "setXThrottle": true } diff --git a/lib/http.js b/lib/http.js index b3b16ef..c3eebd3 100644 --- a/lib/http.js +++ b/lib/http.js @@ -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 }; } diff --git a/test/lib/http.test.js b/test/lib/http.test.js index ebe53a7..61557a4 100644 --- a/test/lib/http.test.js +++ b/test/lib/http.test.js @@ -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 });