{"record":{"id":"05b6a8e217cd64ca","repo":"valyala/fasthttp","slug":"invalid-response-status-code-q-response-q","errorCode":null,"errorMessage":"invalid response status code %q: response %q","messagePattern":"invalid response status code %q: response %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"header.go","lineNumber":2863,"sourceCode":"\t}\n\tprotoStr := b[:n]\n\tb = b[n+1:]\n\tfor len(b) > 0 && b[0] == ' ' {\n\t\tb = b[1:]\n\t}\n\n\t// parse status code\n\tstatusCode := b\n\tstatusMessage := []byte(nil)\n\tif n = bytes.IndexByte(b, ' '); n >= 0 {\n\t\tstatusCode = b[:n]\n\t\tstatusMessage = b[n+1:]\n\t}\n\tif len(statusCode) != 3 {\n\t\tif h.secureErrorLogMessage {\n\t\t\treturn 0, ErrUnexpectedStatusCodeChar\n\t\t}\n\t\treturn 0, fmt.Errorf(\"invalid response status code %q: response %q\", statusCode, buf)\n\t}\n\th.statusCode, n, err = parseUintBuf(statusCode)\n\tif err != nil || n != 3 {\n\t\tif h.secureErrorLogMessage {\n\t\t\treturn 0, ErrUnexpectedStatusCodeChar\n\t\t}\n\t\treturn 0, fmt.Errorf(\"invalid response status code %q: response %q\", statusCode, buf)\n\t}\n\tif !isHTTPVersion(protoStr) {\n\t\tif h.secureErrorLogMessage {\n\t\t\treturn 0, fmt.Errorf(\"unsupported http version %q\", protoStr)\n\t\t}\n\t\treturn 0, fmt.Errorf(\"unsupported http version %q in %q\", protoStr, buf)\n\t}\n\th.noHTTP11 = !bytes.Equal(protoStr, strHTTP11)\n\th.protocol = append(h.protocol[:0], protoStr...)\n\tif len(statusMessage) > 0 {\n\t\th.SetStatusMessage(statusMessage)","sourceCodeStart":2845,"sourceCodeEnd":2881,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/header.go#L2845-L2881","documentation":"The status code in the response's first line must be exactly 3 digits. fasthttp throws this when the extracted status-code token has a length other than 3, indicating a malformed or non-HTTP response line.","triggerScenarios":"parseFirstLine splits the status line and the token between the first and second spaces is not 3 characters long — e.g. 'HTTP/1.1 200' with no message, or garbage tokens.","commonSituations":"Non-HTTP servers replying on the port; HTTP/0.9-style responses; proxies returning custom error strings; truncated responses from broken intermediaries.","solutions":["Check what the endpoint actually returns (curl -v) — the peer is not sending valid HTTP","Fix the URL/scheme/port if you're hitting the wrong service","If a proxy rewrites status lines, bypass or fix the proxy","Note: with SecureErrorLogMessage set, this surfaces as ErrUnexpectedStatusCodeChar without echoing the response"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":"func isBadStatusCodeToken(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"invalid response status code\")\n}","tryCatchPattern":"err := client.Do(req, resp)\nif err != nil && strings.Contains(err.Error(), \"invalid response status code\") {\n    log.Debug(\"non-HTTP peer response\", \"err\", err)\n    return errUpstreamNotHTTP\n}","preventionTips":["curl -v the endpoint to confirm it returns real HTTP status lines","Bypass or fix proxies that rewrite status lines","Pin health-checked, known-good upstreams","Keep clients away from HTTP/0.9 endpoints"],"tags":["http","status-code","response-parsing","fasthttp"],"backgroundTag":"invalid-http-response-first-line","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}