Skip to content

Commit ae443f8

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 216d883 commit ae443f8

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
@@ -391,6 +391,14 @@ class HttpResourceImpl<T>
391391
this.client = injector.get(HttpClient);
392392
}
393393

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

packages/common/http/test/resource_spec.ts

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

0 commit comments

Comments
 (0)