Skip to content

Add response content negotiation with [Writes] and ConnegMode#2437

Merged
jeremydmiller merged 1 commit intomainfrom
2406-content-negotiation
Apr 4, 2026
Merged

Add response content negotiation with [Writes] and ConnegMode#2437
jeremydmiller merged 1 commit intomainfrom
2406-content-negotiation

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

  • Adds [Writes("content-type")] attribute for marking methods as content type-specific response writers
  • New ContentNegotiationWriterPolicy (IResourceWriterPolicy) discovers [Writes] methods and generates Accept header-based dispatch code
  • ConnegMode enum: Loose (default, JSON fallback) vs Strict (406 Not Acceptable)
  • [StrictConneg] ModifyHttpChainAttribute for per-endpoint strict mode
  • ConnegMode property on HttpChain for programmatic configuration
  • [Reads("content-type")] attribute placeholder for future request body negotiation
  • Zero runtime reflection — content type dispatch is compiled at startup
  • 7 integration tests via Alba (text/plain, text/csv, JSON fallback, strict 406, loose mode)
  • Documentation page with usage guide

Closes #2406

Test plan

  • Content negotiation tests: dotnet test src/Http/Wolverine.Http.Tests/ --framework net9.0 --filter ContentNegotiationTests (7/7 pass)
  • Full HTTP test suite: 560 passed, 10 skipped, 0 failed

🤖 Generated with Claude Code

Implements response-side content negotiation where methods decorated with
[Writes("content-type")] are discovered on handler types and code-generated
as Accept header-based dispatch. Supports multiple content type writers per
endpoint, Loose mode (JSON fallback, default) and Strict mode (406 Not
Acceptable), and a [StrictConneg] ModifyHttpChainAttribute.

- [Writes] attribute to mark methods as content type writers
- [Reads] attribute placeholder for future request body negotiation
- ConnegMode enum (Loose/Strict) on HttpChain
- [StrictConneg] attribute for per-endpoint strict mode
- ContentNegotiationWriterPolicy as IResourceWriterPolicy
- Code-generated Accept header branching (zero runtime reflection)
- 7 integration tests via Alba
- Documentation page with usage guide

Closes #2406

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jeremydmiller jeremydmiller force-pushed the 2406-content-negotiation branch from 2d00e2a to 701e9d6 Compare April 4, 2026 03:17
@jeremydmiller jeremydmiller merged commit 38ea78e into main Apr 4, 2026
17 of 19 checks passed
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.

Custom content negotiation via ReadBody/WriteResponse conventions in Wolverine.HTTP

1 participant