Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with httplib and Content-Length: -1 #45968

Closed
airadier mannequin opened this issue Dec 14, 2007 · 4 comments
Closed

Problem with httplib and Content-Length: -1 #45968

airadier mannequin opened this issue Dec 14, 2007 · 4 comments
Labels
easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@airadier
Copy link
Mannequin

airadier mannequin commented Dec 14, 2007

BPO 1627
Nosy @birkenfeld, @tiran, @sdownum
Files
  • 1626_patch.diff: Proposed patch.
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-02-24.00:15:51.729>
    created_at = <Date 2007-12-14.12:52:01.590>
    labels = ['easy', 'type-bug', 'library']
    title = 'Problem with httplib and Content-Length: -1'
    updated_at = <Date 2008-02-24.00:15:51.727>
    user = 'https://bugs.python.org/airadier'

    bugs.python.org fields:

    activity = <Date 2008-02-24.00:15:51.727>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-02-24.00:15:51.729>
    closer = 'georg.brandl'
    components = ['Library (Lib)']
    creation = <Date 2007-12-14.12:52:01.590>
    creator = 'airadier'
    dependencies = []
    files = ['9237']
    hgrepos = []
    issue_num = 1627
    keywords = ['easy']
    message_count = 4.0
    messages = ['58624', '58779', '60253', '62851']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'christian.heimes', 'airadier', 'sdownum']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1627'
    versions = ['Python 2.6']

    @airadier
    Copy link
    Mannequin Author

    airadier mannequin commented Dec 14, 2007

    When opening an IP Webcam URL with urllib2, the response is a continuous
    secuence of Jpeg files from the server, preceded by the following headers:

    Server: DM-Web
    Content-type:
    multipart/x-mixed-replace;boundary=0plm(Pico-Web:Server-Push:Boundary-String)1qaz
    Content-length: -1

    As you can see, the Content-Type is multipart/x-mixed-replace, and the
    Content-Length reported by the server is '-1', which is strange (I guess
    it would be better not to report Content-Length)

    The problem is trying to read anything from the file-like object
    returned by urlopen will block forever. Problem seems to be here, in
    httplib.py, class HTTPResponse, method 'begin':

    ...
    # will the connection close at the end of the response?
    self.will_close = self._check_close()

        \# do we have a Content-Length?
        \# NOTE: RFC 2616, S4.4, #3 says we ignore this if tr_enc is
    

    "chunked"
    length = self.msg.getheader('content-length')
    if length and not self.chunked:
    try:
    self.length = int(length)
    except ValueError:
    self.length = None
    else:
    self.length = None
    ...

    The length attribute is being set to '-1' which leads to blocking when
    reading from the endless stream of data. (See the read method in class
    _fileobject, socket.py).

    I don't know if this is the right fix, but I would suggest changing:

            length = self.msg.getheader('content-length')
            if length and not self.chunked:

    to:

            length = self.msg.getheader('content-length')
            if length >= 0 and not self.chunked:

    @airadier airadier mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 14, 2007
    @tiran
    Copy link
    Member

    tiran commented Dec 18, 2007

    Your proposed fixed is not correct:

            length = self.msg.getheader("content-length")
            if length and not self.chunked:
                try:
                    self.length = int(length)
                except ValueError:
                    pass
            # patch
            if self.length < 0:
                self.length = None

    @tiran tiran added the easy label Jan 12, 2008
    @sdownum
    Copy link
    Mannequin

    sdownum mannequin commented Jan 20, 2008

    I have made a patch of the proposed fixed and ran the httplib test
    afterwards, to make sure it passed.

    @birkenfeld
    Copy link
    Member

    Fixed in r61035.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants