You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -127,7 +117,8 @@ Metadata that a client can receive includes header and trailer.
127
117
128
118
#### Unary call
129
119
130
-
Header and trailer sent along with a unary call can be retrieved using function [Header](https://godoc.org/google.golang.org/grpc#Header) and [Trailer](https://godoc.org/google.golang.org/grpc#Trailer) in [CallOption](https://godoc.org/google.golang.org/grpc#CallOption):
120
+
Header and trailer sent along with a unary call can be retrieved using function
121
+
[Header] and [Trailer] in [CallOption]:
131
122
132
123
```go
133
124
varheader, trailer metadata.MD// variable to store header and trailer
@@ -149,7 +140,8 @@ For streaming calls including:
149
140
- Client streaming RPC
150
141
- Bidirectional streaming RPC
151
142
152
-
Header and trailer can be retrieved from the returned stream using function `Header` and `Trailer` in interface [ClientStream](https://godoc.org/google.golang.org/grpc#ClientStream):
143
+
Header and trailer can be retrieved from the returned stream using function
144
+
`Header` and `Trailer` in interface [ClientStream]:
153
145
154
146
```go
155
147
stream, err:= client.SomeStreamingRPC(ctx)
@@ -164,11 +156,13 @@ trailer := stream.Trailer()
164
156
165
157
## Sending and receiving metadata - server side
166
158
167
-
Server side metadata sending and receiving examples are available [here](../examples/features/metadata/server/main.go).
159
+
Server side metadata sending and receiving examples are available
To read metadata sent by the client, the server needs to retrieve it from RPC context.
164
+
To read metadata sent by the client, the server needs to retrieve it from RPC
165
+
context using [FromIncomingContext].
172
166
If it is a unary call, the RPC handler's context can be used.
173
167
For streaming calls, the server needs to get context from the stream.
174
168
@@ -194,15 +188,16 @@ func (s *server) SomeStreamingRPC(stream pb.Service_SomeStreamingRPCServer) erro
194
188
195
189
#### Unary call
196
190
197
-
To send header and trailer to client in unary call, the server can call [SendHeader](https://godoc.org/google.golang.org/grpc#SendHeader) and [SetTrailer](https://godoc.org/google.golang.org/grpc#SetTrailer) functions in module [grpc](https://godoc.org/google.golang.org/grpc).
191
+
To send header and trailer to client in unary call, the server can call
192
+
[SetHeader] and [SetTrailer] functions in module [grpc].
198
193
These two functions take a context as the first parameter.
199
194
It should be the RPC handler's context or one derived from it:
200
195
201
196
```go
202
197
func(s *server) SomeRPC(ctxcontext.Context, in *pb.someRequest) (*pb.someResponse, error) {
203
-
// create and send header
198
+
// create and set header
204
199
header:= metadata.Pairs("header-key", "val")
205
-
grpc.SendHeader(ctx, header)
200
+
grpc.SetHeader(ctx, header)
206
201
// create and set trailer
207
202
trailer:= metadata.Pairs("trailer-key", "val")
208
203
grpc.SetTrailer(ctx, trailer)
@@ -211,20 +206,39 @@ func (s *server) SomeRPC(ctx context.Context, in *pb.someRequest) (*pb.someRespo
211
206
212
207
#### Streaming call
213
208
214
-
For streaming calls, header and trailer can be sent using function `SendHeader` and `SetTrailer` in interface [ServerStream](https://godoc.org/google.golang.org/grpc#ServerStream):
209
+
For streaming calls, header and trailer can be sent using function
210
+
[SetHeader] and [SetTrailer] in interface [ServerStream]:
0 commit comments