SendHeader sends header metadata. It may be called at most once, and may not be called after any event that causes headers to be sent (see SetHeader for a complete list). The provided md and headers set by SetHeader() will be sent. The error returned is compatible with the status package. However
(ctx context.Context, md metadata.MD)
| 2119 | // status code will often not match the RPC status as seen by the client |
| 2120 | // application, and therefore, should not be relied upon for this purpose. |
| 2121 | func SendHeader(ctx context.Context, md metadata.MD) error { |
| 2122 | stream := ServerTransportStreamFromContext(ctx) |
| 2123 | if stream == nil { |
| 2124 | return status.Errorf(codes.Internal, "grpc: failed to fetch the stream from the context %v", ctx) |
| 2125 | } |
| 2126 | if err := stream.SendHeader(md); err != nil { |
| 2127 | return toRPCErr(err) |
| 2128 | } |
| 2129 | return nil |
| 2130 | } |
| 2131 | |
| 2132 | // SetSendCompressor sets a compressor for outbound messages from the server. |
| 2133 | // It must not be called after any event that causes headers to be sent |