-
Notifications
You must be signed in to change notification settings - Fork 20.7k
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
rpc: add client constructor with headers #24269
Conversation
@fjl Anything I can do to help get this merged? |
Hey, sorry for the delay. I've been thinking about this issue a lot actually. The problem, as you have also noted, is that the existing API is not very extensible and cannot accommodate new options easily. I don't really want to add yet another specialized client constructor for this. Instead, I would prefer one of the following solutions:
I loosely prefer the second way because it is more future proof. At the same time, I think we will need |
Thanks for the detailed response. I agree with both -- and happy to take on the NewClient work. Here are the general options I think might make sense to expose WithHeaders (websocket, http) A few concerns putting the options at the client level (vs transport-specific options)
So I think options need to be at the transport layer unfortunately. This will at least let us cut down on the number of constructors and code paths, but won't get us much code reuse (which I think is OK). I took a first pass at implementing a few options for websockets/http (no tests/comments yet). A path forward for Want to get your thoughts before I write any more code. Let me know what you think! |
Still thinking about this. |
I have implemented client options in #24911, which is now merged to the master branch. The way it's done is a bit different from this PR, but the result is the same. You can now set headers for websocket connections like this:
There are also other options to choose from such as |
Adds a new constructor
DialWebsocketWithHeaders
that takes inhttp.Header
to connect to the websocket with. Currently, some headers like basic auth and origin are added automagically through the existing constructorDialWebsocketWithDialer
.This doesn't change the behavior of that constructor at all, but code is shifted around slightly to add the minimal amount of new code and reuse existing constructors.
Happy to make this more extensible by added some sort of options pattern, but didn't want to change any of the existing APIs.