Skip to content

feat(mediatype): add ResponseTypeFunc for dynamic response headers#167

Merged
alexferl merged 1 commit into
masterfrom
mediatype_func
Apr 4, 2026
Merged

feat(mediatype): add ResponseTypeFunc for dynamic response headers#167
alexferl merged 1 commit into
masterfrom
mediatype_func

Conversation

@alexferl

@alexferl alexferl commented Apr 4, 2026

Copy link
Copy Markdown
Owner

Replace static ResponseTypeValue with ResponseTypeFunc that transforms the negotiated media type into the response header value. This enables the header to reflect what was actually negotiated (e.g., app.v2 when client requests v2) rather than a static construction-time value.

Changes:

  • Config.ResponseTypeValue → Config.ResponseTypeFunc func(string) string
  • Compute effective type at request time based on matched Accept header
  • Add VendorShortType helper: "application/vnd.app.v1+json" -> "app.v1"
  • Add findMatchingType to determine which allowed type matched

Replace static ResponseTypeValue with ResponseTypeFunc that transforms
the negotiated media type into the response header value. This enables
the header to reflect what was actually negotiated (e.g., app.v2 when
client requests v2) rather than a static construction-time value.

Changes:
- Config.ResponseTypeValue → Config.ResponseTypeFunc func(string) string
- Compute effective type at request time based on matched Accept header
- Add VendorShortType helper: "application/vnd.app.v1+json" -> "app.v1"
- Add findMatchingType to determine which allowed type matched

Signed-off-by: alexferl <me@alexferl.com>
@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 23969927009

Details

  • 31 of 36 (86.11%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.03%) to 93.913%

Changes Missing Coverage Covered Lines Changed/Added Lines %
middleware/mediatype/media_type.go 31 36 86.11%
Totals Coverage Status
Change from base Build 23969338537: -0.03%
Covered Lines: 10569
Relevant Lines: 11254

💛 - Coveralls

@alexferl alexferl merged commit 6cbba60 into master Apr 4, 2026
9 checks passed
@alexferl alexferl deleted the mediatype_func branch April 4, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants