Skip to content

Commit

Permalink
Revert "refactor: initialize headers map directly in HttpHeaders class (
Browse files Browse the repository at this point in the history
angular#59268)"

This reverts commit e15226a.
  • Loading branch information
AndrewKushnir committed Jan 14, 2025
1 parent 9db23f9 commit 0db4123
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/common/http/src/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export class HttpHeaders {
/**
* Internal map of lowercase header names to values.
*/
private headers: Map<string, string[]> = new Map();
// TODO(issue/24571): remove '!'.
private headers!: Map<string, string[]>;

/**
* Internal map of lowercased header names to the normalized
Expand All @@ -46,9 +47,11 @@ export class HttpHeaders {
constructor(
headers?: string | {[name: string]: string | number | (string | number)[]} | Headers,
) {
if (!headers) return;
if (typeof headers === 'string') {
if (!headers) {
this.headers = new Map<string, string[]>();
} else if (typeof headers === 'string') {
this.lazyInit = () => {
this.headers = new Map<string, string[]>();
headers.split('\n').forEach((line) => {
const index = line.indexOf(':');
if (index > 0) {
Expand All @@ -59,6 +62,7 @@ export class HttpHeaders {
});
};
} else if (typeof Headers !== 'undefined' && headers instanceof Headers) {
this.headers = new Map<string, string[]>();
headers.forEach((value: string, name: string) => {
this.addHeaderEntry(name, value);
});
Expand All @@ -67,6 +71,7 @@ export class HttpHeaders {
if (typeof ngDevMode === 'undefined' || ngDevMode) {
assertValidHeaders(headers);
}
this.headers = new Map<string, string[]>();
Object.entries(headers).forEach(([name, values]) => {
this.setHeaderEntries(name, values);
});
Expand Down

0 comments on commit 0db4123

Please sign in to comment.