{"record":{"id":"cef07cce30122d0b","repo":"apache/druid","slug":"cannot-figure-out-default-port-for-protocol-s-p","errorCode":null,"errorMessage":"Cannot figure out default port for protocol[%s], please set Host header.","messagePattern":"Cannot figure out default port for protocol\\[(.+?)\\], please set Host header\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/http/client/NettyHttpClient.java","lineNumber":465,"sourceCode":"      return 0;\n    } else {\n      return timeout;\n    }\n  }\n\n  private String getHost(URL url)\n  {\n    int port = url.getPort();\n\n    if (port == -1) {\n      final String protocol = url.getProtocol();\n\n      if (\"http\".equalsIgnoreCase(protocol)) {\n        port = 80;\n      } else if (\"https\".equalsIgnoreCase(protocol)) {\n        port = 443;\n      } else {\n        throw new IAE(\"Cannot figure out default port for protocol[%s], please set Host header.\", protocol);\n      }\n    }\n\n    return url.getHost() + \":\" + port;\n  }\n\n  private String getPoolKey(URL url)\n  {\n    return url.getProtocol() + \"://\" + url.getHost() + \":\"\n           + (url.getPort() == -1 ? url.getDefaultPort() : url.getPort());\n  }\n}\n","sourceCodeStart":447,"sourceCodeEnd":478,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/http/client/NettyHttpClient.java#L447-L478","documentation":"NettyHttpClient.getHost derives a 'host:port' string from the request URL. If the URL carries no explicit port and the protocol is not http or https (e.g. some custom or mistyped scheme), the client cannot infer a default port and throws IAE, advising the caller to set the Host header explicitly.","triggerScenarios":"Executing a request whose URL protocol is not http/https and whose authority lacks a port — e.g. typo'd scheme like 'htp://host/path' or a custom protocol, with no Host header set.","commonSituations":"Hand-built URLs with malformed schemes; config properties containing wrong protocol prefixes; proxy setups where a custom scheme was mistakenly used.","solutions":["Fix the URL scheme to http:// or https://.","Include an explicit port in the URL (e.g. http://host:8080/path) so no default is needed.","Set the Host header (host:port) on the request as the error message suggests.","Validate/normalize configured URLs before passing them to the HttpClient."],"exampleFix":"// before\nString url = \"htp://broker:8082/druid/v2\"; // bad scheme, no default port\n// after\nString url = \"http://broker:8082/druid/v2\";","handlingStrategy":"validation","validationCode":"java.net.URL u = new java.net.URL(rawUrl);\nString scheme = u.getProtocol();\nif (!scheme.equals(\"http\") && !scheme.equals(\"https\")) {\n  throw new IllegalArgumentException(\"URL must use http/https: \" + rawUrl);\n}\nif (u.getPort() == -1 && u.getDefaultPort() == -1) { /* add explicit port */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate configured URLs' schemes at config-load time","Always include an explicit port in internal service URLs","Set the Host header when constructing requests programmatically"],"tags":["http","url","client","illegal-argument"],"backgroundTag":"invalid-url-format","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}