MCPcopy
hub / github.com/grpc/grpc-go / Match

Method Match

internal/xds/xdsclient/xdsresource/matcher.go:93–124  ·  view source on GitHub ↗

Match returns true if all matchers return true.

(info iresolver.RPCInfo)

Source from the content-addressed store, hash-verified

91
92// Match returns true if all matchers return true.
93func (a *CompositeMatcher) Match(info iresolver.RPCInfo) bool {
94 if a.pm != nil && !a.pm.match(info.Method) {
95 return false
96 }
97
98 // Call headerMatchers even if md is nil, because routes may match
99 // non-presence of some headers.
100 var md metadata.MD
101 if info.Context != nil {
102 md, _ = metadata.FromOutgoingContext(info.Context)
103 if extraMD, ok := grpcutil.ExtraMetadata(info.Context); ok {
104 md = metadata.Join(md, extraMD)
105 // Remove all binary headers. They are hard to match with. May need
106 // to add back if asked by users.
107 for k := range md {
108 if strings.HasSuffix(k, "-bin") {
109 delete(md, k)
110 }
111 }
112 }
113 }
114 for _, m := range a.hms {
115 if !m.Match(md) {
116 return false
117 }
118 }
119
120 if a.fm != nil && !a.fm.match() {
121 return false
122 }
123 return true
124}
125
126func (a *CompositeMatcher) String() string {
127 var ret string

Callers

nothing calls this directly

Calls 5

FromOutgoingContextFunction · 0.92
ExtraMetadataFunction · 0.92
JoinFunction · 0.92
matchMethod · 0.65
MatchMethod · 0.65

Tested by

no test coverage detected