[
https://issues.apache.org/jira/browse/CAMEL-27235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18148247#comment-18148247
]
Federico Mariani commented on CAMEL-27235:
------------------------------------------
Hi [~ayushkul2005] feel free to work on it and open the PRs. Thanks for the help
> camel-http-common - a form-urlencoded body with a field without = fails the
> request with 500 ("expected to be a pair"), for example on Spring Boot
> platform-http
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27235
> URL: https://issues.apache.org/jira/browse/CAMEL-27235
> Project: Camel
> Issue Type: Bug
> Components: camel-http-common
> Affects Versions: 4.23.0
> Reporter: Federico Mariani
> Priority: Minor
>
> {{DefaultHttpBinding.readFormUrlEncodedBody}} splits an
> {{application/x-www-form-urlencoded}} body on {{&}} and {{=}}, and throws
> {{IllegalArgumentException("Invalid parameter, expected to be a pair but was
> ...")}} for a field without {{=}}. The request fails with 500 before the
> route runs.
> A field without {{=}} is valid: the URL-encoded form parser of the WHATWG URL
> standard reads it as a name with an empty value, and so does Vert.x
> (platform-http on Camel Main and Camel Quarkus).
> The common way to hit it is {{curl -d "some text"}}, which sends the text as
> {{application/x-www-form-urlencoded}}.
> h3. Reproducer
> Camel Spring Boot 4.23.0 ({{camel run form.camel.yaml
> --runtime=spring-boot}}), with this route:
> {noformat}
> - route:
> id: echo
> from:
> uri: platform-http
> parameters:
> path: /echo
> steps:
> - setBody:
> expression:
> simple:
> expression: "type=${body?.getClass().getName()} body=${body}"
> {noformat}
> {noformat}
> curl -i -X POST http://localhost:8080/echo -d "Hi, I'm [email protected]. My
> order is late, can you refund it?"
> HTTP/1.1 500
> {noformat}
> {noformat}
> WARN SpringBootPlatformHttpConsumer : Error handling request due to:
> java.lang.IllegalArgumentException: Invalid parameter, expected to be a pair
> but was Hi, I'm [email protected]. My order is late, can you refund it?
> Caused by: java.lang.IllegalArgumentException: Invalid parameter, expected to
> be a pair but was Hi, I'm [email protected]. My order is late, can you refund
> it?
> at
> org.apache.camel.http.common.DefaultHttpBinding.readFormUrlEncodedBody(DefaultHttpBinding.java:306)
> at
> org.apache.camel.http.common.DefaultHttpBinding.readRequest(DefaultHttpBinding.java:133)
> at
> org.apache.camel.component.platform.http.springboot.SpringBootPlatformHttpBinding.readRequest(SpringBootPlatformHttpBinding.java:308)
> at
> org.apache.camel.component.platform.http.springboot.PlatformHttpMessage.init(PlatformHttpMessage.java:76)
> {noformat}
> With {{-H 'Content-Type: text/plain'}} the same request returns 200. The code
> is the same on main.
> Other consumers that use {{DefaultHttpBinding}} are probably affected too
> (not tested), and {{DefaultNettyHttpBinding}} (camel-netty-http) has the same
> check. CAMEL-4871 fixed the same exception for an empty body.
> h3. Possible fix
> Read a field without {{=}} as a name with an empty value. The field then
> becomes a message header, so the response must also cope with a header name
> that is not a valid HTTP header name: see the linked
> camel-platform-http-vertx issue, where that is what fails.
> _Claude Code on behalf of Croway_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)