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

Class HttpContext

packages/common/http/src/context.ts:55–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53 * @publicApi
54 */
55export class HttpContext {
56 private readonly map = new Map<HttpContextToken<unknown>, unknown>();
57
58 /**
59 * Store a value in the context. If a value is already present it will be overwritten.
60 *
61 * @param token The reference to an instance of `HttpContextToken`.
62 * @param value The value to store.
63 *
64 * @returns A reference to itself for easy chaining.
65 */
66 set<T>(token: HttpContextToken<T>, value: T): HttpContext {
67 this.map.set(token, value);
68 return this;
69 }
70
71 /**
72 * Retrieve the value associated with the given token.
73 *
74 * @param token The reference to an instance of `HttpContextToken`.
75 *
76 * @returns The stored value or default if one is defined.
77 */
78 get<T>(token: HttpContextToken<T>): T {
79 if (!this.map.has(token)) {
80 this.map.set(token, token.defaultValue());
81 }
82 return this.map.get(token) as T;
83 }
84
85 /**
86 * Delete the value associated with the given token.
87 *
88 * @param token The reference to an instance of `HttpContextToken`.
89 *
90 * @returns A reference to itself for easy chaining.
91 */
92 delete(token: HttpContextToken<unknown>): HttpContext {
93 this.map.delete(token);
94 return this;
95 }
96
97 /**
98 * Checks for existence of a given token.
99 *
100 * @param token The reference to an instance of `HttpContextToken`.
101 *
102 * @returns True if the token exists, false otherwise.
103 */
104 has(token: HttpContextToken<unknown>): boolean {
105 return this.map.has(token);
106 }
107
108 /**
109 * @returns a list of tokens currently stored in the context.
110 */
111 keys(): IterableIterator<HttpContextToken<unknown>> {
112 return this.map.keys();

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…