-
Notifications
You must be signed in to change notification settings - Fork 17
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
Force HTTP/2 (h2c) for streams when URL is http://...
#14
Comments
The first example (injecting this logic into generated code) would tightly couple the generated client stubs to the existing okhttp implementation. But the purpose of this being an interface ( The latter example (pushing the logic into the So a little more exploration is needed to come up with how we might apply an idea similar to the latter example, but still able to re-use clients and pool connections. We also need to make sure the solution doesn't cause resource leaks: okhttp clients are heavyweight and stateful (using both network connections as well as worker threads in a thread pool) and need to be closed/freed when no longer needed. If the solution involves the |
@jhump The first example is my interim workaround - I did not expect that it would be the correct way to do it long term. Given that the code has changed quite a bit since I first raised this issue, I will see if I can take a fresh look at it to try to suggest another way to do this. |
@kohenkatz, I believe this is still an issue. The BTW, one downside to having this be automatic/implicit (i.e. based on detecting the gRPC protocol, as in the example) is that it means different configuration would be needed in order to use H2C with gRPC-Web and Connect protocol traffic. That inconsistency (that sometimes H2C is used when not explicitly requested, but not always) could be a source of confusion/surprise. |
The gRPC libraries for Java/Kotlin (and most other languages) provide a
usePlaintext()
builder method that tells the library to communicate using HTTP/2 over Cleartext (h2c
). This is mostly useful for communicating with development servers running on the developers' PC and for certain types of automated testing.Because connect-kotlin uses a full URL instead of separate
host
andport
arguments, we can check whether the scheme ishttp
orhttps
to determine whether to enable plaintext support.We for want to keep HTTP/1.1 support for unary connect calls, which is similar to the discussion in #13 about separate client options for unary vs. streaming. However, gRPC requires HTTP/2 for unary calls too, so we probably need to check the chosen protocol before setting this option.
Here's what I'm using for this right now (built on top of my code sample in #13). Note that this cannot use automatic detection based on the URL scheme and network protocol because the scheme is not available when the client is created. Instead, the constructor has two additional arguments:
I suspect that it makes the most sense to implement this in
ConnectOkHttpClient
as follows (not tested), but I'm not totally sure:The text was updated successfully, but these errors were encountered: