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

Problems that occur when using --library okhttp4-gson configuration,version:3.0.50 #1206

Open
bai-xuan opened this issue Nov 6, 2023 · 5 comments

Comments

@bai-xuan
Copy link

bai-xuan commented Nov 6, 2023

The version I'm using is:3.0.50
image

Set debug mode, httpClient should not add Interceptor through httpClient.interceptors().add()

image

Because httpClient.interceptors() returns views that cannot be modified. The specific situation is as follows:

image
image
image

. My solution is:
image

@HugoMario
Copy link
Contributor

Thanks @bai-xuan for filing this issue. I have a doubt about your solution. Wouldn't that code replace any interceptor added previously?

@bai-xuan
Copy link
Author

bai-xuan commented Nov 9, 2023

Thanks @bai-xuan for filing this issue. I have a doubt about your solution. Wouldn't that code replace any interceptor added previously?

An immutable list will definitely not take effect, and he even reported an error

@bai-xuan
Copy link
Author

bai-xuan commented Nov 9, 2023

Thanks @bai-xuan for filing this issue. I have a doubt about your solution. Wouldn't that code replace any interceptor added previously?

The code where the problem occurs:
httpClient.interceptors().add(loggingInterceptor);

interceptors()
The implementation is:
@get:JvmName("interceptors") val interceptors: List =
builder.interceptors.toImmutableList()

toImmutableList()
The implementation is:

/** Returns an immutable copy of this. */
fun List.toImmutableList(): List {
return Collections.unmodifiableList(toMutableList())
}

@bai-xuan
Copy link
Author

bai-xuan commented Nov 9, 2023

It has been explained in detail in unmodifiableList:

image

@bai-xuan
Copy link
Author

bai-xuan commented Nov 9, 2023

Let me add one more thing,
in okhttp-2.7.5
The implementation of interceptors is like this:

image
image

What I'm talking about is using --library okhttp4-gson
His okhttp version is 4.10.0:
image

This is the implementation in version 4.10.0:
image

Specific code:
https://github.com/square/okhttp/blob/6b07f6227416506a44bb97012551929cd6a1dd79/okhttp/src/main/kotlin/okhttp3/OkHttpClient.kt#L134

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

No branches or pull requests

2 participants