Skip to content
Commitwise
Menu

Interceptor (OkHttp)

Code that sees every HTTP request and response passing through an OkHttp client, used to add headers, log, or measure.

Definition

An interceptor receives the outgoing request, can change it (for example adding an Authorization header), passes it on with chain.proceed(), and can inspect or change the response. Application interceptors run once per call; network interceptors see every network attempt, including redirects. Token refresh on 401 belongs in an Authenticator, which OkHttp calls when the server rejects the credentials.

In practice

An AuthInterceptor adds "Bearer <token>" to every request, so no Retrofit function has to mention the token.

Related terms

Esc

Type to search the whole site.