Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/common/http/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ export class HttpRequest<T> {
this.integrity = options.integrity;
}

if (options.referrer) {
if (options.referrer !== undefined) {
this.referrer = options.referrer;
}

Expand Down Expand Up @@ -734,7 +734,8 @@ export class HttpRequest<T> {
const mode = update.mode || this.mode;
const redirect = update.redirect || this.redirect;
const credentials = update.credentials || this.credentials;
const referrer = update.referrer || this.referrer;

const referrer = update.referrer ?? this.referrer;
const integrity = update.integrity || this.integrity;
const referrerPolicy = update.referrerPolicy || this.referrerPolicy;
// Carefully handle the transferCache to differentiate between
Expand Down
11 changes: 11 additions & 0 deletions packages/common/http/test/request_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ describe('HttpRequest', () => {
const req = new HttpRequest('GET', '/test', {referrer: 'about:client'});
expect(req.referrer).toBe('about:client');
});
it('should preserve an empty string referrer (used to suppress the Referer header)', () => {
const req = new HttpRequest('GET', '/test', {referrer: ''});
expect(req.referrer).toBe('');
});
it('should allow setting referrerPolicy option', () => {
const req = new HttpRequest('GET', '/test', {referrerPolicy: 'no-referrer'});
expect(req.referrerPolicy).toBe('no-referrer');
Expand Down Expand Up @@ -175,6 +179,13 @@ describe('HttpRequest', () => {
it('and updates the referrer', () => {
expect(req.clone({referrer: 'https://example.com'}).referrer).toBe('https://example.com');
});
it('and preserves an existing empty string referrer when the update omits it', () => {
const emptyReferrerReq = new HttpRequest('GET', '/test', {referrer: ''});
expect(emptyReferrerReq.clone().referrer).toBe('');
});
it('and can update the referrer to an empty string', () => {
expect(req.clone({referrer: ''}).referrer).toBe('');
});
it('and updates the integrity', () => {
expect(req.clone({integrity: 'sha512-...'}).integrity).toBe('sha512-...');
});
Expand Down
Loading