gnodet-bot commented on code in PR #30509:
URL: https://github.com/apache/camel/pull/30509#discussion_r4644924996
##########
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:
🐛 **`@Deprecated` annotation is now on `decodeFormField`, not on
`shouldUrlDecodeHeader`.**
The new Javadoc (`/**`) was inserted after `@Deprecated(since = "4.4.0")` on
the preceding line. Java binds the annotation to the next declaration it
reaches, skipping the Javadoc — so it annotates `decodeFormField` (this new
private method) instead of `shouldUrlDecodeHeader`. Move `decodeFormField` and
its Javadoc **above** the existing `@Deprecated` + `shouldUrlDecodeHeader`
block:
```suggestion
/**
* 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);
}
}
```
##########
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:
💡 `DefaultHttpBinding` and `HttpProducer` both use
`HttpHelper.sanitizeLog(key)` here. Use it here too for consistency.
```suggestion
HttpHelper.sanitizeLog(key));
```
##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java:
##########
@@ -756,6 +781,15 @@ public HttpRequest toNettyRequest(Message message, String
fullUri, NettyHttpConf
if (skipRequestHeaders != null &&
skipRequestHeaders.containsKey(key)) {
continue;
}
+ if (!HttpHelper.isValidHeaderName(key)) {
+ // a message header can have any name, for example a form
field mapped to a header by a consumer,
+ // but it cannot be sent as an HTTP header
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Skipping header {} in the request, as its name
is not a valid HTTP header name",
+ key.replaceAll("[\n\r]", "_"));
Review Comment:
💡 Same: use `HttpHelper.sanitizeLog(key)` to match the other components.
```suggestion
HttpHelper.sanitizeLog(key));
```
--
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]