SetHeader sets the header metadata to be sent from the server to the client. The context provided must be the context passed to the server's handler. Streaming RPCs should prefer the SetHeader method of the ServerStream. When called multiple times, all the provided metadata will be merged. All th
(ctx context.Context, md metadata.MD)
| 2100 | // status code will often not match the RPC status as seen by the client |
| 2101 | // application, and therefore, should not be relied upon for this purpose. |
| 2102 | func SetHeader(ctx context.Context, md metadata.MD) error { |
| 2103 | if md.Len() == 0 { |
| 2104 | return nil |
| 2105 | } |
| 2106 | stream := ServerTransportStreamFromContext(ctx) |
| 2107 | if stream == nil { |
| 2108 | return status.Errorf(codes.Internal, "grpc: failed to fetch the stream from the context %v", ctx) |
| 2109 | } |
| 2110 | return stream.SetHeader(md) |
| 2111 | } |
| 2112 | |
| 2113 | // SendHeader sends header metadata. It may be called at most once, and may not |
| 2114 | // be called after any event that causes headers to be sent (see SetHeader for |