mirror of https://github.com/grpc/grpc-go.git
Merge pull request #967 from ncteisen/advanced_go_interop_tests
Go Advanced Interop Tests
This commit is contained in:
commit
0d9891286a
|
|
@ -71,7 +71,10 @@ var (
|
|||
oauth2_auth_token: large_unary with oauth2 token auth;
|
||||
cancel_after_begin: cancellation after metadata has been sent but before payloads are sent;
|
||||
cancel_after_first_response: cancellation after receiving 1st message from the server;
|
||||
status_code_and_message: status code propagated back to client.`)
|
||||
status_code_and_message: status code propagated back to client;
|
||||
custom_metadata: server will echo custom metadata;
|
||||
unimplemented_method: client attempts to call unimplemented method;
|
||||
unimplemented_service: client attempts to call unimplemented service.`)
|
||||
|
||||
// The test CA root cert file
|
||||
testCAFile = "testdata/ca.pem"
|
||||
|
|
@ -184,6 +187,15 @@ func main() {
|
|||
case "status_code_and_message":
|
||||
interop.DoStatusCodeAndMessage(tc)
|
||||
grpclog.Println("StatusCodeAndMessage done")
|
||||
case "custom_metadata":
|
||||
interop.DoCustomMetadata(tc)
|
||||
grpclog.Println("CustomMetadata done")
|
||||
case "unimplemented_method":
|
||||
interop.DoUnimplementedMethod(conn)
|
||||
grpclog.Println("UnimplementedMethod done")
|
||||
case "unimplemented_service":
|
||||
interop.DoUnimplementedService(testpb.NewUnimplementedServiceClient(conn))
|
||||
grpclog.Println("UnimplementedService done")
|
||||
default:
|
||||
grpclog.Fatal("Unsupported test case: ", *testCase)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -792,48 +792,115 @@ var _TestService_serviceDesc = grpc.ServiceDesc{
|
|||
Metadata: "test.proto",
|
||||
}
|
||||
|
||||
// Client API for UnimplementedService service
|
||||
|
||||
type UnimplementedServiceClient interface {
|
||||
// A call that no server should implement
|
||||
UnimplementedCall(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
|
||||
}
|
||||
|
||||
type unimplementedServiceClient struct {
|
||||
cc *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewUnimplementedServiceClient(cc *grpc.ClientConn) UnimplementedServiceClient {
|
||||
return &unimplementedServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *unimplementedServiceClient) UnimplementedCall(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) {
|
||||
out := new(Empty)
|
||||
err := grpc.Invoke(ctx, "/grpc.testing.UnimplementedService/UnimplementedCall", in, out, c.cc, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for UnimplementedService service
|
||||
|
||||
type UnimplementedServiceServer interface {
|
||||
// A call that no server should implement
|
||||
UnimplementedCall(context.Context, *Empty) (*Empty, error)
|
||||
}
|
||||
|
||||
func RegisterUnimplementedServiceServer(s *grpc.Server, srv UnimplementedServiceServer) {
|
||||
s.RegisterService(&_UnimplementedService_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _UnimplementedService_UnimplementedCall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Empty)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UnimplementedServiceServer).UnimplementedCall(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/grpc.testing.UnimplementedService/UnimplementedCall",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UnimplementedServiceServer).UnimplementedCall(ctx, req.(*Empty))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _UnimplementedService_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "grpc.testing.UnimplementedService",
|
||||
HandlerType: (*UnimplementedServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "UnimplementedCall",
|
||||
Handler: _UnimplementedService_UnimplementedCall_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: fileDescriptor0,
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("test.proto", fileDescriptor0) }
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 625 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xbc, 0x54, 0x4d, 0x6f, 0xd3, 0x4c,
|
||||
0x10, 0x7e, 0x9d, 0x8f, 0x37, 0xcd, 0x24, 0x35, 0xd1, 0x46, 0x15, 0xae, 0x8b, 0x44, 0x65, 0x0e,
|
||||
0x18, 0x24, 0x02, 0x8a, 0x04, 0x07, 0x0e, 0xa0, 0xd0, 0xa6, 0xa2, 0x52, 0x9b, 0x04, 0x3b, 0x39,
|
||||
0x47, 0x4b, 0xb2, 0x75, 0x2d, 0x39, 0xb6, 0xb1, 0xd7, 0x88, 0x70, 0xe0, 0xcf, 0xf0, 0x23, 0x38,
|
||||
0xf0, 0xe7, 0xd8, 0x5d, 0x7f, 0xc4, 0x49, 0x5c, 0x91, 0xf2, 0x75, 0xdb, 0x7d, 0xf6, 0x99, 0x67,
|
||||
0xe6, 0x99, 0x19, 0x1b, 0x80, 0x92, 0x90, 0x76, 0xfc, 0xc0, 0xa3, 0x1e, 0x6a, 0x5a, 0x81, 0x3f,
|
||||
0xeb, 0x70, 0xc0, 0x76, 0x2d, 0xad, 0x06, 0xd5, 0xfe, 0xc2, 0xa7, 0x4b, 0xed, 0x02, 0x6a, 0x23,
|
||||
0xbc, 0x74, 0x3c, 0x3c, 0x47, 0x4f, 0xa0, 0x42, 0x97, 0x3e, 0x51, 0xa4, 0x63, 0x49, 0x97, 0xbb,
|
||||
0x87, 0x9d, 0x7c, 0x40, 0x27, 0x21, 0x8d, 0x19, 0xc1, 0x10, 0x34, 0x84, 0xa0, 0xf2, 0xde, 0x9b,
|
||||
0x2f, 0x95, 0x12, 0xa3, 0x37, 0x0d, 0x71, 0xd6, 0x5e, 0x02, 0xf4, 0x67, 0xd7, 0x9e, 0x49, 0x31,
|
||||
0x8d, 0x42, 0xce, 0x98, 0x79, 0xf3, 0x58, 0xb0, 0x6a, 0x88, 0x33, 0x52, 0xa0, 0xb6, 0x20, 0x61,
|
||||
0x88, 0x2d, 0x22, 0x02, 0xeb, 0x46, 0x7a, 0xd5, 0xbe, 0x95, 0x60, 0xdf, 0xb4, 0x17, 0xbe, 0x43,
|
||||
0x0c, 0xf2, 0x21, 0x62, 0x69, 0xd1, 0x2b, 0xd8, 0x0f, 0x48, 0xe8, 0x7b, 0x6e, 0x48, 0xa6, 0xbb,
|
||||
0x55, 0xd6, 0x4c, 0xf9, 0xfc, 0x86, 0x1e, 0xe4, 0xe2, 0x43, 0xfb, 0x73, 0x9c, 0xb1, 0xba, 0x22,
|
||||
0x99, 0x0c, 0x43, 0x4f, 0xa1, 0xe6, 0xc7, 0x0a, 0x4a, 0x99, 0x3d, 0x37, 0xba, 0x07, 0x85, 0xf2,
|
||||
0x46, 0xca, 0xe2, 0xaa, 0x57, 0xb6, 0xe3, 0x4c, 0xa3, 0x90, 0x04, 0x2e, 0x5e, 0x10, 0xa5, 0xc2,
|
||||
0xc2, 0xf6, 0x8c, 0x26, 0x07, 0x27, 0x09, 0x86, 0x74, 0x68, 0x09, 0x92, 0x87, 0x23, 0x7a, 0x3d,
|
||||
0x0d, 0x67, 0x1e, 0xab, 0xbe, 0x2a, 0x78, 0x32, 0xc7, 0x87, 0x1c, 0x36, 0x39, 0x8a, 0x7a, 0x70,
|
||||
0x67, 0x55, 0xa4, 0xe8, 0x9b, 0x52, 0x13, 0x75, 0x28, 0xeb, 0x75, 0xac, 0xfa, 0x6a, 0xc8, 0x99,
|
||||
0x01, 0x71, 0xd7, 0xbe, 0x80, 0x9c, 0x36, 0x2e, 0xc6, 0xf3, 0xa6, 0xa4, 0x9d, 0x4c, 0xa9, 0xb0,
|
||||
0x97, 0xf9, 0x89, 0xe7, 0x92, 0xdd, 0xd1, 0x7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, 0x6c, 0x95, 0xba, 0xdf, 0x2b, 0xd0, 0x18, 0x33, 0x75, 0x93,
|
||||
0xcd, 0xd1, 0x9e, 0x11, 0xf4, 0x1c, 0xea, 0xe2, 0x17, 0xc8, 0xcb, 0x42, 0xed, 0x0d, 0x5f, 0xfc,
|
||||
0x41, 0x2d, 0x02, 0xd1, 0x19, 0xd4, 0x27, 0x2e, 0x0e, 0xe2, 0xb0, 0xa3, 0x75, 0xc6, 0xda, 0xef,
|
||||
0x4b, 0xbd, 0x57, 0xfc, 0x98, 0x34, 0xc0, 0x81, 0x76, 0x41, 0x7f, 0x90, 0xbe, 0x11, 0x74, 0xe3,
|
||||
0x9e, 0xa9, 0x8f, 0x76, 0x60, 0xc6, 0xb9, 0x9e, 0x49, 0xc8, 0x06, 0xb4, 0xfd, 0x51, 0xa1, 0x87,
|
||||
0x37, 0x48, 0x6c, 0x7e, 0xc4, 0xaa, 0xfe, 0x73, 0x62, 0x9c, 0x4a, 0xe7, 0xa9, 0xe4, 0xb3, 0xc8,
|
||||
0x71, 0x4e, 0x23, 0xe6, 0xf6, 0xd3, 0x5f, 0xf3, 0xa4, 0x4b, 0xc2, 0x95, 0xfc, 0x16, 0x3b, 0x57,
|
||||
0xff, 0x20, 0xd5, 0x8f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbb, 0x7f, 0x47, 0xd6, 0x4b, 0x07, 0x00,
|
||||
0x00,
|
||||
// 649 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xbc, 0x54, 0x4d, 0x6f, 0xd3, 0x40,
|
||||
0x10, 0xc5, 0x69, 0x42, 0xda, 0x49, 0x6a, 0xc2, 0x94, 0x0a, 0x37, 0x45, 0x22, 0x32, 0x07, 0x0c,
|
||||
0x12, 0x01, 0x45, 0x82, 0x03, 0x12, 0xa0, 0xd2, 0xa6, 0xa2, 0x52, 0xdb, 0x14, 0xbb, 0x39, 0x47,
|
||||
0x4b, 0x32, 0x75, 0x2d, 0xf9, 0x0b, 0x7b, 0x5d, 0x91, 0x1e, 0xf8, 0x33, 0xfc, 0x08, 0x0e, 0xfc,
|
||||
0x39, 0xb4, 0x6b, 0x3b, 0x71, 0xd2, 0x54, 0x34, 0x7c, 0xdd, 0x76, 0xdf, 0xbe, 0xf9, 0x78, 0x33,
|
||||
0xcf, 0x06, 0xe0, 0x14, 0xf3, 0x76, 0x18, 0x05, 0x3c, 0xc0, 0xba, 0x1d, 0x85, 0xc3, 0xb6, 0x00,
|
||||
0x1c, 0xdf, 0xd6, 0xab, 0x50, 0xe9, 0x7a, 0x21, 0x1f, 0xeb, 0x87, 0x50, 0x3d, 0x61, 0x63, 0x37,
|
||||
0x60, 0x23, 0x7c, 0x06, 0x65, 0x3e, 0x0e, 0x49, 0x53, 0x5a, 0x8a, 0xa1, 0x76, 0xb6, 0xda, 0xc5,
|
||||
0x80, 0x76, 0x46, 0x3a, 0x1d, 0x87, 0x64, 0x4a, 0x1a, 0x22, 0x94, 0x3f, 0x05, 0xa3, 0xb1, 0x56,
|
||||
0x6a, 0x29, 0x46, 0xdd, 0x94, 0x67, 0xfd, 0x35, 0x40, 0x77, 0x78, 0x1e, 0x58, 0x9c, 0xf1, 0x24,
|
||||
0x16, 0x8c, 0x61, 0x30, 0x4a, 0x13, 0x56, 0x4c, 0x79, 0x46, 0x0d, 0xaa, 0x1e, 0xc5, 0x31, 0xb3,
|
||||
0x49, 0x06, 0xae, 0x99, 0xf9, 0x55, 0xff, 0x5e, 0x82, 0x75, 0xcb, 0xf1, 0x42, 0x97, 0x4c, 0xfa,
|
||||
0x9c, 0x50, 0xcc, 0xf1, 0x2d, 0xac, 0x47, 0x14, 0x87, 0x81, 0x1f, 0xd3, 0xe0, 0x66, 0x9d, 0xd5,
|
||||
0x73, 0xbe, 0xb8, 0xe1, 0xa3, 0x42, 0x7c, 0xec, 0x5c, 0xa6, 0x15, 0x2b, 0x53, 0x92, 0xe5, 0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6, 0x0b, 0x05, 0x1d, 0xc0, 0xab,
|
||||
0x1f, 0x15, 0x3e, 0xbe, 0x26, 0xc5, 0xfc, 0x47, 0xdc, 0x34, 0x7e, 0x4d, 0x4c, 0x4b, 0x19, 0xa2,
|
||||
0x94, 0xba, 0x9f, 0xb8, 0xee, 0x5e, 0x12, 0xba, 0xf4, 0xe5, 0x9f, 0x69, 0x32, 0x14, 0xa9, 0x4a,
|
||||
0xfd, 0xc0, 0xdc, 0xb3, 0xff, 0x50, 0xaa, 0xd3, 0x87, 0x7b, 0x7d, 0x5f, 0x6e, 0xd0, 0x23, 0x9f,
|
||||
0xd3, 0x28, 0x77, 0xd1, 0x1b, 0xb8, 0x3b, 0x83, 0x2f, 0xe7, 0xa6, 0x9f, 0x01, 0x00, 0x00, 0xff,
|
||||
0xff, 0xdd, 0xb5, 0x50, 0x6f, 0xa2, 0x07, 0x00, 0x00,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,3 +151,10 @@ service TestService {
|
|||
rpc HalfDuplexCall(stream StreamingOutputCallRequest)
|
||||
returns (stream StreamingOutputCallResponse);
|
||||
}
|
||||
|
||||
// A simple service NOT implemented at servers so clients can test for
|
||||
// that case.
|
||||
service UnimplementedService {
|
||||
// A call that no server should implement
|
||||
rpc UnimplementedCall(grpc.testing.Empty) returns (grpc.testing.Empty);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ var (
|
|||
respSizes = []int{31415, 9, 2653, 58979}
|
||||
largeReqSize = 271828
|
||||
largeRespSize = 314159
|
||||
initialMetadataKey = "x-grpc-test-echo-initial"
|
||||
trailingMetadataKey = "x-grpc-test-echo-trailing-bin"
|
||||
)
|
||||
|
||||
func clientNewPayload(t testpb.PayloadType, size int) *testpb.Payload {
|
||||
|
|
@ -454,6 +456,92 @@ func DoCancelAfterFirstResponse(tc testpb.TestServiceClient) {
|
|||
}
|
||||
}
|
||||
|
||||
var (
|
||||
initialMetadataValue = "test_initial_metadata_value"
|
||||
trailingMetadataValue = "\x0a\x0b\x0a\x0b\x0a\x0b"
|
||||
customMetadata = metadata.Pairs(
|
||||
initialMetadataKey, initialMetadataValue,
|
||||
trailingMetadataKey, trailingMetadataValue,
|
||||
)
|
||||
)
|
||||
|
||||
func validateMetadata(header, trailer metadata.MD) {
|
||||
if len(header[initialMetadataKey]) != 1 {
|
||||
grpclog.Fatalf("Expected exactly one header from server. Received %d", len(header[initialMetadataKey]))
|
||||
}
|
||||
if header[initialMetadataKey][0] != initialMetadataValue {
|
||||
grpclog.Fatalf("Got header %s; want %s", header[initialMetadataKey][0], initialMetadataValue)
|
||||
}
|
||||
if len(trailer[trailingMetadataKey]) != 1 {
|
||||
grpclog.Fatalf("Expected exactly one trailer from server. Received %d", len(trailer[trailingMetadataKey]))
|
||||
}
|
||||
if trailer[trailingMetadataKey][0] != trailingMetadataValue {
|
||||
grpclog.Fatalf("Got trailer %s; want %s", trailer[trailingMetadataKey][0], trailingMetadataValue)
|
||||
}
|
||||
}
|
||||
|
||||
// DoCustomMetadata checks that metadata is echoed back to the client.
|
||||
func DoCustomMetadata(tc testpb.TestServiceClient) {
|
||||
// Testing with UnaryCall.
|
||||
pl := clientNewPayload(testpb.PayloadType_COMPRESSABLE, 1)
|
||||
req := &testpb.SimpleRequest{
|
||||
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||
ResponseSize: proto.Int32(int32(1)),
|
||||
Payload: pl,
|
||||
}
|
||||
ctx := metadata.NewContext(context.Background(), customMetadata)
|
||||
var header, trailer metadata.MD
|
||||
reply, err := tc.UnaryCall(
|
||||
ctx,
|
||||
req,
|
||||
grpc.Header(&header),
|
||||
grpc.Trailer(&trailer),
|
||||
)
|
||||
if err != nil {
|
||||
grpclog.Fatal("/TestService/UnaryCall RPC failed: ", err)
|
||||
}
|
||||
t := reply.GetPayload().GetType()
|
||||
s := len(reply.GetPayload().GetBody())
|
||||
if t != testpb.PayloadType_COMPRESSABLE || s != 1 {
|
||||
grpclog.Fatalf("Got the reply with type %d len %d; want %d, %d", t, s, testpb.PayloadType_COMPRESSABLE, 1)
|
||||
}
|
||||
validateMetadata(header, trailer)
|
||||
|
||||
// Testing with FullDuplex.
|
||||
stream, err := tc.FullDuplexCall(ctx)
|
||||
if err != nil {
|
||||
grpclog.Fatalf("%v.FullDuplexCall(_) = _, %v, want <nil>", tc, err)
|
||||
}
|
||||
respParam := []*testpb.ResponseParameters{
|
||||
{
|
||||
Size: proto.Int32(1),
|
||||
},
|
||||
}
|
||||
streamReq := &testpb.StreamingOutputCallRequest{
|
||||
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
|
||||
ResponseParameters: respParam,
|
||||
Payload: pl,
|
||||
}
|
||||
if err := stream.Send(streamReq); err != nil {
|
||||
grpclog.Fatalf("%v.Send(%v) = %v", stream, streamReq, err)
|
||||
}
|
||||
streamHeader, err := stream.Header()
|
||||
if err != nil {
|
||||
grpclog.Fatalf("%v.Header() = %v", stream, err)
|
||||
}
|
||||
if _, err := stream.Recv(); err != nil {
|
||||
grpclog.Fatalf("%v.Recv() = %v", stream, err)
|
||||
}
|
||||
if err := stream.CloseSend(); err != nil {
|
||||
grpclog.Fatalf("%v.CloseSend() = %v, want <nil>", stream, err)
|
||||
}
|
||||
if _, err := stream.Recv(); err != io.EOF {
|
||||
grpclog.Fatalf("%v failed to complete the custom metadata test: %v", stream, err)
|
||||
}
|
||||
streamTrailer := stream.Trailer()
|
||||
validateMetadata(streamHeader, streamTrailer)
|
||||
}
|
||||
|
||||
// DoStatusCodeAndMessage checks that the status code is propagated back to the client.
|
||||
func DoStatusCodeAndMessage(tc testpb.TestServiceClient) {
|
||||
var code int32 = 2
|
||||
|
|
@ -489,6 +577,22 @@ func DoStatusCodeAndMessage(tc testpb.TestServiceClient) {
|
|||
}
|
||||
}
|
||||
|
||||
// DoUnimplementedService attempts to call a method from an unimplemented service.
|
||||
func DoUnimplementedService(tc testpb.UnimplementedServiceClient) {
|
||||
_, err := tc.UnimplementedCall(context.Background(), &testpb.Empty{})
|
||||
if grpc.Code(err) != codes.Unimplemented {
|
||||
grpclog.Fatalf("%v.UnimplementedCall() = _, %v, want _, %v", tc, grpc.Code(err), codes.Unimplemented)
|
||||
}
|
||||
}
|
||||
|
||||
// DoUnimplementedMethod attempts to call an unimplemented method.
|
||||
func DoUnimplementedMethod(cc *grpc.ClientConn) {
|
||||
var req, reply proto.Message
|
||||
if err := grpc.Invoke(context.Background(), "/grpc.testing.TestService/UnimplementedCall", req, reply, cc); err == nil || grpc.Code(err) != codes.Unimplemented {
|
||||
grpclog.Fatalf("grpc.Invoke(_, _, _, _, _) = %v, want error code %s", err, codes.Unimplemented)
|
||||
}
|
||||
}
|
||||
|
||||
type testServer struct {
|
||||
}
|
||||
|
||||
|
|
@ -521,6 +625,16 @@ func serverNewPayload(t testpb.PayloadType, size int32) (*testpb.Payload, error)
|
|||
|
||||
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
||||
status := in.GetResponseStatus()
|
||||
if md, ok := metadata.FromContext(ctx); ok {
|
||||
if initialMetadata, ok := md[initialMetadataKey]; ok {
|
||||
header := metadata.Pairs(initialMetadataKey, initialMetadata[0])
|
||||
grpc.SendHeader(ctx, header)
|
||||
}
|
||||
if trailingMetadata, ok := md[trailingMetadataKey]; ok {
|
||||
trailer := metadata.Pairs(trailingMetadataKey, trailingMetadata[0])
|
||||
grpc.SetTrailer(ctx, trailer)
|
||||
}
|
||||
}
|
||||
if status != nil && *status.Code != 0 {
|
||||
return nil, grpc.Errorf(codes.Code(*status.Code), *status.Message)
|
||||
}
|
||||
|
|
@ -570,6 +684,16 @@ func (s *testServer) StreamingInputCall(stream testpb.TestService_StreamingInput
|
|||
}
|
||||
|
||||
func (s *testServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error {
|
||||
if md, ok := metadata.FromContext(stream.Context()); ok {
|
||||
if initialMetadata, ok := md[initialMetadataKey]; ok {
|
||||
header := metadata.Pairs(initialMetadataKey, initialMetadata[0])
|
||||
stream.SendHeader(header)
|
||||
}
|
||||
if trailingMetadata, ok := md[trailingMetadataKey]; ok {
|
||||
trailer := metadata.Pairs(trailingMetadataKey, trailingMetadata[0])
|
||||
stream.SetTrailer(trailer)
|
||||
}
|
||||
}
|
||||
for {
|
||||
in, err := stream.Recv()
|
||||
if err == io.EOF {
|
||||
|
|
|
|||
Loading…
Reference in New Issue