Skip to content

Commit

Permalink
fix: add hiro product header to default network fetch function
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Sep 18, 2023
1 parent debeb00 commit c14ea95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/network/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import 'cross-fetch/polyfill';
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
const defaultFetchOpts: RequestInit = {
// By default referrer value will be client:origin: above reference link
referrerPolicy: 'origin', // Use origin value for referrer policy
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
referrerPolicy: 'origin', // Use origin value for referrer policy
headers: {
'x-hiro-product': 'stacksjs',
},
};

/**
Expand Down
7 changes: 6 additions & 1 deletion packages/network/tests/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { fetchWrapper, getFetchOptions, setFetchOptions } from '../src/fetch';
test('Verify fetch private options', async () => {
const defaultOptioins = getFetchOptions();

expect(defaultOptioins).toEqual({ referrerPolicy: 'origin' });
expect(defaultOptioins).toEqual({
referrerPolicy: 'origin',
headers: {
'x-hiro-product': 'stacksjs',
},
});

// Override default options when fetchPrivate is called internally by other stacks.js libraries like transactions or from server side
// This is for developers as they cannot directly pass options directly in fetchPrivate
Expand Down

0 comments on commit c14ea95

Please sign in to comment.