代理如何访问grpc服务中的请求标头.Golang的grpc-gateway [英] How to access request headers in grpc service proxied by. grpc-gateway in golang

查看:92
本文介绍了代理如何访问grpc服务中的请求标头.Golang的grpc-gateway的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由grpc-gateway代理的grpc服务器.当我对网关端点进行HTTP调用时,将调用相应的grpc服务方法.现在,grpc服务实现接收到一个具有标头的Context.我不知道如何访问标题.

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.

当我调试grpc服务并放置一个断点时,这是我的服务接收到的Context对象的结构.现在,如何获取任何HTTP请求标头的值?

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?

推荐答案

HTTP标头存储在元数据中.

HTTP headers are stored in metadata.

md,确定:=元数据.FromIncomingContext(ctx)应该可以获取传入的元数据.

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

这篇关于代理如何访问grpc服务中的请求标头.Golang的grpc-gateway的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆