MCPcopy
hub / github.com/angular/angular / HttpHeaders

Class HttpHeaders

packages/common/http/src/headers.ts:24–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 * @publicApi
23 */
24export class HttpHeaders {
25 /**
26 * Internal map of lowercase header names to values.
27 */
28 private headers!: Map<string, string[]>;
29
30 /**
31 * Internal map of lowercased header names to the normalized
32 * form of the name (the form seen first).
33 */
34 private normalizedNames: Map<string, string> = new Map();
35
36 /**
37 * Complete the lazy initialization of this object (needed before reading).
38 */
39 private lazyInit!: HttpHeaders | Function | null;
40
41 /**
42 * Queued updates to be materialized the next initialization.
43 */
44 private lazyUpdate: Update[] | null = null;
45
46 /** Constructs a new HTTP header object with the given values.*/
47
48 constructor(
49 headers?: string | {[name: string]: string | number | (string | number)[]} | Headers,
50 ) {
51 if (!headers) {
52 this.headers = new Map<string, string[]>();
53 } else if (typeof headers === 'string') {
54 this.lazyInit = () => {
55 this.headers = new Map<string, string[]>();
56 headers.split('\n').forEach((line) => {
57 const index = line.indexOf(':');
58 if (index > 0) {
59 const name = line.slice(0, index);
60 const value = line.slice(index + 1).trim();
61 this.addHeaderEntry(name, value);
62 }
63 });
64 };
65 } else if (typeof Headers !== 'undefined' && headers instanceof Headers) {
66 this.headers = new Map<string, string[]>();
67 headers.forEach((value: string, name: string) => {
68 this.addHeaderEntry(name, value);
69 });
70 } else {
71 this.lazyInit = () => {
72 if (typeof ngDevMode === 'undefined' || ngDevMode) {
73 assertValidHeaders(headers);
74 }
75 this.headers = new Map<string, string[]>();
76 Object.entries(headers).forEach(([name, values]) => {
77 this.setHeaderEntries(name, values);
78 });
79 };
80 }
81 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…