简体   繁体   English

代理如何访问grpc服务中的请求标头。 Golang的grpc-gateway

[英]How to access request headers in grpc service proxied by. grpc-gateway in golang

I have a grpc server proxied by grpc-gateway. 我有由grpc-gateway代理的grpc服务器。 When I make a HTTP call to the gateway endpoint, my corresponding grpc service method is called. 当我对网关端点进行HTTP调用时,将调用我相应的grpc服务方法。 Now, the grpc service implementation receives a Context which has the headers. 现在,grpc服务实现接收到一个具有标头的Context。 I couldn't figure out how to access the headers. 我不知道如何访问标题。

在此处输入图片说明

When I debug my grpc service and put a breakpoint, this is the structure of the Context object which my service receives. 当我调试grpc服务并放置一个断点时,这就是我的服务接收到的Context对象的结构。 Now, how can I get the value of any of the HTTP request headers? 现在,如何获取任何HTTP请求标头的值?

HTTP headers are stored in metadata. HTTP标头存储在元数据中。

md, ok := metadata.FromIncomingContext(ctx) should work for getting the incoming metadata. md, ok := metadata.FromIncomingContext(ctx)应该可以获取传入的元数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM