Thanks to visit codestin.com
Credit goes to github.com

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
6 changes: 6 additions & 0 deletions goldens/public-api/common/http/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,9 @@ 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 @@ -2117,6 +2120,9 @@ 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 Down
14 changes: 10 additions & 4 deletions 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,6 +468,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
body?: any | null;
method?: string;
url?: string;
Expand All @@ -479,6 +482,10 @@ export class HttpRequest<T> {
const url = update.url || this.url;
const responseType = update.responseType || this.responseType;

// Carefully handle the transferCache to differentiate between
// `false` and `undefined` in the update args.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now it also handles null so mayby add that to comment : undefined or null here and in other places that were edited. Also why not add move this logic together with withCredentials and reportProgress? becouse now
this comment is duplicated in lines 485 and 495

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
// body, whereas an `undefined` value in update.body implies no
Expand All @@ -487,10 +494,8 @@ export class HttpRequest<T> {

// Carefully handle the boolean options to differentiate between
// `false` and `undefined` in the update args.
const withCredentials =
update.withCredentials !== undefined ? update.withCredentials : this.withCredentials;
const reportProgress =
update.reportProgress !== undefined ? update.reportProgress : this.reportProgress;
const withCredentials = update.withCredentials ?? this.withCredentials;
const reportProgress = update.reportProgress ?? this.reportProgress;

// Headers and params may be appended to if `setHeaders` or
// `setParams` are used.
Expand Down Expand Up @@ -526,6 +531,7 @@ export class HttpRequest<T> {
reportProgress,
responseType,
withCredentials,
transferCache,
});
}
}
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