MCPcopy Create free account
hub / github.com/prometheus/common / matchFormat

Function matchFormat

expfmt/encode.go:175–216  ·  view source on GitHub ↗

matchFormat checks if a parsed accept clause matches a given Format.

(ac goautoneg.Accept, f Format)

Source from the content-addressed store, hash-verified

173
174// matchFormat checks if a parsed accept clause matches a given Format.
175func matchFormat(ac goautoneg.Accept, f Format) bool {
176 target, ok := formatToAccept[f]
177 if !ok {
178 parsed := goautoneg.ParseAccept(string(f))
179 if len(parsed) == 0 {
180 return false
181 }
182 target = parsed[0]
183 }
184
185 if ac.Type != "*" && ac.Type != target.Type {
186 return false
187 }
188 if ac.SubType != "*" && ac.SubType != target.SubType {
189 return false
190 }
191
192 // Default OpenMetrics version to OpenMetricsVersion_0_0_1.
193 acVersion := ac.Params["version"]
194 if acVersion == "" && ac.Type+"/"+ac.SubType == OpenMetricsType {
195 acVersion = OpenMetricsVersion_0_0_1
196 }
197 if acVersion == "" && ac.Type == "text" && ac.SubType == "plain" {
198 acVersion = TextVersion
199 }
200
201 // General param matching.
202 for k, v := range target.Params {
203 if k == "charset" {
204 continue
205 }
206 acVal := ac.Params[k]
207 if k == "version" {
208 acVal = acVersion
209 }
210 if acVal != v {
211 return false
212 }
213 }
214
215 return true
216}
217
218// NewEncoder returns a new encoder based on content type negotiation. All
219// Encoder implementations returned by NewEncoder also implement Closer, and

Callers 1

NegotiateAcceptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected