MCPcopy Index your code
hub / github.com/angular/angular / constructor

Method constructor

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

Constructs a new HTTP header object with the given values.

(
    headers?: string | {[name: string]: string | number | (string | number)[]} | Headers,
  )

Source from the content-addressed store, hash-verified

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 }
82
83 /**
84 * Checks for existence of a given header.

Callers

nothing calls this directly

Calls 6

addHeaderEntryMethod · 0.95
setHeaderEntriesMethod · 0.95
assertValidHeadersFunction · 0.85
indexOfMethod · 0.80
forEachMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected