Ayush0612005 commented on code in PR #30509:
URL: https://github.com/apache/camel/pull/30509#discussion_r4644993936


##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java:
##########
@@ -341,6 +344,19 @@ protected void copyCamelHeaders(Map<String, Object> 
headers, Exchange exchange)
      * @throws     UnsupportedEncodingException is thrown if error decoding.
      */
     @Deprecated(since = "4.4.0")
+    /**
+     * Decodes a name or a value of a form field as a header with {@link 
#shouldUrlDecodeHeader}. A % that is not
+     * followed by two hex digits, as in a text such as "50% off" sent as form 
data, is kept as it is, as in the
+     * URL-encoded form parser of the WHATWG URL standard, instead of failing 
the request.
+     */
+    private String decodeFormField(NettyHttpConfiguration configuration, 
String headerName, String value) {
+        try {
+            return shouldUrlDecodeHeader(configuration, headerName, value, 
StandardCharsets.UTF_8);
+        } catch (IllegalArgumentException e) {
+            return HttpHelper.decodeFormComponent(value, 
StandardCharsets.UTF_8);
+        }
+    }

Review Comment:
   Good catch, thanks: the annotation had moved to `decodeFormField`. Fixed in 
the latest commit: `decodeFormField` is now above the Javadoc of 
`shouldUrlDecodeHeader(..., String charset)`, which keeps its 
`@Deprecated(since = "4.4.0")`. The netty-http tests pass.
   
   _Claude Code on behalf of Ayush0612005_
   



##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java:
##########
@@ -568,6 +584,15 @@ public HttpResponse toNettyResponse(Message message, 
NettyHttpConfiguration conf
         // must use entrySet to ensure case of keys is preserved
         for (Map.Entry<String, Object> entry : 
message.getHeaders().entrySet()) {
             String key = entry.getKey();
+            if (!HttpHelper.isValidHeaderName(key)) {
+                // a message header can have any name, for example a form 
field mapped to a header,
+                // but it cannot be sent as an HTTP header, and the route has 
already run
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Skipping header {} in the response, as its name 
is not a valid HTTP header name",
+                            key.replaceAll("[\n\r]", "_"));

Review Comment:
   `sanitizeLog` is in the camel-http-common `HttpHelper`, which 
camel-netty-http does not depend on: its `HttpHelper` import is the 
camel-http-base one. So I kept `key.replaceAll("[\n\r]", "_")`, which is what 
`sanitizeLog` does. I can move `sanitizeLog` to camel-http-base if you'd prefer 
one helper.
   
   _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]

Reply via email to