Skip to content

Fix HTTP response charset parameter parsing - #3654

Open
hutiefang76 wants to merge 1 commit into
alibaba:1.8from
hutiefang76:frank/oss-http-charset-20261007-01a11186
Open

hutiefang76 wants to merge 1 commit into
alibaba:1.8from
hutiefang76:frank/oss-http-charset-20261007-01a11186

Conversation

@hutiefang76

Copy link
Copy Markdown

Describe what this PR does / why we need it

Decode HTTP response bodies using the declared charset for Content-Type values such as text/plain;charset=ISO-8859-1, charset="ISO-8859-1" and a charset followed by other parameters. Splitting the header on spaces either misses the charset or passes quotes/semicolons to Charset.forName.

Does this pull request fix one issue?

Fixes #3652.

Describe how you did it

Split media-type parameters on semicolons outside quoted values, respect quoted-pair escapes while splitting, and match the charset parameter case-insensitively. Reset to the configured default when no usable charset is declared. Unsupported charsets still raise the existing explicit exception.

Describe how to verify it

  • JDK 17: mvn -pl sentinel-transport/sentinel-transport-simple-http -am -Dtest=SimpleHttpResponseTest,HttpEventTaskTest,CommandCenterTest -Dsurefire.failIfNoSpecifiedTests=false verify — 19 tests passed.
  • JDK 8 toolchain: SimpleHttpResponseTest — 10 tests passed.
  • Tests cover omitted/quoted/no-space/mixed-case/trailing parameters, semicolons inside quoted values, mutated headers, non-ASCII bodies and unsupported charsets.

Special notes for reviews

Closed PR #1590 only added null checking; this change addresses parameter parsing. No new dependency or configuration option.

AI assistance: DeepSeek and Codex assisted implementation, tests and this description.

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.

[BUG] Content-Type charset parameters are parsed incorrectly

1 participant