{"record":{"id":"c69cf13baf4abb3b","repo":"composer/composer","slug":"unable-to-find-proxy-host-in-envname","errorCode":null,"errorMessage":"unable to find proxy host in {envName}","messagePattern":"unable to find proxy host in (.+?)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Composer/Util/Http/ProxyItem.php","lineNumber":48,"sourceCode":"    private $optionsAuth;\n\n    /**\n     * @param string $proxyUrl The value from the environment\n     * @param string $envName The name of the environment variable\n     * @throws \\RuntimeException If the proxy url is invalid\n     */\n    public function __construct(string $proxyUrl, string $envName)\n    {\n        $syntaxError = sprintf('unsupported `%s` syntax', $envName);\n\n        if (strpbrk($proxyUrl, \"\\r\\n\\t\") !== false) {\n            throw new \\RuntimeException($syntaxError);\n        }\n        if (false === ($proxy = parse_url($proxyUrl))) {\n            throw new \\RuntimeException($syntaxError);\n        }\n        if (!isset($proxy['host'])) {\n            throw new \\RuntimeException('unable to find proxy host in ' . $envName);\n        }\n\n        $scheme = isset($proxy['scheme']) ? strtolower($proxy['scheme']) . '://' : 'http://';\n        $safe = '';\n\n        if (isset($proxy['user'])) {\n            $safe = '***';\n            $user = $proxy['user'];\n            $auth = rawurldecode($proxy['user']);\n\n            if (isset($proxy['pass'])) {\n                $safe .= ':***';\n                $user .= ':' . $proxy['pass'];\n                $auth .= ':' . rawurldecode($proxy['pass']);\n            }\n\n            $safe .= '@';\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/composer/composer/blob/6ffc1177404d0c50119c22dde6564a380f4a82c9/src/Composer/Util/Http/ProxyItem.php#L30-L66","documentation":"Thrown by ProxyItem when parse_url() succeeded but returned no 'host' component — the proxy URL has a scheme/port but no reachable host. Composer needs a host to build the curl CONNECT target, so it refuses the configuration. The message names the offending env var.","triggerScenarios":"Values like `http://:8080`, `https://`, or a bare port `8080` where parse_url treats the segment as path/port rather than host. Triggered when Composer first constructs the ProxyItem from the environment.","commonSituations":"Forgotten hostname in templated CI config, partially overwritten env var, or a value constructed by concatenating only scheme+port. Common when the hostname comes from a separate variable that was never set.","solutions":["Re-export the env var including the host: `export HTTP_PROXY=http://proxy.example.com:8080`.","If the host lives in a separate variable, ensure it is set before composing the URL.","Validate with `php -r 'var_dump(parse_url(getenv(\"HTTP_PROXY\"), PHP_URL_HOST));'`.","Unset the variable if no proxy is intended."],"exampleFix":"// before\nexport HTTP_PROXY=\"http://:8080\"\n// after\nexport HTTP_PROXY=\"http://proxy.example.com:8080\"","handlingStrategy":"validation","validationCode":"function assertProxyHost(string $url, string $envName): void {\n    $p = parse_url($url);\n    if ($p === false || empty($p['host'])) {\n        throw new \\InvalidArgumentException($envName.' missing proxy host');\n    }\n}","typeGuard":"function proxyHasHost(string $v): bool { $p = parse_url($v); return $p !== false && !empty($p['host']); }","tryCatchPattern":"try { new \\Composer\\Util\\Http\\ProxyItem($url, $envName); } catch (\\RuntimeException $e) {\n    if (str_starts_with($e->getMessage(), 'unable to find proxy host')) {\n        throw new \\RuntimeException('Re-export '.$envName.' as http://HOST:PORT', 0, $e);\n    }\n    throw $e;\n}","preventionTips":["Always include the hostname in proxy URLs.","Verify host-producing variables are set before composing the URL.","Lint proxy URLs in CI."],"tags":["network","proxy","config","environment","composer"],"analyzedSha":"6ffc1177404d0c50119c22dde6564a380f4a82c9","analyzedAt":"2026-08-07T00:01:08.491Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}