#4635·retrofit

Retrofit loses modified request headers when wrapping okhttp3.Response to retrofit2.Response

Author: PrithuldCreated Jan 22, 2026Updated Aug 2, 2026

When an OkHttp interceptor modifies request headers, the modified headers are present in okhttp3.Response.request but are not preserved in retrofit2.Response.raw().request.

Steps to Reproduce:

  1. Create an interceptor that modifies request headers: updatedReq = originalReq.newBuilder().addHeader("X-Custom-Header", "some-value").build() httpResponse = chain.proceed(updatedReq)
  2. okhttp3.Response.request has the header ✅
  3. retrofit2.Response.raw().request.header("X-Custom-Header") returns null ❌

Expected Behavior: retrofit2.Response.raw().request should contain the same headers as okhttp3.Response.request (the modified request that was actually sent).

Actual Behavior: retrofit2.Response.raw().request contains the original request headers (before interceptor modifications).

Impact: Custom headers added by interceptors cannot be extracted from retrofit2.Response.raw().request, forcing workarounds like adding values to response headers.