Skip to content

Commit c7d0145

Browse files
committed
Increment: Redefines metatdata.FromOutgoingContextRaw() as an internal method
1 parent 70f1a40 commit c7d0145

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

internal/internal.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ var (
186186

187187
// ExitIdleModeForTesting gets the ClientConn to exit IDLE mode.
188188
ExitIdleModeForTesting any // func(*grpc.ClientConn) error
189+
190+
// Gets the function definition from metadata package
191+
FromOutgoingContextRaw any // func(context.Context) (metadata.MD, [][]string, bool)
189192
)
190193

191194
// 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
@@ -36,6 +36,7 @@ import (
3636
"golang.org/x/net/http2/hpack"
3737
"google.golang.org/grpc/codes"
3838
"google.golang.org/grpc/credentials"
39+
"google.golang.org/grpc/internal"
3940
"google.golang.org/grpc/internal/channelz"
4041
icredentials "google.golang.org/grpc/internal/credentials"
4142
"google.golang.org/grpc/internal/grpclog"
@@ -566,7 +567,8 @@ func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr)
566567
headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-trace-bin", Value: encodeBinHeader(b)})
567568
}
568569

569-
if md, added, ok := metadata.FromOutgoingContextRaw(ctx); ok {
570+
fromOutgoingCtxRaw := internal.FromOutgoingContextRaw.(func(context.Context) (metadata.MD, [][]string, bool))
571+
if md, added, ok := fromOutgoingCtxRaw(ctx); ok {
570572
var k string
571573
for k, vv := range md {
572574
// HTTP doesn't allow you to set pseudoheaders after non pseudoheaders were set.

metadata/metadata.go

Lines changed: 8 additions & 2 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,7 +244,7 @@ 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
@@ -247,7 +253,7 @@ func copyOf(v []string) []string {
247253
//
248254
// This is intended for gRPC-internal use ONLY. Users should use
249255
// FromOutgoingContext instead.
250-
func FromOutgoingContextRaw(ctx context.Context) (MD, [][]string, bool) {
256+
func fromOutgoingContextRaw(ctx context.Context) (MD, [][]string, bool) {
251257
raw, ok := ctx.Value(mdOutgoingKey{}).(rawMD)
252258
if !ok {
253259
return nil, nil, false

stream.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth
184184
// when the RPC completes.
185185
opts = append([]CallOption{OnFinish(func(error) { cc.idlenessMgr.OnCallEnd() })}, opts...)
186186

187-
if md, added, ok := metadata.FromOutgoingContextRaw(ctx); ok {
187+
fromOutgoingCtxRaw := internal.FromOutgoingContextRaw.(func(context.Context) (metadata.MD, [][]string, bool))
188+
if md, added, ok := fromOutgoingCtxRaw(ctx); ok {
188189
// validate md
189190
if err := imetadata.Validate(md); err != nil {
190191
return nil, status.Error(codes.Internal, err.Error())

0 commit comments

Comments
 (0)