Skip to content
Closed
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
2 changes: 2 additions & 0 deletions packages/common/http/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ function normalizeRequest(
reportProgress: unwrappedRequest.reportProgress,
withCredentials: unwrappedRequest.withCredentials,
responseType,
context: unwrappedRequest.context,
transferCache: unwrappedRequest.transferCache,
},
);
}
Expand Down
42 changes: 41 additions & 1 deletion packages/common/http/test/resource_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

import {ApplicationRef, Injector, signal} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {HttpEventType, provideHttpClient, httpResource} from '@angular/common/http';
import {
HttpEventType,
provideHttpClient,
httpResource,
HttpContext,
HttpContextToken,
} from '@angular/common/http';
import {HttpTestingController, provideHttpClientTesting} from '@angular/common/http/testing';

describe('httpResource', () => {
Expand Down Expand Up @@ -145,6 +151,40 @@ describe('httpResource', () => {
expect(res.value()).toEqual([]);
});

it('should pass all request parameters', () => {
const backend = TestBed.inject(HttpTestingController);

const CTX_TOKEN = new HttpContextToken(() => 'value');
const res = httpResource(
() => ({
url: '/data',
params: {
'fast': 'yes',
},
responseType: 'text', // This one is not overwritten (and no excess property check from ts)
headers: {
'X-Tag': 'alpha,beta',
},
reportProgress: true,
context: new HttpContext().set(CTX_TOKEN, 'bar'),
withCredentials: true,
transferCache: {includeHeaders: ['Y-Tag']},
}),
{
injector: TestBed.inject(Injector),
},
);
TestBed.flushEffects();

const req = TestBed.inject(HttpTestingController).expectOne('/data?fast=yes');
expect(req.request.headers.get('X-Tag')).toEqual('alpha,beta');
expect(req.request.responseType).toEqual('json');
expect(req.request.withCredentials).toEqual(true);
expect(req.request.context.get(CTX_TOKEN)).toEqual('bar');
expect(req.request.reportProgress).toEqual(true);
expect(req.request.transferCache).toEqual({includeHeaders: ['Y-Tag']});
});

it('should allow mapping data to an arbitrary type', async () => {
const backend = TestBed.inject(HttpTestingController);
const res = httpResource(
Expand Down