Skip to content

Commit 82d3d16

Browse files
awalterschulzefacebook-github-bot
authored andcommitted
deprecate thrift.WithProtocol
Summary: deprecate thrift.WithProtocol Reviewed By: codyohl Differential Revision: D59577298 fbshipit-source-id: 671b7c90aa984eea0af7d94640a6a4552cf5d6ba
1 parent 29a5b0a commit 82d3d16

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

thrift/lib/go/thrift/context.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,12 @@ func ConnInfoFromContext(ctx context.Context) (ConnInfo, bool) {
7878
return v, ok
7979
}
8080

81-
// WithProtocol attaches thrift protocol to a context
81+
// Deprecated: use thrift.WithHeaders(ctx, proto.GetResponseHeaders())
8282
func WithProtocol(ctx context.Context, proto Protocol) context.Context {
8383
return context.WithValue(ctx, protocolKey, proto)
8484
}
8585

86-
// HeadersFromContext extracts headers for this message, both per-message
87-
// and persistent headers. When both a per-message header and a persistent
88-
// header exist with the same name, the persistent header is returned. This is
89-
// also the behaviour of the C++ implementation.
90-
// This function returns nil when the underlying transport/protocol do not
91-
// support headers.
86+
// Deprecated: Use thrift.GetHeaders
9287
func HeadersFromContext(ctx context.Context) map[string]string {
9388
t, ok := ctx.Value(protocolKey).(Protocol)
9489
if !ok {

thrift/lib/go/thrift/context_headers.go

+24
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ func AddHeader(ctx context.Context, key string, value string) (context.Context,
4343
return ctx, nil
4444
}
4545

46+
// WithHeaders attaches thrift headers to a ctx
47+
func WithHeaders(ctx context.Context, headers map[string]string) context.Context {
48+
return context.WithValue(ctx, headersKey, headers)
49+
}
50+
51+
// GetHeaders gets thrift headers from ctx.
52+
// WithHeaders will set this, and if nothing is set it
53+
// will defer to thrift.HeadersFromContext
54+
// can return nil if there is no headers.
55+
func GetHeaders(ctx context.Context) map[string]string {
56+
// check for headersKey
57+
v, ok := ctx.Value(headersKey).(map[string]string)
58+
if ok {
59+
return v
60+
}
61+
// deprecated
62+
t, ok := ctx.Value(protocolKey).(Protocol)
63+
if !ok {
64+
// A nil map behaves like an empty map for reading.
65+
return nil
66+
}
67+
return t.GetResponseHeaders()
68+
}
69+
4670
// Deprecated: RequestHeaders will eventually be private.
4771
type RequestHeaders interface {
4872
SetRequestHeader(key, value string)

0 commit comments

Comments
 (0)