Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.doris.thrift.TNetworkAddress;

import com.google.common.base.Strings;
import com.google.common.net.HostAndPort;
import io.netty.handler.codec.http.HttpHeaderNames;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -504,14 +505,11 @@ private TNetworkAddress selectEndpointByRedirectPolicy(HttpServletRequest req, B
}

String reqHost = "";
String[] pair = reqHostStr.split(":");
if (pair.length == 1) {
reqHost = pair[0];
} else if (pair.length == 2) {
reqHost = pair[0];
} else {
try {
reqHost = HostAndPort.fromString(reqHostStr).getHost();
} catch (IllegalArgumentException e) {
LOG.info("Invalid header host: {}", reqHostStr);
throw new LoadException("Invalid header host: " + reqHost);
throw new LoadException("Invalid header host: " + reqHostStr);
}

// User specified redirect policy
Expand Down Expand Up @@ -579,19 +577,26 @@ private Pair<String, Integer> splitHostAndPort(String hostPort) throws AnalysisE
throw new AnalysisException("empty endpoint: " + hostPort);
}

String[] pair = hostPort.split(":");
if (pair.length != 2) {
String host;
int port;
try {
HostAndPort hp = HostAndPort.fromString(hostPort);
if (!hp.hasPort()) {
throw new IllegalArgumentException("No port found");
}
host = hp.getHost();
port = hp.getPort();
} catch (IllegalArgumentException e) {
LOG.info("Invalid endpoint: {}", hostPort);
throw new AnalysisException("Invalid endpoint: " + hostPort);
}

int port = Integer.parseInt(pair[1]);
if (port <= 0 || port >= 65536) {
LOG.info("Invalid endpoint port: {}", pair[1]);
throw new AnalysisException("Invalid endpoint port: " + pair[1]);
LOG.info("Invalid endpoint port: {}", port);
throw new AnalysisException("Invalid endpoint port: " + port);
}

return Pair.of(pair[0], port);
return Pair.of(host, port);
}

// NOTE: This function can only be used for AuditlogPlugin stream load for now.
Expand Down
Loading