You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "allthingssecurity (via GitHub)" <gi...@apache.org> on 2026/10/05 00:09:31 UTC

[PR] CAMEL-25305: camel-netty-http - write a String body in the charset that the Content-Type declares [camel]

allthingssecurity opened a new pull request, #27346:
URL: https://github.com/apache/camel/pull/27346

   # Description
   
   [CAMEL-25305](https://issues.apache.org/jira/browse/CAMEL-25305)
   
   camel-netty-http converted a `String` body with the exchange charset (`CamelCharsetName`, UTF-8 by default), also when the `Content-Type` declared another charset, so a route answering `text/plain; charset=ISO-8859-1` with `Grüße aus Kâln` sent 17 UTF-8 bytes labelled ISO-8859-1; the producer did the same for the request body. And the request charset was found with the deprecated `HttpUtil.getCharsetFromContentType`, which only matches `charset=` in lower case (parameter names are case-insensitive, RFC 9110 5.6.6), so `Charset=ISO-8859-1` was decoded as UTF-8.
   
   The same defect was fixed for camel-platform-http-vertx (CAMEL-25217) and camel-undertow (CAMEL-25248).
   
   This change:
   - converts a `String` body with the charset the `Content-Type` declares, when there is a supported one (consumer response and producer request); other bodies and messages without a declared charset are converted as before;
   - adds `NettyHttpHelper.getCharsetFromContentType` (case-insensitive, no UTF-8 default) and uses it in the consumer and in `NettyHttpConverter`;
   - adds an upgrade guide note.
   
   Tests: new `NettyHttpStringBodyCharsetTest`: response with a declared ISO-8859-1, request with `Charset=ISO-8859-1`, producer request with a declared ISO-8859-1; control: a response without a charset is UTF-8; a unit test of `NettyHttpHelper.getCharsetFromContentType` (case-insensitive, quoted value, and `null` without a charset parameter, so the exchange charset stays in use). Without the change 3 fail (2 runs), the control passes; with it the module passes (281 tests, 8 skipped).
   
   Found with the Lean 4 model of the String body encoding written for CAMEL-25217: "a peer that decodes with the declared charset reads back the text" fails for every text with a character outside US-ASCII and holds with the change.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
     (I built and tested the affected module, including the formatter and import-sort plugins. I did not run the full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   πŸ€– Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25305: camel-netty-http - write a String body in the charset that the Content-Type declares [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #27346:
URL: https://github.com/apache/camel/pull/27346#discussion_r4181088559


##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java:
##########
@@ -56,6 +56,26 @@ public static void appendHeader(Map<String, Object> headers, String key, Object
         CollectionHelper.appendEntry(headers, key, value);
     }
 
+    /**
+     * Gets the charset parameter of the content type. The parameter name is case-insensitive (RFC 9110, section 5.6.6).
+     *
+     * @param  contentType the content type, may be <tt>null</tt>
+     * @return             the charset name, or <tt>null</tt> if the content type has no charset parameter
+     */
+    public static String getCharsetFromContentType(String contentType) {
+        if (contentType == null) {
+            return null;
+        }
+        String[] parts = contentType.split(";");
+        for (int i = 1; i < parts.length; i++) {
+            String part = parts[i].trim();
+            if (part.regionMatches(true, 0, "charset=", 0, 8)) {
+                return IOHelper.normalizeCharset(part.substring(8));

Review Comment:
   `text/plain; charset=` (empty value) returns `""` here. The consumer then sets an empty `CamelCharsetName` on the exchange, and later conversions fail in `Charset.forName("")`. `UndertowHelper.getCharsetFromContentType` guards this case; please do the same (`ObjectHelper` is already imported):
   
   ```suggestion
                   String name = IOHelper.normalizeCharset(part.substring(8));
                   return ObjectHelper.isEmpty(name) ? null : name;
   ```



##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc:
##########
@@ -780,6 +780,16 @@ The `charset` parameter of a `Content-Type` was only recognized in lower case. A
 `String` body with such a `Content-Type` was written as UTF-8. The parameter name is now matched case-insensitively
 (RFC 9110), as in the other HTTP components, on the consumer (request and response) and on the producer.
 
+=== camel-netty-http - String bodies in the charset of the Content-Type
+
+The Netty HTTP consumer (response) and producer (request) wrote a `String` body in the charset of the exchange
+(`CamelCharsetName`, UTF-8 by default), even when the `Content-Type` declared another charset (for example
+`text/plain; charset=ISO-8859-1` set by the route). A `String` body is now written in the charset that the
+`Content-Type` declares. Bodies that are not a `String`, and messages whose `Content-Type` declares no charset, are
+sent as before. Also, the `charset` parameter of a received `Content-Type` (a request on the consumer) is now
+recognized whatever its case (`Charset=ISO-8859-1`). A peer that ignored the declared charset and read such a message as UTF-8 must now use the

Review Comment:
   Nit: this line is much longer than the ~120-column wrap of the surrounding text. Please re-wrap it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25305: camel-netty-http - write a String body in the charset that the Content-Type declares [camel]

Posted by "apupier (via GitHub)" <gi...@apache.org>.
apupier merged PR #27346:
URL: https://github.com/apache/camel/pull/27346


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25305: camel-netty-http - write a String body in the charset that the Content-Type declares [camel]

Posted by "allthingssecurity (via GitHub)" <gi...@apache.org>.
allthingssecurity commented on code in PR #27346:
URL: https://github.com/apache/camel/pull/27346#discussion_r4181332139


##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java:
##########
@@ -56,6 +56,26 @@ public static void appendHeader(Map<String, Object> headers, String key, Object
         CollectionHelper.appendEntry(headers, key, value);
     }
 
+    /**
+     * Gets the charset parameter of the content type. The parameter name is case-insensitive (RFC 9110, section 5.6.6).
+     *
+     * @param  contentType the content type, may be <tt>null</tt>
+     * @return             the charset name, or <tt>null</tt> if the content type has no charset parameter
+     */
+    public static String getCharsetFromContentType(String contentType) {
+        if (contentType == null) {
+            return null;
+        }
+        String[] parts = contentType.split(";");
+        for (int i = 1; i < parts.length; i++) {
+            String part = parts[i].trim();
+            if (part.regionMatches(true, 0, "charset=", 0, 8)) {
+                return IOHelper.normalizeCharset(part.substring(8));

Review Comment:
   Done in c69826ad69b2: `getCharsetFromContentType` returns `null` for an empty value (`charset=` and `charset=""`), as
   `UndertowHelper` does. Added a unit check for both forms and a consumer test: a request with `text/plain; charset=`
   sets no `CamelCharsetName` and its body is read as before. Both checks fail without the guard. For the record, the
   deprecated `HttpUtil.getCharsetFromContentType` that the consumer used on main also returned `""` here, so this was not
   new in the PR, but it is fixed now. Module suite: 282 tests, 0 failures, 8 skipped.
   
   _Claude Code on behalf of allthingssecurity_
   



##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc:
##########
@@ -780,6 +780,16 @@ The `charset` parameter of a `Content-Type` was only recognized in lower case. A
 `String` body with such a `Content-Type` was written as UTF-8. The parameter name is now matched case-insensitively
 (RFC 9110), as in the other HTTP components, on the consumer (request and response) and on the producer.
 
+=== camel-netty-http - String bodies in the charset of the Content-Type
+
+The Netty HTTP consumer (response) and producer (request) wrote a `String` body in the charset of the exchange
+(`CamelCharsetName`, UTF-8 by default), even when the `Content-Type` declared another charset (for example
+`text/plain; charset=ISO-8859-1` set by the route). A `String` body is now written in the charset that the
+`Content-Type` declares. Bodies that are not a `String`, and messages whose `Content-Type` declares no charset, are
+sent as before. Also, the `charset` parameter of a received `Content-Type` (a request on the consumer) is now
+recognized whatever its case (`Charset=ISO-8859-1`). A peer that ignored the declared charset and read such a message as UTF-8 must now use the

Review Comment:
   Re-wrapped to the ~120 columns of the surrounding text in c69826ad69b2.
   
   _Claude Code on behalf of allthingssecurity_
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25305: camel-netty-http - write a String body in the charset that the Content-Type declares [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27346:
URL: https://github.com/apache/camel/pull/27346#issuecomment-5988931541

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25305: camel-netty-http - write a String body in the charset that the Content-Type declares [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27346:
URL: https://github.com/apache/camel/pull/27346#issuecomment-5989097451

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `components/camel-netty-http`
   - `docs`
   
   > :information_source: Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the `test-dependents` label to force testing all dependents.
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison β€” Scalpel: 35 of 698 tested, 26 compile-only β€” current: 35 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **35 affected modules** (current approach: 35).
   
   **Skip-tests mode would test 35 modules** (2 direct + 34 downstream), **skip tests for 26** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (35)</summary>
   
   - `camel-a2a` ← downstream of org.apache.camel:camel-platform-http-vertx
   - `camel-clickup` ← downstream of org.apache.camel:camel-netty-http
   - `camel-java-joor-dsl` ← downstream of org.apache.camel:camel-telegram
   - `camel-jbang-mcp` ← downstream of org.apache.camel:camel-xml-io-dsl
   - `camel-jbang-plugin-mcp` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-route-parser` ← downstream of org.apache.camel:camel-route-parser
   - `camel-jbang-plugin-tui` ← downstream of org.apache.camel:camel-catalog
   - `camel-jbang-plugin-validate` ← downstream of org.apache.camel:camel-yaml-dsl-validator
   - `camel-jsonpath` ← downstream of org.apache.camel:camel-platform-http-vertx
   - `camel-knative-http` ← downstream of org.apache.camel:camel-platform-http-vertx
   - `camel-launcher-container` ← downstream of org.apache.camel:camel-launcher
   - `camel-mcp-server` ← downstream of org.apache.camel:camel-platform-http-vertx
   - `camel-micrometer-prometheus` ← downstream of org.apache.camel:camel-platform-http-main
   - `camel-netty-http` ← components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java, components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConverter.java, components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java, components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java, components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpStringBodyCharsetTest.java
   - `camel-oauth` ← downstream of org.apache.camel:camel-platform-http-main
   - `camel-observability-services` ← downstream of org.apache.camel:camel-micrometer-prometheus
   - `camel-openai` ← downstream of org.apache.camel:camel-platform-http-vertx
   - `camel-openapi-validator` ← downstream of org.apache.camel:camel-rest-openapi
   - `camel-platform-http-main` ← downstream of org.apache.camel:camel-platform-http-vertx
   - `camel-platform-http-vertx` ← downstream of org.apache.camel:camel-rest-openapi
   - `camel-rest-openapi` ← downstream of org.apache.camel:camel-netty-http
   - `camel-semantic` ← downstream of org.apache.camel:camel-xml-io-dsl
   - `camel-state-store` ← downstream of org.apache.camel:camel-test-main-junit5
   - `camel-telegram` ← downstream of org.apache.camel:camel-netty-http
   - `camel-test-main-junit5` ← downstream of org.apache.camel:camel-xml-io-dsl
   - `camel-test-main-junit6` ← downstream of org.apache.camel:camel-xml-io-dsl
   - `camel-typesafe-ai` ← downstream of org.apache.camel:camel-xml-io-dsl
   - `camel-webhook` ← downstream of org.apache.camel:camel-netty-http
   - `camel-whatsapp` ← downstream of org.apache.camel:camel-netty-http
   - `camel-xml-io-dsl` ← downstream of org.apache.camel:camel-telegram
   - `camel-xml-jaxb-dsl` ← downstream of org.apache.camel:camel-telegram
   - `camel-xml-jaxb-dsl-test-definition` ← downstream of org.apache.camel:camel-telegram
   - `camel-xml-jaxb-dsl-test-spring` ← downstream of org.apache.camel:camel-telegram
   - `camel-yaml-dsl-validator` ← downstream of org.apache.camel:camel-yaml-dsl
   - `camel-yaml-dsl-validator-maven-plugin` ← downstream of org.apache.camel:camel-yaml-dsl-validator
   
   </details>
   
   <details><summary>Modules with tests skipped (26)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog`
   - `camel-catalog-console`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `camel-endpointdsl`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `dummy-component`
   
   </details>
   
   > :information_source: Shadow mode β€” Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   <details><summary>Build reactor β€” dependencies compiled but only changed modules were tested (2 modules, 14.6s total)</summary>
   
   **Total reactor time:** 14.6s
   
   | Module | Duration | Status |
   | --- | --- | --- |
   | Camel :: Docs | 14.6s | SUCCESS |
   | Camel :: Netty HTTP | n/a |  |
   
   **Top 20 slowest modules:**
   - `Camel :: Docs` (14.6s)
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/37246381159)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org