Skip to content

improvement: net/http: reuse connection if entire unread body is in buffer #75308

@canoriz

Description

@canoriz

Currently, if an HTTP response body is closed before fully read (fully means till EOF),
the underlying HTTP connection won't be reused. But in the current implementation,
body is first read into bufio buffer by bufio reader, then from buffer by body Reader.
So even if the body is closed before fully read, as long as the entire body has been
read into buffer, after discard buffer, the connection can be reused.

This will be useful when go client only read body if status is 200 while server sends
HTTP body in a non 200 status response.

I filed a PR #75303, reviewer suggests opening an issue and discuss it first, so here it is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions