Skip to content

http.client.HTTPResponse.read1 does not close response after reading all data #113199

Description

@illia-v

Bug report

Bug description:

While trying to use read1 in urllib3, we discovered that read1 unlike read never closes the response after reading all data when the content length is known (urllib3/urllib3#3235).


import http.client

conn = http.client.HTTPSConnection("www.python.org")
conn.request("GET", "/")
response = conn.getresponse()

This runs successfully:

response.read()
assert response.isclosed()

This fails:

while response.read1():
    pass
assert response.isclosed()

CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12, 3.13, CPython main branch

Operating systems tested on:

Linux, macOS, Windows

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions