Skip to content

Commit 987df13

Browse files
metadata: move FromOutgoingContextRaw() to internal (#6765)
Co-authored-by: Arvind Bright <[email protected]>
1 parent 61eab37 commit 987df13

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

internal/internal.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,13 @@ var (
189189
// the associated watch timer fires. For testing purposes, having this
190190
// function makes events more predictable than relying on timer events.
191191
TriggerXDSResourceNameNotFoundForTesting any // func(func(xdsresource.Type, string), string, string) error
192+
192193
// TriggerXDSResourceNotFoundClient invokes the testing xDS Client singleton
193194
// to invoke resource not found for a resource type name and resource name.
194195
TriggerXDSResourceNameNotFoundClient any // func(string, string) error
196+
197+
// FromOutgoingContextRaw returns the un-merged, intermediary contents of metadata.rawMD.
198+
FromOutgoingContextRaw any // func(context.Context) (metadata.MD, [][]string, bool)
195199
)
196200

197201
// HealthChecker defines the signature of the client-side LB channel health checking function.

internal/transport/http2_client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ import (
5959
// atomically.
6060
var clientConnectionCounter uint64
6161

62+
var metadataFromOutgoingContextRaw = internal.FromOutgoingContextRaw.(func(context.Context) (metadata.MD, [][]string, bool))
63+
6264
// http2Client implements the ClientTransport interface with HTTP2.
6365
type http2Client struct {
6466
lastRead int64 // Keep this field 64-bit aligned. Accessed atomically.
@@ -568,7 +570,7 @@ func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr)
568570
headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-trace-bin", Value: encodeBinHeader(b)})
569571
}
570572

571-
if md, added, ok := metadata.FromOutgoingContextRaw(ctx); ok {
573+
if md, added, ok := metadataFromOutgoingContextRaw(ctx); ok {
572574
var k string
573575
for k, vv := range md {
574576
// HTTP doesn't allow you to set pseudoheaders after non pseudoheaders were set.

metadata/metadata.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ import (
2525
"context"
2626
"fmt"
2727
"strings"
28+
29+
"google.golang.org/grpc/internal"
2830
)
2931

32+
func init() {
33+
internal.FromOutgoingContextRaw = fromOutgoingContextRaw
34+
}
35+
3036
// DecodeKeyValue returns k, v, nil.
3137
//
3238
// Deprecated: use k and v directly instead.
@@ -238,16 +244,13 @@ func copyOf(v []string) []string {
238244
return vals
239245
}
240246

241-
// FromOutgoingContextRaw returns the un-merged, intermediary contents of rawMD.
247+
// fromOutgoingContextRaw returns the un-merged, intermediary contents of rawMD.
242248
//
243249
// Remember to perform strings.ToLower on the keys, for both the returned MD (MD
244250
// is a map, there's no guarantee it's created using our helper functions) and
245251
// the extra kv pairs (AppendToOutgoingContext doesn't turn them into
246252
// lowercase).
247-
//
248-
// This is intended for gRPC-internal use ONLY. Users should use
249-
// FromOutgoingContext instead.
250-
func FromOutgoingContextRaw(ctx context.Context) (MD, [][]string, bool) {
253+
func fromOutgoingContextRaw(ctx context.Context) (MD, [][]string, bool) {
251254
raw, ok := ctx.Value(mdOutgoingKey{}).(rawMD)
252255
if !ok {
253256
return nil, nil, false

stream.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import (
4848
"google.golang.org/grpc/status"
4949
)
5050

51+
var metadataFromOutgoingContextRaw = internal.FromOutgoingContextRaw.(func(context.Context) (metadata.MD, [][]string, bool))
52+
5153
// StreamHandler defines the handler called by gRPC server to complete the
5254
// execution of a streaming RPC.
5355
//
@@ -184,7 +186,7 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth
184186
// when the RPC completes.
185187
opts = append([]CallOption{OnFinish(func(error) { cc.idlenessMgr.OnCallEnd() })}, opts...)
186188

187-
if md, added, ok := metadata.FromOutgoingContextRaw(ctx); ok {
189+
if md, added, ok := metadataFromOutgoingContextRaw(ctx); ok {
188190
// validate md
189191
if err := imetadata.Validate(md); err != nil {
190192
return nil, status.Error(codes.Internal, err.Error())

0 commit comments

Comments
 (0)