[ 
https://issues.apache.org/jira/browse/CAMEL-27235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18148242#comment-18148242
 ] 

Ayush Kulshreshtha commented on CAMEL-27235:
--------------------------------------------

I’d like to work on this. Could a committer assign it to me (ayushkul2005)?

I have a fix with tests ready, following the approach in the description:
 * In \{{DefaultHttpBinding.readFormUrlEncodedBody}}, and in the same loop in 
\{{DefaultNettyHttpBinding}} (camel-netty-http), a field without \{{=}} is read 
as a name with an empty value, as the WHATWG form parser and Vert.x do. An 
empty field, as in \{{a=1&&b=2}}, is skipped. It used to fail the request in 
the same way.
 * As you pointed out, such a field becomes a message header whose name is 
usually not a valid HTTP header name. \{{DefaultHttpBinding.doWriteResponse}} 
and the Netty binding now skip a header whose name is not an RFC 9110 token, 
with a debug log, so the response does not fail after the route has run. The 
check is a new \{{HttpHelper.isValidHeaderName}} in camel-http-base. 
CAMEL-27236 (Vert.x) is not changed.

I’ll open the PR shortly.

_Claude Code on behalf of Ayush0612005_

> 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)

Reply via email to