{"record":{"id":"121f1817c24e5170","repo":"valyala/fasthttp","slug":"fasthttp-cannot-find-whitespace-in-the-first-line","errorCode":null,"errorMessage":"fasthttp: cannot find whitespace in the first line of response","messagePattern":"fasthttp: cannot find whitespace in the first line of response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"header.go","lineNumber":472,"sourceCode":"//\n// The following trailers are forbidden:\n// 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length),\n// 2. routing (e.g., Host),\n// 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]),\n// 4. authentication (e.g., see [RFC7235] and [RFC6265]),\n// 5. response control data (e.g., see Section 7.1 of [RFC7231]),\n// 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)\n//\n// Return ErrBadTrailer if contain any forbidden trailers.\nfunc (h *header) AddTrailer(trailer string) error {\n\treturn h.AddTrailerBytes(s2b(trailer))\n}\n\nvar (\n\tErrBadTrailer                    = errors.New(\"fasthttp: contain forbidden trailer\")\n\tErrReadingResponseHeaders        = errors.New(\"fasthttp: error when reading response headers\")\n\tErrReadingResponseTrailer        = errors.New(\"fasthttp: error when reading response trailer\")\n\tErrResponseFirstLineMissingSpace = errors.New(\"fasthttp: cannot find whitespace in the first line of response\")\n\tErrUnexpectedStatusCodeChar      = errors.New(\"fasthttp: unexpected char at the end of status code\")\n\tErrMissingRequestMethod          = errors.New(\"fasthttp: cannot find http request method\")\n\tErrUnsupportedRequestMethod      = errors.New(\"fasthttp: unsupported http request method\")\n\tErrExtraWhitespaceInRequestLine  = errors.New(\"fasthttp: extra whitespace in request line\")\n\tErrEmptyRequestURI               = errors.New(\"fasthttp: requesturi cannot be empty\")\n\tErrDuplicateContentLength        = errors.New(\"fasthttp: duplicate content-length header\")\n\tErrUnsupportedTransferEncoding   = errors.New(\"fasthttp: unsupported transfer-encoding\")\n\tErrNonNumericChars               = errors.New(\"fasthttp: non-numeric chars found\")\n\tErrNeedMore                      = errors.New(\"fasthttp: need more data: cannot find trailing lf\")\n\tErrSmallReadBuffer               = errors.New(\"fasthttp: small read buffer. increase readbuffersize\")\n)\n\n// AddTrailerBytes add Trailer header value for chunked response\n// to indicate which headers will be sent after the body.\n//\n// Use Set to set the trailer header later.\n//\n// Trailers are only supported with chunked transfer.","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/header.go#L454-L490","documentation":"fasthttp's response header parser scans the first line of an HTTP response for a space separating the protocol (e.g. 'HTTP/1.1') from the status code. When no whitespace is found in that line, the response is malformed and ErrResponseFirstLineMissingSpace is returned. This guards against non-HTTP garbage or truncated/corrupted responses from an upstream server.","triggerScenarios":"Calling Response.Read, HostClient/Client.Do, or DoTimeout against a peer whose first response line contains no space (e.g. 'HTTP/1.1' alone, or a plain-text/HTML error page from a proxy, or a binary greeting from a non-HTTP service) instead of the required 'HTTP/1.1 200 OK' format.","commonSituations":"Pointing the client at the wrong port (a TCP service that is not HTTP, an HTTPS port without TLS, a database or SMTP server), an intermediate proxy returning a bare status line, or a corrupted/truncated keep-alive connection reused from the pool.","solutions":["Verify you are dialing the correct host:port for an HTTP endpoint and that TLS settings (https:// scheme / TLSClientConfig) match the server.","Check what the peer actually sends on connect with curl -v or netcat; if it is not 'HTTP/1.x <code> ...', fix the target service or proxy.","If an upstream proxy emits nonstandard responses, either fix it or use a client that tolerates it (e.g. SetSkipResponseValidation via custom header handling is not available — switch to net/http or fix the upstream).","Discard pooled connections on error by not reusing the client after such errors; create a fresh HostClient or rely on fasthttp's automatic connection close on parse errors."],"exampleFix":"// before\nc := &fasthttp.Client{ Addr: \"db.example.com:5432\" }\n_, body, err := c.Get(nil, \"http://db.example.com:5432/\") // parse error on non-HTTP service\n// after\nc := &fasthttp.Client{ Addr: \"api.example.com:80\" }\n_, body, err := c.Get(nil, \"http://api.example.com:80/\") // real HTTP endpoint","handlingStrategy":"type-guard","validationCode":"// Before sending, verify the endpoint speaks HTTP:\n// curl -sv http://host:port/ | head -1  -> expect 'HTTP/1.x <code>'\n// Also ensure scheme matches TLS: https URL for TLS servers.","typeGuard":"func isResponseParseError(err error) bool {\n    return err == fasthttp.ErrResponseFirstLineMissingSpace ||\n        err == fasthttp.ErrUnexpectedStatusCodeChar\n}","tryCatchPattern":"_, body, err := client.Do(req, resp)\nif err == fasthttp.ErrResponseFirstLineMissingSpace {\n    // drop conn, mark endpoint unhealthy, alert on wrong-port/TLS misconfig\n    return fmt.Errorf(\"non-HTTP response from upstream: %w\", err)\n}","preventionTips":["Confirm target host:port speaks HTTP/1.x before wiring the client (curl -v probe).","Match scheme to transport: use https:// + TLSClientConfig for TLS endpoints.","Never point an HTTP client at database/SMTP/other protocol ports.","Monitor for this error in production — a sudden burst usually means a proxy or upstream broke."],"tags":["network","http","fasthttp","response-parsing"],"backgroundTag":"malformed-http-response","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}