Skip to content

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

Description

@Prithuld

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions