gnodet-bot commented on code in PR #31251:
URL: https://github.com/apache/camel/pull/31251#discussion_r4771023074
##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java:
##########
@@ -175,11 +175,33 @@ public void populateCamelHeaders(
headers.put(NettyHttpConstants.HTTP_URI, uri.getPath());
headers.put(NettyHttpConstants.HTTP_QUERY, uri.getQuery());
headers.put(NettyHttpConstants.HTTP_RAW_QUERY, uri.getRawQuery());
- headers.put(NettyHttpConstants.HTTP_SCHEME, uri.getScheme());
- headers.put(NettyHttpConstants.HTTP_HOST, uri.getHost());
+ // when the request URI is relative (e.g. /foo?x=1), uri.getScheme()
and
+ // uri.getHost() return null; fall back to the endpoint configuration.
+ // For absolute URIs (e.g. proxy-style: GET http://example.com/foo
HTTP/1.1),
+ // use the URI's own values so the proxy forwards to the correct
target.
+ final boolean isRelativeUri = uri.getHost() == null;
+ final boolean ssl = configuration.isSsl() ||
"https".equals(uri.getScheme());
+ headers.put(NettyHttpConstants.HTTP_SCHEME, uri.getScheme() != null ?
uri.getScheme() : (ssl ? "https" : "http"));
+ if (isRelativeUri) {
+ // Relative request line: prefer the Host HTTP header (sent by all
HTTP/1.1 clients),
+ // then fall back to configuration.getHost() (consistent with
platform-http-vertx).
+ String hostHeader = request.headers().get(HttpHeaderNames.HOST);
+ if (hostHeader != null && !hostHeader.isEmpty()) {
+ // Strip optional port from the Host header value (e.g.
"example.com:8080" -> "example.com")
+ int colonIdx = hostHeader.lastIndexOf(':');
+ hostHeader = colonIdx > 0 ? hostHeader.substring(0, colonIdx)
: hostHeader;
Review Comment:
⚠️ **IPv6 Host header corruption.** `lastIndexOf(':')` on `[::1]` (IPv6
without port) returns 2, truncating to `[:` — a corrupted address. Per RFC 7230
§5.4, `Host: [::1]` is valid for default-port IPv6 connections. Guard: only
strip the colon if it comes after the closing bracket.
```suggestion
int colonIdx = hostHeader.lastIndexOf(':');
// Guard: only strip port if the colon is not inside an IPv6
bracket
if (colonIdx > 0 && !(hostHeader.startsWith("[") && colonIdx
<= hostHeader.lastIndexOf(']'))) {
hostHeader = hostHeader.substring(0, colonIdx);
}
```
--
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]