Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to use addUnsafeNonAscii header on Request.Builder #7275

Closed
iruizmar opened this issue May 11, 2022 · 1 comment
Closed

Possibility to use addUnsafeNonAscii header on Request.Builder #7275

iruizmar opened this issue May 11, 2022 · 1 comment
Labels
enhancement Feature not a bug

Comments

@iruizmar
Copy link

When trying to add new headers inside an interceptor, I usually do the following:

OkHttpClient.Builder()
    .addInterceptor { chain ->
        chain.proceed(
             chain.request()
                 .newBuilder()
                 .addHeader(X, Y)
                 .build()
        )
    }

But what if I want to use the internal header builder addUnsafeNonAscii method? There isn't any shortcut for that.
The workaround is something like:

OkHttpClient.Builder()
    .addInterceptor { chain ->
        chain.proceed(
             chain.request()
                 .newBuilder()
                 //We need to use headers already in the request.
                 .headers(chain.request().headers.newBuilder().apply {
                     addUnsafeNonAscii(X, Y)
                 }.build())
                 .build()
        )
    }

It would be easy to add a new addUnsafeNonAscii method to Request.Builder that will use the internal header builder's addUnsafeNonAscii.

@iruizmar iruizmar added the enhancement Feature not a bug label May 11, 2022
@yschimke
Copy link
Collaborator

This was a deliberate API decision #4296 (comment)

I think it's the right call, technically possible but not a suggestion on the easy path. Since it's possible but more verbose, I'm going to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature not a bug
Projects
None yet
Development

No branches or pull requests

2 participants