Skip to content

Commit 245494a

Browse files
SkyZeroZxthePunderWoman
authored andcommitted
fix(http): add missing http options allowed in fetch API (#62881)
The addBody function was not preserving all fetch API options like integrity and referrer when creating request options for POST/PUT/PATCH requests. This caused these options to be stripped out during request construction. PR Close #62881
1 parent d23c5e4 commit 245494a

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages/common/http/src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ function addBody<T>(
6161
reportProgress: options.reportProgress,
6262
responseType: options.responseType,
6363
withCredentials: options.withCredentials,
64+
credentials: options.credentials,
6465
transferCache: options.transferCache,
6566
timeout: options.timeout,
6667
keepalive: options.keepalive,
6768
priority: options.priority,
6869
cache: options.cache,
6970
mode: options.mode,
7071
redirect: options.redirect,
72+
integrity: options.integrity,
73+
referrer: options.referrer,
7174
};
7275
}
7376

packages/common/http/test/client_spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,41 @@ describe('HttpClient', () => {
148148
expect(testReq.request.body).toBe(body);
149149
testReq.flush('hello world');
150150
});
151+
it('validates all fetch API options are properly handled', (done) => {
152+
client
153+
.post(
154+
'/test',
155+
{},
156+
{
157+
credentials: 'include',
158+
cache: 'force-cache',
159+
priority: 'high',
160+
mode: 'cors',
161+
redirect: 'follow',
162+
referrer: 'www.example.com',
163+
integrity: 'sha256-abc',
164+
timeout: 1000,
165+
keepalive: true,
166+
withCredentials: true,
167+
},
168+
)
169+
.subscribe(() => {
170+
done();
171+
});
172+
const testReq = backend.expectOne('/test');
173+
expect(testReq.request.credentials).toBe('include');
174+
expect(testReq.request.cache).toBe('force-cache');
175+
expect(testReq.request.priority).toBe('high');
176+
expect(testReq.request.mode).toBe('cors');
177+
expect(testReq.request.redirect).toBe('follow');
178+
expect(testReq.request.referrer).toBe('www.example.com');
179+
expect(testReq.request.integrity).toBe('sha256-abc');
180+
expect(testReq.request.timeout).toBe(1000);
181+
expect(testReq.request.keepalive).toBe(true);
182+
expect(testReq.request.withCredentials).toBe(true);
183+
expect(testReq.request.body).toEqual({});
184+
testReq.flush({});
185+
});
151186
it('with a json body of false', (done) => {
152187
client.post('/test', false, {observe: 'response', responseType: 'text'}).subscribe((res) => {
153188
expect(res.ok).toBeTruthy();

0 commit comments

Comments
 (0)