Read()-ing a response raises ValueError

Bug #1616690 reported by Jamie Lennox
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
requests-mock
Fix Released
Medium
Jamie Lennox

Bug Description

When you read() from a closed HTTPResponse object it returns a b'' [1]. When you read from a closed BytesIO object you get a ValueError. This is very rarely a problem unless you have something like swiftclient that is reading directly from the urllib3 response and expecting this behaviour.

We should be as compatible as possible and fix it to return a b''.

[1] https://hg.python.org/cpython/file/3.4/Lib/http/client.py#l527

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to requests-mock (master)

Fix proposed to branch: master
Review: https://review.openstack.org/360137

Changed in requests-mock:
assignee: nobody → Jamie Lennox (jamielennox)
status: New → In Progress
Changed in requests-mock:
importance: Undecided → Medium
Changed in requests-mock:
milestone: none → 1.1
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to requests-mock (master)

Reviewed: https://review.openstack.org/360137
Committed: https://git.openstack.org/cgit/openstack/requests-mock/commit/?id=fe147914a644cabe11648fb313b990730ae25744
Submitter: Jenkins
Branch: master

commit fe147914a644cabe11648fb313b990730ae25744
Author: Jamie Lennox <email address hidden>
Date: Thu Aug 25 10:34:49 2016 +1000

    Return b'' when reading closed response.

    A HTTPResponse returns a b'' when you read from a closed socket. BytesIO
    raises a ValueError. This only comes to light when you are specifically
    reading past the end of the stream in a chunking scenario like
    swiftclient does.

    Change-Id: I67ed45252deac9472cfb011a5eb89130a3791d6b
    Closes-Bug: #1616690

Changed in requests-mock:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.