Skip to content

Commit 0db4123

Browse files
committed
Revert "refactor: initialize headers map directly in HttpHeaders class (angular#59268)"
This reverts commit e15226a.
1 parent 9db23f9 commit 0db4123

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/common/http/src/headers.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export class HttpHeaders {
2323
/**
2424
* Internal map of lowercase header names to values.
2525
*/
26-
private headers: Map<string, string[]> = new Map();
26+
// TODO(issue/24571): remove '!'.
27+
private headers!: Map<string, string[]>;
2728

2829
/**
2930
* Internal map of lowercased header names to the normalized
@@ -46,9 +47,11 @@ export class HttpHeaders {
4647
constructor(
4748
headers?: string | {[name: string]: string | number | (string | number)[]} | Headers,
4849
) {
49-
if (!headers) return;
50-
if (typeof headers === 'string') {
50+
if (!headers) {
51+
this.headers = new Map<string, string[]>();
52+
} else if (typeof headers === 'string') {
5153
this.lazyInit = () => {
54+
this.headers = new Map<string, string[]>();
5255
headers.split('\n').forEach((line) => {
5356
const index = line.indexOf(':');
5457
if (index > 0) {
@@ -59,6 +62,7 @@ export class HttpHeaders {
5962
});
6063
};
6164
} else if (typeof Headers !== 'undefined' && headers instanceof Headers) {
65+
this.headers = new Map<string, string[]>();
6266
headers.forEach((value: string, name: string) => {
6367
this.addHeaderEntry(name, value);
6468
});
@@ -67,6 +71,7 @@ export class HttpHeaders {
6771
if (typeof ngDevMode === 'undefined' || ngDevMode) {
6872
assertValidHeaders(headers);
6973
}
74+
this.headers = new Map<string, string[]>();
7075
Object.entries(headers).forEach(([name, values]) => {
7176
this.setHeaderEntries(name, values);
7277
});

0 commit comments

Comments
 (0)