expfmt: fix wildcard content negotiation regression for Negotiate and NegotiateIncludingOpenMetrics - #966
Merged
Conversation
… NegotiateIncludingOpenMetrics Clients sending Accept: */* or browser Accept headers containing wildcards should receive standard Prometheus text format (FmtText) when using Negotiate or NegotiateIncludingOpenMetrics. Previously, matchFormat short-circuited on */*, immediately returning the first format in the accepted list (Protobuf for Negotiate, and OpenMetrics 1.0 for NegotiateIncludingOpenMetrics). Remove the */* short-circuit from matchFormat so wildcard Accept headers fall back to the text-preferring fallback logic in NegotiateAccept. Signed-off-by: David Ashpole <dashpole@google.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a content negotiation regression in expfmt where wildcard Accept headers (e.g., */* and common browser headers containing wildcards) incorrectly selected the first offered format (notably Protobuf / OpenMetrics) instead of falling back to the expected Prometheus text format.
Changes:
- Removes the
*/*short-circuit inmatchFormat, allowing wildcardAcceptheaders to fall through toNegotiateAccept’s text-preferring fallback behavior. - Adds/updates tests to cover
*/*, browser-style wildcard headers, and mixed headers (e.g.,application/json, */*) for bothNegotiateandNegotiateIncludingOpenMetrics. - Updates
NegotiateAcceptwildcard expectations, including the case where no text format is available (fallback to first accepted format).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| expfmt/encode.go | Removes */* special-casing in format matching so wildcard headers no longer force selection of the first accepted format. |
| expfmt/encode_test.go | Adds/updates negotiation tests to verify wildcard Accept headers prefer Prometheus text when available. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
dashpole
marked this pull request as ready for review
August 24, 2026 16:23
bwplotka
approved these changes
Aug 24, 2026
| "github.com/prometheus/common/model" | ||
| ) | ||
|
|
||
| func TestNegotiate(t *testing.T) { |
Member
There was a problem hiding this comment.
observation: Probably a duplicated test, we could DRY here
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a regression introduced by #894.
Clients sending Accept: / or browser Accept headers containing wildcards should receive standard Prometheus text format (FmtText) when using Negotiate or NegotiateIncludingOpenMetrics.
Previously, matchFormat short-circuited on /, immediately returning the first format in the accepted list (Protobuf for Negotiate, and OpenMetrics 1.0 for NegotiateIncludingOpenMetrics).
Remove the / short-circuit from matchFormat so wildcard Accept headers fall back to the text-preferring fallback logic in NegotiateAccept.