{"record":{"id":"067c5799a24ae42b","repo":"XTLS/Xray-core","slug":"unexpected-http-status-code-d","errorCode":null,"errorMessage":"unexpected HTTP status code: %d","messagePattern":"unexpected HTTP status code: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main/commands/all/api/shared.go","lineNumber":100,"sourceCode":"\tif s := strings.ToLower(parsedTarget.Scheme); s != \"http\" && s != \"https\" {\n\t\treturn nil, fmt.Errorf(\"invalid scheme: %s\", parsedTarget.Scheme)\n\t}\n\n\tclient := &http.Client{\n\t\tTimeout: 30 * time.Second,\n\t}\n\tresp, err := client.Do(&http.Request{\n\t\tMethod: \"GET\",\n\t\tURL:    parsedTarget,\n\t\tClose:  true,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to dial to %s\", target)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"unexpected HTTP status code: %d\", resp.StatusCode)\n\t}\n\n\tcontent, err := buf.ReadAllToBytes(resp.Body)\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to read HTTP response\")\n\t}\n\n\treturn content, nil\n}\n\nfunc showJSONResponse(m proto.Message) {\n\tif isNil(m) {\n\t\treturn\n\t}\n\tif j, ok := creflect.MarshalToJson(m, true); ok {\n\t\tfmt.Println(j)\n\t} else {\n\t\tfmt.Fprintf(os.Stdout, \"%v\\n\", m)","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/main/commands/all/api/shared.go#L82-L118","documentation":"After a successful fetch, fetchHTTPContent requires exactly HTTP 200; any other status — including other 2xx codes like 204, and all redirects that aren't auto-followed for hand-built requests — is rejected with the numeric code.","triggerScenarios":"Server returns 403/404/5xx for the resource URL; a 204 or 206 response; a redirect (301/302) that the constructed http.Request did not follow because the URL host/path changed or the client's redirect policy was hit.","commonSituations":"Geo resource moved or removed upstream (404); CDN rate-limiting or geo-blocking (403); authenticated endpoints returning 401; mirrors returning redirects to signed URLs.","solutions":["curl -I the URL to see the actual status and Location header","Update the URL to a current, direct (non-redirecting) source","For 403: add a User-Agent or use a different mirror if the server filters clients","Host the file locally to remove the dependency"],"exampleFix":"# before: 404\n\"downloadUrl\": \"https://old-mirror/geoip.dat\"\n# after (verified with curl -I → 200)\n\"downloadUrl\": \"https://new-mirror/geoip.dat\"","handlingStrategy":"fallback","validationCode":"// pre-flight: expect exactly 200\nresp, err := http.Head(url)\nif err == nil && resp.StatusCode != 200 {\n    return fmt.Errorf(\"source returned %d — pick another mirror\", resp.StatusCode)\n}","typeGuard":null,"tryCatchPattern":"body, err := fetchHTTPContent(target)\nif err != nil && strings.Contains(err.Error(), \"unexpected HTTP status code\") {\n    for _, mirror := range mirrors { // fallback list\n        if body, err = fetchHTTPContent(mirror); err == nil { break }\n    }\n}","preventionTips":["Only 200 counts as success — even 204/206 fail","Prefer stable direct-download URLs over redirecting mirrors","Verify links with curl -I during config authoring"],"tags":["http","status-code","network","cli"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}