-
Notifications
You must be signed in to change notification settings - Fork 329
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
Allow python client to accept custom http headers #185
Comments
I would be happy to add this feature, yes. |
Is adding optional
For twirp, HTTP is an implementation detail and naively exposing HTTP headers may not be a very good idea. Go client does not directly expose HTTP by wrapping it with
https://godoc.org/github.com/twitchtv/twirp#WithHTTPRequestHeaders Though adding an optional headers argument may not be a real problem, just wanted to express my concern. Thank you. |
Right - I think what you're seeing is that the Python code doesn't have a very well-thought-out API today. In Go generated clients, users can pass in their own HTTP Client; we have nothing like that for Python. On the other hand, Go isn't Python. In Go, the tradition is to be strict about hiding implementation details, and to discourage bad behavior very strongly. In Python, shooting yourself in the foot is discouraged, but rarely completely banned :) I agree that |
Disclaimer: I rarely write python. One idea is to allow users to decorate twirp client with http request handler.
This way, the generated method signature stays the same and it should This can be accomplished by using a custom url opener and works both python 2 https://docs.python.org/2/library/urllib2.html Any feedback would be appreciated 😄 |
I like the idea but why not with a simpler approach by extending the constructor of the generated client class to accept an optional request handler fuction.
You could also add a class check on This is also matches the Go client signature. |
Thanks for the feedback! One reason is to change headers dynamically.
We can accomplish the same thing with your idea but it seems somewhat strange to pass |
Well we could change it to |
That won't be safe with multi-threaded servers. We need to make clients immutable. |
Hm, im not too familiar with the internals, but how would dynamically changing headers through a decorator function be any different? Maybe if you could show a more concrete example of the implementation you had in mind. |
Our implementation of the python client and server allow you to set headers via the context object. |
@dpolansky Readme mentions this so can close this issue unless you want to add support in this repo as well. |
I don't think we will support the Python implementation in this repo. It mainly works as an example, and we may end up removing it. For now, mentioning the verloop/vtwirp implementation should be good to offer a better alternative. |
Twirp version: 5.8.0
It seems like that the generated python client does not allow us to pass custom http headers. See the following excerpt.
Do you plan to add that feature or accept PR?
Thank you.
The text was updated successfully, but these errors were encountered: