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

Change user-agent on connect request? #7362

Open
regbo opened this issue Jun 30, 2022 · 6 comments
Open

Change user-agent on connect request? #7362

regbo opened this issue Jun 30, 2022 · 6 comments
Labels
enhancement Feature not a bug

Comments

@regbo
Copy link

regbo commented Jun 30, 2022

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?

#7297

@regbo regbo added the enhancement Feature not a bug label Jun 30, 2022
@swankjesse
Copy link
Member

No way to manipulate this currently. I'm not even sure where we'd add that configuration option in our API.

@swankjesse swankjesse reopened this Jul 1, 2022
@regbo
Copy link
Author

regbo commented Jul 1, 2022

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?

@swankjesse
Copy link
Member

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.

@regbo
Copy link
Author

regbo commented Jul 1, 2022

Right. What about a default user agent tied to the connection pool?

Or somehow allow intercepting on the Real connection?

@yschimke
Copy link
Collaborator

yschimke commented Jul 1, 2022

Should User-Agent be configurable on OkHttpClient?

The hardcoded default seems like the issue here.

requestBuilder.header("User-Agent", userAgent)

import okhttp3.internal.userAgent

@yschimke
Copy link
Collaborator

@swankjesse would you object to allow setting the user agent on the client?

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

3 participants