{"record":{"id":"96c003348cad0376","repo":"XX-net/XX-Net","slug":"http-proxy-host-can-t-parsed-s-s","errorCode":null,"errorMessage":"http proxy host can't parsed. %s %s","messagePattern":"http proxy host can't parsed\\. (.+?) (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/x_tunnel/local/proxy_handler.py","lineNumber":369,"sourceCode":"\n            p = url[7:].find(b\"/\")\n            if p >= 0:\n                path = url[7+p:]\n            else:\n                path = b\"/\"\n        else:\n            header_block = self.read_headers()\n            lines = header_block.split(b\"\\r\\n\")\n            path = url\n            host = None\n            headers = {}\n            for line in lines:\n                key, _, value = line.partition(b\":\")\n                headers[key] = value\n                if key.lower() == b\"host\":\n                    host, port = netloc_to_host_port(value)\n            if host is None:\n                xlog.warn(\"http proxy host can't parsed. %s %s\", req_line, header_block)\n                self.connection.send(b'HTTP/1.1 500 Fail\\r\\n\\r\\n')\n                return\n\n            if url.startswith(b\"/openai/\"):\n                content_length = int(headers.get(b\"Content-Length\", 0))\n                req_body = self.read_bytes(content_length)\n                return openai_handler.handle_openai(method, url, headers, req_body, self.connection)\n\n        sock = self.connection\n        conn_id = proxy_session.create_conn(sock, host, port)\n        if not conn_id:\n            xlog.warn(\"http create conn to %s:%d fail\", host, port)\n            sock.send(b'HTTP/1.1 500 Fail\\r\\n\\r\\n')\n            return\n\n        xlog.info(\"http %r connect to %s:%d conn:%d\", self.client_address, host, port, conn_id)\n\n        new_req_line = b\"%s %s %s\" % (method, path, http_version)","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/x_tunnel/local/proxy_handler.py#L351-L387","documentation":"While handling an absolute-form or proxy-style HTTP request, x_tunnel's http_handler could not find a Host header (or could not parse one into host/port via netloc_to_host_port). The proxy needs the destination host before it can create an outbound connection, so it logs the request line and header block and returns 'HTTP/1.1 500 Fail' to the client.","triggerScenarios":"A client sends an HTTP/1.1 request through the local proxy without a Host header (HTTP/1.0-style client), or with a malformed Host value (e.g. 'Host: :8080', empty value, or non-ASCII bytes) that netloc_to_host_port cannot split into host and port.","commonSituations":"Legacy HTTP/1.0 tools or custom sockets that omit Host; health-check probes (e.g. 'GET / HTTP/1.0') from load balancers; malformed hand-written raw requests in tests; clients sending Host with a value that has no port and breaks the parser.","solutions":["Fix the client to send a valid 'Host: host[:port]' header on every proxied HTTP/1.1 request.","Check the logged req_line/header_block in the warning to see exactly what the client sent and which header is missing or malformed.","If you control the client, prefer origin-form requests with an explicit proxy (absolute URI) so the target can be taken from the request line.","As a defensive improvement, fall back to parsing the host out of an absolute-form URL when the Host header is absent."],"exampleFix":"# before\nrequest = b'GET / HTTP/1.1\\r\\n\\r\\n'  # no Host header\n\n# after\nrequest = b'GET / HTTP/1.1\\r\\nHost: example.com\\r\\n\\r\\n'","handlingStrategy":"validation","validationCode":"# before proxying, validate the request has a parseable Host\nhost_header = headers.get(b'Host') or headers.get(b'host')\nif not host_header:\n    conn.send(b'HTTP/1.1 400 Bad Request\\r\\n\\r\\n')\nelse:\n    proxy.http_handler(req)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always send a Host header in HTTP/1.1 requests through the proxy.","Validate outgoing request headers in client code before writing to the socket."],"tags":["http","proxy","header-parsing","host-header"],"backgroundTag":"malformed-http-header","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}