Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 698
Amudhan Avatar asked Oct 28 '25 17:10

Amudhan


1 Answers

HTTP headers are stored in metadata.

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

like image 185
ConnectionLost Avatar answered Oct 31 '25 07:10

ConnectionLost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!