stepancheg / grpc-rust

Rust implementation of gRPC
MIT License
1.38k stars 124 forks source link

Support for additional headers #17

Open softprops opened 7 years ago

softprops commented 7 years ago

At the moment it looks like call_impl supports a fixed set of headers when starting a request. The wire format outlines a few others http://www.grpc.io/docs/guides/wire.html. in particular I'm wondering there is a way to start a request with the authorization header to authenticate requests? If not, would you be open to a pull request adding that support?

stepancheg commented 7 years ago

Yes, pull request would be great. But before starting implementation, let's discuss, what API for specifying additional header should look like.

softprops commented 7 years ago

Sry for the slow reply, I'm now swinging back in to see the state of things.

so looking that this example for instance you may want to provide an interface for user defined headers I was digging a while back and found this vec of the required ':'-prefixed headers. For the non :-prefixed headers, my first through would be to provide those as vec/hashset of httpbis::Headers.

I'm specifically interested in ( and blocked by ) send the authorization header. I took a look at go grpc's auth docs

After reading their strategy I changed my mind a bit. It's not really a thing I want to have to provide on each request but configuration I'd want to set once. I dug around a bit more and identified GrpcClientConf which may actually be a nicer candidate for users to configure things default headers like authorization and timeouts. If you capture and add the conf data to the GrpcClient instance, the call_impl could just append self.conf.headers to the list of headers it builds up for the request.

I like this best because the bootstrapping of the client tends to be where you want to configure authorization credentials and other details.

There's a separate question about structured Headers. I haven't looked into specific headers have defined value types. But I think it would be simplest to expose your httpbis::Header type as the interface for providing headers