1

I have a grpc server proxied by grpc-gateway. When I make a HTTP call to the gateway endpoint, my corresponding grpc service method is called. Now, the grpc service implementation receives a Context which has the headers. I couldn't figure out how to access the headers.

enter image description here

When I debug my grpc service and put a breakpoint, this is the structure of the Context object which my service receives. Now, how can I get the value of any of the HTTP request headers?

4

1 回答 1

9

HTTP 标头存储在元数据中。

md, ok := metadata.FromIncomingContext(ctx)应该用于获取传入的元数据。

于 2019-08-30T02:18:13.473 回答