{"id":"3b12e5745bb2978a","repo":"gofiber/fiber","slug":"failed-to-discard-interim-response-body-w","errorCode":null,"errorMessage":"failed to discard interim response body: %w","messagePattern":"failed to discard interim response body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app.go","lineNumber":1502,"sourceCode":"\tfor {\n\t\t// Convert raw http response to *http.Response\n\t\tres, err = httpReadResponse(buffer, req)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, io.ErrUnexpectedEOF) {\n\t\t\t\treturn nil, ErrTestGotEmptyResponse\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"failed to read response: %w\", err)\n\t\t}\n\n\t\t// Break if this response is non-1xx or there are no more responses\n\t\tif res.StatusCode >= http.StatusOK || buffer.Buffered() == 0 {\n\t\t\tbreak\n\t\t}\n\n\t\t// Discard interim response body before reading the next one\n\t\tif res.Body != nil {\n\t\t\tif _, errCopy := io.Copy(io.Discard, res.Body); errCopy != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to discard interim response body: %w\", errCopy)\n\t\t\t}\n\t\t\tif errClose := res.Body.Close(); errClose != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to close interim response body: %w\", errClose)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn res, nil\n}\n\ntype disableLogger struct{}\n\n// Printf implements the fasthttp Logger interface and discards log output.\nfunc (*disableLogger) Printf(string, ...any) {\n}\n\nfunc (app *App) init() *App {\n\tfunc() {","sourceCodeStart":1484,"sourceCodeEnd":1520,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/app.go#L1484-L1520","documentation":"Returned by App.Test (app.go:1502) when discarding the body of a 1xx interim response fails before reading the next response in the loop. Test loops over interim responses (100 Continue, 102 Processing, 103 Early Hints) and discards each body; if io.Copy(io.Discard, res.Body) errors, the interim body could not be drained.","triggerScenarios":"A handler under test emits 1xx interim responses with a body that errors on read (broken/short body), or the testConn is closed mid-interim-response. Occurs specifically when exercising interim-response code paths.","commonSituations":"Testing Early Hints (103) / 100-Continue flows; handlers that write interim status then reset the connection; compression/streaming edge cases on interim responses.","solutions":["Inspect the wrapped error (usually io.ErrUnexpectedEOF or a read on a closed conn).","Ensure interim responses in the handler carry no body (or a validly framed one) per RFC 2516.","Increase TestConfig.Timeout if the handler is slow to produce the final response after interim ones."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"resp, err := app.Test(req, fiber.TestConfig{Timeout: 5 * time.Second})\nif err != nil && strings.Contains(err.Error(), \"failed to discard interim response body\") {\n    // 1xx interim response body could not be drained — inspect handler's interim writes\n}","preventionTips":["Ensure interim (1xx) responses carry no body per RFC.","Increase TestConfig.Timeout if the handler is slow to produce the final response.","Inspect wrapped errors to distinguish read failures from connection resets."],"tags":["testing","http","interim-response","test-helper"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}