NG.VII · Angular 22 practice question

Consider an Angular application using a functional `HttpInterceptorFn` to attach an authentication token. The interceptor receives the outgoing `HttpRequest`. If the interceptor needs to read an `HttpContextToken` to change behavior for this request, which of the following describes the correct way to access that token?

Choose one answer
Check answer and explanation

Correct answer: Call `request.context.get(token)` where `token` is an `HttpContextToken`, then clone the request if needed.

Explanation

The `HttpInterceptor` interface is designed primarily to *modify* the request or *handle* the response chain. While Angular offers mechanisms for context, direct, easy access to a complex, route-bound `HttpContext` object from within the `intercept` method signature itself is not a standard, exposed feature for reading context tokens in the way one might expect from other parts of the framework (like when using advanced routing features). If specific context is needed, it is typically injected into the service/component initiating the call, or baked into the request itself (Option B, if the consuming code supports it). In the context of a generic interceptor pattern, the options A, B, and C are either incorrect assumptions or rely on non-standard extensions.

Common trap

Learners might assume that if a concept like `HttpContext` exists in the surrounding framework, it must be readable through the standard parameters of the interceptor methods, leading them to select A or C.

Source: Angular Guide on HTTP Interceptors, https://angular.dev/guide/http/interceptors
Checked against the cited text on 2026-11-27.

Report an error in this question