grpc / grpc-node

gRPC for Node.js
https://grpc.io
Apache License 2.0
4.49k stars 649 forks source link

H2C support #1492

Open cyx opened 4 years ago

cyx commented 4 years ago

Is your feature request related to a problem? Please describe.

For certain infrastructure setups doing H2C with load balancers that doesn't support http/2 is the only feasible option. Would be good to have a simple option to do this.

Describe the solution you'd like

Either a flag or a way to stub in a different channel implementation

Describe alternatives you've considered

Alternative is to change our infrastructure but it's not really as simple.

Additional context

Would be happy to help implement or just get direction how to do this cleanly.

murgatroid99 commented 4 years ago

If I understand right, H2C is just http2 in cleartext, instead of using TLS. You should be able to do that by creating a client using an "insecure" credentials object (grpc.credentials.createInsecure()).

cyx commented 4 years ago

If I understand right, H2C is just http2 in cleartext, instead of using TLS. You should be able to do that by creating a client using an "insecure" credentials object (grpc.credentials.createInsecure()).

I'm not so sure. My understanding is:

  1. TCP connection created.
  2. Optionally, TLS handshake done for the TCP connection.
  3. A GET request is sent, with Connection: upgrade, Upgrade: h2c headers.
  4. The response is checked, making sure proper headers are set.

Here's the implementation for Go on the client side: https://github.com/lstoll/grpce/blob/master/h2c/dialer.go#L24-L85

murgatroid99 commented 4 years ago

In that case there probably isn't currently a way to do it.

I'm guessing that the implementation would be similar to the existing HTTP proxy traversal code (https://github.com/grpc/grpc-node/blob/master/packages/grpc-js/src/http_proxy.ts). Pull requests are welcome, but this would be a new feature that adds to the API, so it should also be accompanied by a proposal.

cyx commented 4 years ago

@murgatroid99 thanks for the response! While I would be happy to send a proposal, I don't think it's entirely necessary to be on the gRPC level unless I'm misunderstanding what you mean?

e.g. is there a way to just make this a third party extension which layers on top of the existing pure nodejs implementation?

murgatroid99 commented 4 years ago

I don't see a way to do it like that. Establishing a connection is a fairly low-level operation, and there aren't any API hooks to modify it.