Skip to content

Commit e5d6fb5

Browse files
wartabthePunderWoman
authored andcommitted
fix(http): Reset headers, progress, and statusCode when using set() in HttpResource (#62873)
Currently, those values aren't reset, which means they are out of sync with the new value PR Close #62873
1 parent 7836f79 commit e5d6fb5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/common/http/src/resource.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,14 @@ class HttpResourceImpl<T>
393393
this.client = injector.get(HttpClient);
394394
}
395395

396+
override set(value: T): void {
397+
super.set(value);
398+
399+
this._headers.set(undefined);
400+
this._progress.set(undefined);
401+
this._statusCode.set(undefined);
402+
}
403+
396404
// This is a type only override of the method
397405
declare hasValue: () => this is HttpResourceRef<Exclude<T, undefined>>;
398406
}

packages/common/http/test/resource_spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,19 @@ describe('httpResource', () => {
323323
req = backend.expectOne('/data');
324324
req.flush([]);
325325
});
326+
327+
it('should reset past request data when using set()', async () => {
328+
const backend = TestBed.inject(HttpTestingController);
329+
const res = httpResource(() => '/data', {injector: TestBed.inject(Injector)});
330+
TestBed.tick();
331+
const req = backend.expectOne('/data');
332+
req.flush([]);
333+
await TestBed.inject(ApplicationRef).whenStable();
334+
335+
res.set([]);
336+
337+
expect(res.headers()).toBe(undefined);
338+
expect(res.progress()).toBe(undefined);
339+
expect(res.statusCode()).toBe(undefined);
340+
});
326341
});

0 commit comments

Comments
 (0)