Skip to content

Commit ab60339

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 55e575a commit ab60339

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
@@ -58,12 +58,15 @@ function addBody<T>(
5858
reportProgress: options.reportProgress,
5959
responseType: options.responseType,
6060
withCredentials: options.withCredentials,
61+
credentials: options.credentials,
6162
transferCache: options.transferCache,
6263
keepalive: options.keepalive,
6364
priority: options.priority,
6465
cache: options.cache,
6566
mode: options.mode,
6667
redirect: options.redirect,
68+
integrity: options.integrity,
69+
referrer: options.referrer,
6770
};
6871
}
6972

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)