MCPcopy Create free account
hub / github.com/angular/angular / assertValidHeaders

Function assertValidHeaders

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

* Verifies that the headers object has the right shape: the values * must be either strings, numbers or arrays. Throws an error if an invalid * header value is present.

(
  headers: Record<string, unknown> | Headers,
)

Source from the content-addressed store, hash-verified

281 * header value is present.
282 */
283function assertValidHeaders(
284 headers: Record<string, unknown> | Headers,
285): asserts headers is Record<string, string | string[] | number | number[]> {
286 for (const [key, value] of Object.entries(headers)) {
287 if (!(typeof value === 'string' || typeof value === 'number') && !Array.isArray(value)) {
288 throw new Error(
289 `Unexpected value of the \`${key}\` header provided. ` +
290 `Expecting either a string, a number or an array, but got: \`${value}\`.`,
291 );
292 }
293 }
294}

Callers 1

constructorMethod · 0.85

Calls 2

isArrayMethod · 0.80
entriesMethod · 0.45

Tested by

no test coverage detected