{"record":{"id":"28db80be11f4b3c4","repo":"XX-net/XX-Net","slug":"forward-local-fail-command-s-path-s-headers","errorCode":null,"errorMessage":"forward_local fail, command:%s, path:%s, headers: %s, payload: %s","messagePattern":"forward_local fail, command:(.+?), path:(.+?), headers: (.+?), payload: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"code/default/gae_proxy/local/proxy_handler.py","lineNumber":109,"sourceCode":"\n    def forward_local(self):\n        \"\"\"\n        If browser send localhost:xxx request to GAE_proxy,\n        we forward it to localhost.\n        \"\"\"\n        request_headers = dict((k.title(), v) for k, v in list(self.headers.items()))\n        payload = b''\n        if b'Content-Length' in request_headers:\n            try:\n                payload_len = int(request_headers.get(b'Content-Length', 0))\n                payload = self.rfile.read(payload_len)\n            except Exception as e:\n                xlog.warn('forward_local read payload failed:%s', e)\n                return\n\n        response = simple_http_client.request(self.command, self.path, request_headers, payload)\n        if not response:\n            xlog.warn(\"forward_local fail, command:%s, path:%s, headers: %s, payload: %s\",\n                self.command, self.path, request_headers, payload)\n            return\n\n        out_list = []\n        out_list.append(b\"HTTP/1.1 %d\\r\\n\" % response.status)\n        for key in response.headers:\n            key = key.title()\n            out_list.append(b\"%s: %s\\r\\n\" % (key, response.headers[key]))\n        out_list.append(b\"\\r\\n\")\n        out_list.append(response.text)\n\n        self.wfile.write(b\"\".join(out_list))\n\n    def send_method_allows(self, headers, payload):\n        xlog.debug(\"send method allow list for:%s %s\", self.command, self.path)\n        # Refer: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests\n\n        response = \\","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/gae_proxy/local/proxy_handler.py#L91-L127","documentation":"forward_local attempted the local direct HTTP request via simple_http_client.request() and got a falsy response (None/empty), meaning the local connection to the target failed entirely. The command, path, headers and payload are logged for diagnosis before returning.","triggerScenarios":"simple_http_client.request() returns None because the TCP connection to the origin failed, the connection was reset, or the response could not be parsed — e.g. target site unreachable, local network down, DNS failure, or firewall reset.","commonSituations":"Target site blocked or unreachable from the local network; local internet outage; DNS pollution resolving the host to a bogus IP; the site resetting non-proxy connections. Compare with the GAE path: if DIRECT fails but GAE works, it's network blocking.","solutions":["Check basic local connectivity to the host (curl --resolve / ping the resolved IP)","Verify DNS resolution is correct; switch to a trusted DNS resolver to rule out pollution","Let the proxy fall back to the GAE/AGENT path for blocked sites instead of DIRECT","If it affects all sites, fix the local network/firewall before debugging the proxy"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import socket\ntry:\n    socket.create_connection((host, 80), timeout=3).close()\n    direct_ok = True\nexcept OSError:\n    direct_ok = False","typeGuard":null,"tryCatchPattern":"response = simple_http_client.request(...)\nif not response:\n    xlog.warn('forward_local fail ...')\n    self.go_AGENT()  # retry via GAE instead of failing the client","preventionTips":["Add a connectivity precheck before direct forwarding","Automatically fall back to the GAE path when DIRECT returns nothing","Retry once with fresh DNS to dodge polluted resolution"],"tags":["http-proxy","direct-forward","connection-failure","network"],"backgroundTag":"upstream-connection-failed","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}