Skip to content

Commit 93f49de

Browse files
committed
fix: add required headers
Signed-off-by: Vikram Vaswani <2571660+vvaswani@users.noreply.github.com>
1 parent 6c2d07d commit 93f49de

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/hooks/registration.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,28 @@ export function initHooks(_hooks: Hooks) {
1010
// Add hooks by calling hooks.register{ClientInit/BeforeCreateRequest/BeforeRequest/AfterSuccess/AfterError}Hook
1111
// with an instance of a hook that implements that specific Hook interface
1212
// Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
13+
_hooks.registerBeforeCreateRequestHook({
14+
beforeCreateRequest(hookCtx, input) {
15+
const { httpReferer, xTitle } = hookCtx.options;
16+
if (!httpReferer && !xTitle) {
17+
return input;
18+
}
19+
20+
const headers = new Headers(input.options?.headers);
21+
if (httpReferer && !headers.has("HTTP-Referer")) {
22+
headers.set("HTTP-Referer", httpReferer);
23+
}
24+
if (xTitle && !headers.has("X-Title")) {
25+
headers.set("X-Title", xTitle);
26+
}
27+
28+
return {
29+
...input,
30+
options: {
31+
...input.options,
32+
headers,
33+
},
34+
};
35+
},
36+
});
1337
}

0 commit comments

Comments
 (0)