Ayush0612005 opened a new pull request, #30509: URL: https://github.com/apache/camel/pull/30509
# Description [CAMEL-27235](https://issues.apache.org/jira/browse/CAMEL-27235): an `application/x-www-form-urlencoded` body with a field without `=` fails the request with 500 before the route runs. `curl -d "some text"` sends exactly that. `DefaultHttpBinding.readFormUrlEncodedBody` threw `IllegalArgumentException("Invalid parameter, expected to be a pair ...")` for such a field, and so did the same loop in `DefaultNettyHttpBinding` (camel-netty-http), where the server closes the connection without a response. Spring Boot platform-http goes through `DefaultHttpBinding`. **Reading the form.** A field without `=` is now a name with an empty value, as in the URL-encoded form parser of the WHATWG URL standard, which is also what Vert.x (platform-http on Camel Main and Quarkus) does. An empty field, as in `a=1&&b=2`, is skipped; before, it failed the request the same way. Fields with `=` are read as before. **Writing the response.** As the issue points out, such a field becomes a message header whose name is usually not a valid HTTP header name (`Hi, I'm [email protected]. ...`), and the consumer copies the message headers to the response. The response would then fail after the route has run (Netty validates header names), or send an invalid header. `DefaultHttpBinding.doWriteResponse` and `DefaultNettyHttpBinding` now skip a header whose name is not an RFC 9110 token, with a debug log. The check is a new `HttpHelper.isValidHeaderName` in camel-http-base, which both modules use. A header with a valid name is written as before. The Vert.x side of the response (CAMEL-27236) is a separate, assigned issue and is not changed here. `SpringBootPlatformHttpBinding` overrides `doWriteDirectResponse` but not `doWriteResponse`, so it gets the header check. # Tests - `HttpHelperTest#testIsValidHeaderName` (camel-http-base): tokens, empty and null names, spaces, `:`, CR/LF and non-ASCII characters. - `DefaultHttpBindingFormUrlEncodedTest` (camel-http-common): a field without `=`; a mix of fields with and without `=`, an empty field, `+` and percent decoding; an invalid header name is not added to the response while a valid one is. - `NettyHttpPostFormFieldWithoutValueTest` (camel-netty-http): a request whose body is a text plus `&a=1` gets a 200 with the route's body, the `a` header comes back, and the text header does not. Without the change, the camel-http-common tests fail with `expected to be a pair`, and the Netty test with `No response received from remote server`. `HttpHelperTest`, `DefaultHttpBinding*Test`, `NettyHttpBindingPreservePostFormUrlEncodedBodyTest` and `NettyHttpPostDataTest` pass. # 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. - [x] I built the three changed modules with `install` (including code generation, `formatter:format` and `impsort:sort`); no generated file changed. _Claude Code on behalf of Ayush0612005_ -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
