okhttp
okhttp copied to clipboard
Change user-agent on connect request?
Forgive me if there is a solution for this, but I can't seem to find a way to change the User-Agent header on a connect request. It seems like it's hard coded to:
User-Agent: okhttp/4.10.0
I can change it with reflection, but we have a situation where a server needs the user agent to match all requests moving forward. Is there a way to do it? Perhaps it could be acheived with this enhancement?
https://github.com/square/okhttp/issues/7297
No way to manipulate this currently. I'm not even sure where we'd add that configuration option in our API.
No way to manipulate this currently. I'm not even sure where we'd add that configuration option in our API.
Perhaps just copy the value sent with the request initiating the connect?
That's the most obvious option. The drawback is that the request that creates the tunnel is arbitrary. If you have a connection that carries multiple requests, they may each use different user-agents. In general we're pretty allergic to data leakage like this.
For regular applications it's unlikely to matter but it's possible for OkHttp to be used inside a proxy or gateway where the requests are truly independent.
Right. What about a default user agent tied to the connection pool?
Or somehow allow intercepting on the Real connection?
Should User-Agent be configurable on OkHttpClient?
The hardcoded default seems like the issue here.
https://github.com/square/okhttp/blob/5c62ed796d05682c969b2636d3419b5bc214eb11/okhttp/src/jvmMain/kotlin/okhttp3/internal/http/BridgeInterceptor.kt#L80
import okhttp3.internal.userAgent
@swankjesse would you object to allow setting the user agent on the client?