{"record":{"id":"4ce7b8e9359a3cfe","repo":"valyala/fasthttp","slug":"cannot-find-whitespace-in-the-first-line-of-respon","errorCode":null,"errorMessage":"cannot find whitespace in the first line of response %q","messagePattern":"cannot find whitespace in the first line of response %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"header.go","lineNumber":2844,"sourceCode":"}\n\nfunc (h *ResponseHeader) parseFirstLine(buf []byte) (int, error) {\n\tbNext := buf\n\tvar b []byte\n\tvar err error\n\tfor len(b) == 0 {\n\t\tif b, bNext, err = nextLine(bNext); err != nil {\n\t\t\treturn 0, err\n\t\t}\n\t}\n\n\t// parse protocol\n\tn := bytes.IndexByte(b, ' ')\n\tif n < 0 {\n\t\tif h.secureErrorLogMessage {\n\t\t\treturn 0, ErrResponseFirstLineMissingSpace\n\t\t}\n\t\treturn 0, fmt.Errorf(\"cannot find whitespace in the first line of response %q\", buf)\n\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}","sourceCodeStart":2826,"sourceCodeEnd":2862,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/header.go#L2826-L2862","documentation":"The response status line must contain a space separating the protocol (e.g. HTTP/1.1) from the status code. fasthttp throws this when the first line of a response has no whitespace at all, meaning the bytes are not a valid HTTP status line.","triggerScenarios":"ResponseHeader.Parse (parseFirstLine) reads a first line with no ' ' byte — e.g. the server sent an error page, TLS handshake data, or empty/garbage response.","commonSituations":"Pointing a fasthttp client at an HTTPS endpoint without TLS (getting plaintext TLS alerts or HTML); hitting a non-HTTP service on the port; captive portals or proxies returning HTML error pages; receiving an HTTP/0.9-style bare response.","solutions":["Verify the target URL scheme — use https:// (and TLS client) if the server requires TLS","Confirm the remote port actually speaks HTTP (nmap/curl to check)","Inspect the raw response in the error (%q of buf) to see what was actually returned","If a proxy is in the path, check it isn't returning a non-HTTP error page"],"exampleFix":"// before\nc := &fasthttp.Client{} // used against https://host\n// after\nc := &fasthttp.Client{TLSConfig: &tls.Config{ServerName: \"host\"}} // with https URL","handlingStrategy":"validation","validationCode":"u, _ := url.Parse(target)\nif u.Scheme == \"https\" {\n    client.TLSConfig = &tls.Config{ServerName: u.Hostname()}\n}","typeGuard":"func isMalformedFirstLine(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"cannot find whitespace in the first line\")\n}","tryCatchPattern":"err := client.Do(req, resp)\nif err != nil && strings.Contains(err.Error(), \"cannot find whitespace in the first line\") {\n    return fmt.Errorf(\"peer did not return HTTP: %w\", err)\n}","preventionTips":["Match URL scheme to transport (https URL ⇒ TLS-enabled client)","Confirm the target port speaks HTTP before integrating","Prefer explicit fasthttp.Client with HostClient per scheme","Validate upstream endpoints in smoke tests"],"tags":["http","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"}