{"record":{"id":"152016de1e8abbe6","repo":"XIU2/CloudflareSpeedTest","slug":"ip-s-http-d-s","errorCode":null,"errorMessage":"[调试] IP: %s, 延迟测速终止，HTTP 状态码: %d, 测速地址: %s","messagePattern":"\\[调试\\] IP: (.+?), 延迟测速终止，HTTP 状态码: (.+?), 测速地址: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"task/httping.go","lineNumber":67,"sourceCode":"\t\t\t}\n\t\t\treturn 0, 0, \"\"\n\t\t}\n\t\trequest.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36\")\n\t\tresponse, err := hc.Do(request)\n\t\tif err != nil {\n\t\t\tif utils.Debug { // 调试模式下，输出更多信息\n\t\t\t\tutils.Red.Printf(\"[调试] IP: %s, 延迟测速失败，错误信息: %v, 测速地址: %s\\n\", ip.String(), err, URL)\n\t\t\t}\n\t\t\treturn 0, 0, \"\"\n\t\t}\n\t\tdefer response.Body.Close()\n\n\t\t//fmt.Println(\"IP:\", ip, \"StatusCode:\", response.StatusCode, response.Request.URL)\n\t\t// 如果未指定的 HTTP 状态码，或指定的状态码不合规，则默认只认为 200、301、302 才算 HTTPing 通过\n\t\tif HttpingStatusCode == 0 || HttpingStatusCode < 100 && HttpingStatusCode > 599 {\n\t\t\tif response.StatusCode != 200 && response.StatusCode != 301 && response.StatusCode != 302 {\n\t\t\t\tif utils.Debug { // 调试模式下，输出更多信息\n\t\t\t\t\tutils.Red.Printf(\"[调试] IP: %s, 延迟测速终止，HTTP 状态码: %d, 测速地址: %s\\n\", ip.String(), response.StatusCode, URL)\n\t\t\t\t}\n\t\t\t\treturn 0, 0, \"\"\n\t\t\t}\n\t\t} else {\n\t\t\tif response.StatusCode != HttpingStatusCode {\n\t\t\t\tif utils.Debug { // 调试模式下，输出更多信息\n\t\t\t\t\tutils.Red.Printf(\"[调试] IP: %s, 延迟测速终止，HTTP 状态码: %d, 指定的 HTTP 状态码 %d, 测速地址: %s\\n\", ip.String(), response.StatusCode, HttpingStatusCode, URL)\n\t\t\t\t}\n\t\t\t\treturn 0, 0, \"\"\n\t\t\t}\n\t\t}\n\n\t\tio.Copy(io.Discard, response.Body)\n\n\t\t// 通过头部参数获取地区码\n\t\tcolo = getHeaderColo(response.Header)\n\n\t\t// 只有指定了地区才匹配机场地区码","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/XIU2/CloudflareSpeedTest/blob/1da0c025d7b6f9bf0b2b0cf47a547f65430deab2/task/httping.go#L49-L85","documentation":"Debug branch in task/httping.go:64-70: the first HTTPing response returned a status code outside the accepted set. When -httping-code is 0 (or the intended-invalid check trips, see error 6), only 200, 301, 302 count as pass, so a 403/404/5xx/redirect-code like 308 fails the IP. The IP gets return 0, 0, \"\" and disappears from results.","triggerScenarios":"A -url endpoint that answers non-200 to HEAD on the tested IP: WAF/anti-bot rules returning 403/503, a speed file moved to 404, an origin returning 500, or a CDN that answers HEAD with 405. Also happens when testing non-Cloudflare IP ranges whose anycast serves different status codes.","commonSituations":"Using the default https://cf.xiu2.xyz/url after it started answering errors; self-hosted speed endpoints that reject HEAD; DDoS-protection layers (Cloudflare Under Attack mode) returning 503 challenges; a stale tutorial URL that now 301s to a login page (301 is accepted, but the target content isn't).","solutions":["Probe your -url directly with the same method: curl -I https://your-url and check the status code it actually returns.","If the endpoint legitimately returns a different code every time (e.g. 301 or 204), pass it via -httping-code 301.","If the endpoint is broken, point -url at a reliable, self-hosted static file that answers 200 to HEAD.","When testing non-Cloudflare CDNs, verify what status that CDN returns and set -httping-code accordingly."],"exampleFix":"# before\n./cfst -httping -url https://example.com/speed  # server returns 204 on HEAD\n# after\n./cfst -httping -url https://example.com/speed -httping-code 204","handlingStrategy":"validation","validationCode":"# confirm what the endpoint answers to HEAD before choosing expectations\ncode=$(curl -sI -o /dev/null -w '%{http_code}' https://speed.example.com/)\necho \"endpoint answers: $code\"  # feed this to -httping-code if not 200/301/302","typeGuard":"func acceptedStatus(code int, want int) bool {\n\tif want == 0 { // mirror the default set from httping.go:64-70\n\t\treturn code == 200 || code == 301 || code == 302\n\t}\n\treturn code == want\n}","tryCatchPattern":null,"preventionTips":["curl -I your -url once; anything outside 200/301/302 needs an explicit -httping-code.","Self-host the latency endpoint so status behavior is stable.","Remember default acceptance is exactly 200/301/302 — 204/304 fail."],"tags":["go","httping","http-status","debug-output"],"backgroundTag":null,"analyzedSha":"1da0c025d7b6f9bf0b2b0cf47a547f65430deab2","analyzedAt":"2026-08-15T22:22:10.737Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}