简体   繁体   English

HTTP/2 客户端可以通过在双向流 RPC 中发送 HEADER 帧来终止流吗?

[英]Can HTTP/2 client terminate the stream by sending a HEADER frame in bidirectional streaming RPC?

Suppose we have a bidirectional streaming RPC where the client is sending several request messages (ie multiple DATA frames) and the server is answering back with several response messages (ie multiple DATA frames).假设我们有一个双向流式 RPC,其中客户端正在发送多个请求消息(即多个 DATA 帧),而服务器正在用多个响应消息(即多个 DATA 帧)进行回复。

As I understand it, when the RPC is complete, the server will normally send a HEADER frame with the status header as well as possibly some trailer headers like grpc-status and grpc-message to mark the completion of the request/response exchange.据我了解,当 RPC 完成时,服务器通常会发送一个带有状态标头的 HEADER 帧,可能还有一些像 grpc-status 和 grpc-message 这样的尾部标头来标记请求/响应交换的完成。

My question is, suppose the server sends a bad response message, is it possible for the client to send the HEADER frame with the grpc-status and grpc-message headers to convey information about the error.我的问题是,假设服务器发送了错误的响应消息,客户端是否可以发送带有 grpc-status 和 grpc-message 标头的 HEADER 帧来传达有关错误的信息。

The reason why I'm asking is because in the c++ server code (generated from protobuf defininition), I'm struggling to find a way to get a hold of this last HEADER frame sent by the client to verify the values of the grpc-status and grpc-message headers.我问的原因是因为在 C++ 服务器代码(从 protobuf 定义生成)中,我正在努力寻找一种方法来获取客户端发送的最后一个 HEADER 帧以验证 grpc 的值-状态和 grpc 消息标头。

Additionally, after going through the unit tests in the grpc project, it seems like only the server returns the status for the RPC, which further raises doubts.另外,经过grpc项目中的单元测试,似乎只有服务器返回RPC的状态,这更令人怀疑。

I was however able to send the HEADER frame out from the client, but based on the above, I'm not certain whether this is the correct behavior even though I was able to do it.然而,我能够从客户端发送 HEADER 帧,但基于上述内容,即使我能够做到,我也不确定这是否是正确的行为。

I would appreciate it if someone can clarify this for me as I'm fairly new to HTTP/2 and gRPC.如果有人能为我澄清这一点,我将不胜感激,因为我对 HTTP/2 和 gRPC 还很陌生。

Additionally, after going through the unit tests in the grpc project, it seems like only the server returns the status for the RPC, which further raises doubts.另外,经过grpc项目中的单元测试,似乎只有服务器返回RPC的状态,这更令人怀疑。

Correct!正确的! In gRPC, the server is responsible for terminating the RPC with a status and optional trailing metadata.在 gRPC 中,服务器负责使用状态和可选的尾随元数据终止 RPC。 The client never sends a status to the server.客户端从不向服务器发送状态。 The client can indicate it is done sending on the stream without a status (which internally happens by sending an empty data frame with the END_STREAM flag set, but users shouldn't need to be concerned with this detail).客户端可以在没有状态的情况下指示它已完成在流上的发送(这在内部通过发送一个带有 END_STREAM 标志的空数据帧发生,但用户不需要关心这个细节)。 The client only sends HEADER frames at the start of the RPC.客户端仅在 RPC 开始时发送 HEADER 帧。

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

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