8000 feat: add opt-in charset/encoding negotiation to ContentNegotiationMiddleware by kawasima · Pull Request #116 · enkan/enkan · GitHub
[go: up one dir, main page]

Skip to content

feat: add opt-in charset/encoding negotiation to ContentNegotiationMiddleware - #116

Merged
kawasima merged 1 commit into
developfrom
feature/opt-in-charset-encoding-negotiation
Mar 28, 2026
Merged

kawasima merged 1 commit into
developfrom
feature/opt-in-charset-encoding-negotiation

Conversation

@kawasima
Copy link
Copy Markdown
Collaborator

Summary

  • Add allowedCharsets and allowedEncodings configuration to ContentNegotiationMiddleware (default null = no negotiation, backward compatible)
  • When configured, negotiate Accept-Charset / Accept-Encoding headers and store results on the request
  • Add getCharset()/setCharset()/getEncoding()/setEncoding() to ContentNegotiable interface
  • All ContentNegotiator methods are now reachable from the middleware, eliminating dead code

Closes #112

Usage

ContentNegotiationMiddleware cnm = new ContentNegotiationMiddleware();
cnm.setAllowedCharsets(Set.of("utf-8", "iso-8859-1"));   // opt-in
cnm.setAllowedEncodings(Set.of("gzip", "deflate"));       // opt-in

Test plan

  • charsetAndEncodingNotNegotiatedByDefault — null by default, backward compatible
  • charsetNegotiatedWhenConfigured — Accept-Charset: utf-8 → getCharset() = "utf-8"
  • encodingNegotiatedWhenConfigured — Accept-Encoding: gzip → getEncoding() = "gzip"
  • charsetAndEncodingBothConfigured — both set together
  • All 11 ContentNegotiationMiddleware tests pass (7 existing + 4 new)

🤖 Generated with Claude Code

…ddleware

ContentNegotiator defines bestAllowedCharset and bestAllowedEncoding
but the middleware never called them. Add allowedCharsets and
allowedEncodings configuration fields (default null = skip). When
configured, the middleware negotiates Accept-Charset / Accept-Encoding
and stores results on the request via ContentNegotiable.

Add charset/encoding accessors to ContentNegotiable interface.

Closes #112

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kawasima
kawasima merged commit b4527ff into develop Mar 28, 2026
1 check 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.

1 participant

0