Golang: Is it possible to get header (metadata) in StreamClientInterceptor?

2,670 views
Skip to first unread message

温明浩

unread,
Mar 31, 2022, 12:44:02 AM3/31/22
to grpc.io
Hi all,

Currently I have a rpc like this:
rpc SayHello (HelloRequest) returns (stream HelloReply) {}

Now I add a StreamClientInterceptor to catch response initial metadata,
but it block forever, and server shows that no request get, at least not into the rpc function.

The interceptor is similar to this example:
and I just add a line under L107 :
responseMeta, err := s.Header()  //<-- block here

Im sure that I can done in Python code,  which is implement similar to:
and adds code under L37:
print(response_it.initial_metadata())

Can anyone tell me what is wrong of my Golang code?
Actually I can get header by wrapping grpc.ClientStream and received in RecvMsg()
and I observed that I can only get header after SendMsg, but it doesn't make sense :(

Amit Saha

unread,
Mar 31, 2022, 5:49:54 PM3/31/22
to grpc.io
Have you tried the metadata.FromIncomingContext() function?

You haven't shared your example code - i think that will be useful for others to help you.

温明浩

unread,
Apr 5, 2022, 11:03:45 PM4/5/22
to grpc.io
Hi amits, 

Sorry for the late replay.
I have write a minimal example to express my question.

The main purpose is trying to manage request&response header in interceptor, in order to share come context or status.
I have try metadata.FromIncomingContext() and seems empty.
Is there have any method to send request header first without sending payload?
Since this concept is documented in here: https://grpc.io/docs/what-is-grpc/core-concepts/#unary-rpc
Or, any method that can let me access response header without wrapping a ClientStream?
thanks!
amits...@gmail.com 在 2022年4月1日 星期五上午5:49:54 [UTC+8] 的信中寫道:

温明浩

unread,
Apr 10, 2022, 11:54:08 PM4/10/22
to grpc.io
Sorry for pushing up manually,

but I really want to know if there's method to do it like in Python.

Yes I can do it by wrapping a `ClientStream`, however it create a new instance in every call that I needs to use a pointer or somehow to manage together with my `ClientInterceptor`, which seems a bit dirty 

thanks.

温明浩 在 2022年4月6日 星期三上午11:03:45 [UTC+8] 的信中寫道:
Message has been deleted

Easwar Swaminathan

unread,
Jun 6, 2022, 4:43:02 PM6/6/22
to grpc.io
Apologies for the late reply.

> Is there have any method to send request header first without sending payload?

You can do so by calling grpc.SendHeader, or for streaming handlers by calling stream.SendHeader


The grpc.Header call option only works for unary RPCs and the header metadata will be available only after the RPC completes. For streaming RPCs, the client can call the stream.Header when they know that header metadata will be available, or after the first call to stream.RecvMsg has returned.

Hope this helps. If not, please feel free to post a question on our GitHub repo.

On Tuesday, May 31, 2022 at 5:35:48 PM UTC-7 Hagenauer Anja wrote:
DIRECT SENDER IS HERE LETS DEAL.



MT103/202 DIRECT WIRE TRANSFER
PAYPAL TRANSFER
CASHAPP TRANSFER
ZELLE TRANSFER
TRANSFER WISE
WESTERN UNION TRANSFER
BITCOIN FLASHING 
BANK ACCOUNT LOADING/FLASHING
IBAN TO IBAN TRANSFER
MONEYGRAM TRANSFER
IPIP/DTC
SLBC PROVIDER
CREDIT CARD TOP UP
DUMPS/ PINS
SEPA TRANSFER
WIRE TRANSFER
BITCOIN TOP UP
GLOBALPAY INC US
SKRILL USA

Thanks.

For more information Dm on WhatsApp:

+491512 9738176
Reply all
Reply to author
Forward
0 new messages