Skip to content

Commit

Permalink
fix(common): include transferCache when cloning HttpRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
mlz11 committed Mar 19, 2024
1 parent 314112d commit b07fbb4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/common/http/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
body?: T | null;
method?: string;
url?: string;
Expand All @@ -452,6 +453,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
body?: V | null;
method?: string;
url?: string;
Expand All @@ -466,18 +468,20 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
body?: any | null;
method?: string;
url?: string;
setHeaders?: {[name: string]: string | string[]};
setParams?: {[param: string]: string};
} = {},
): HttpRequest<any> {
// For method, url, and responseType, take the current value unless
// For method, url, responseType and transferCache take the current value unless
// it is overridden in the update hash.
const method = update.method || this.method;
const url = update.url || this.url;
const responseType = update.responseType || this.responseType;
const transferCache = update.transferCache || this.transferCache;

// The body is somewhat special - a `null` value in update.body means
// whatever current body is present is being overridden with an empty
Expand Down
5 changes: 5 additions & 0 deletions packages/common/http/test/request_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('HttpRequest', () => {
reportProgress: true,
responseType: 'text',
withCredentials: true,
transferCache: true,
});
it('in the base case', () => {
const clone = req.clone();
Expand All @@ -87,6 +88,7 @@ describe('HttpRequest', () => {
expect(clone.headers.get('Test')).toBe('Test header');

expect(clone.context).toBe(context);
expect(clone.transferCache).toBe(true);
});
it('and updates the url', () => {
expect(req.clone({url: '/changed'}).url).toBe('/changed');
Expand All @@ -101,6 +103,9 @@ describe('HttpRequest', () => {
const newContext = new HttpContext();
expect(req.clone({context: newContext}).context).toBe(newContext);
});
it('and updates the transferCache', () => {
expect(req.clone({transferCache: false}).transferCache).toBe(false);
});
});
describe('content type detection', () => {
const baseReq = new HttpRequest('POST', '/test', null);
Expand Down

0 comments on commit b07fbb4

Please sign in to comment.