File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments