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

混江龙づ霸主 提交于 2021-02-10 14:14:57

问题


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.

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?


回答1:


HTTP headers are stored in metadata.

md, ok := metadata.FromIncomingContext(ctx) should work for getting the incoming metadata.



来源:https://stackoverflow.com/questions/57686963/how-to-access-request-headers-in-grpc-service-proxied-by-grpc-gateway-in-golang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!