Skip to content

Message body length not matching Content-Length should raise httplib.IncompleteRead even when using stream() #311

@patricklaw

Description

@patricklaw

More details in the issue I originally filed with requests (https://github.com/kennethreitz/requests/issues/1855). Here is a repro, slightly modified from the repro in that issue:

import SocketServer as socketserver
import threading
import urllib3
import time


class MyTCPHandler(socketserver.BaseRequestHandler):
    def handle(self):
        self.data = self.request.recv(1024)
        self.request.sendall('HTTP/1.1 200 OK\r\n'
                             'Server: truncator/0.0\r\n'
                             'Content-Length: 20\r\n'
                             'Connection: close\r\n\r\n'
                             '12345')

server = None
def background_server():
    global server
    HOST, PORT = "localhost", 9999
    server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)
    server.serve_forever()


if __name__ == "__main__":
    t = threading.Thread(target=background_server)
    t.daemon = True
    t.start()
    time.sleep(1)
    http = urllib3.PoolManager()
    try:
        g = http.request('GET', 'http://localhost:9999', preload_content=False).stream()
        data = list(g) # This should raise httplib.IncompleteRead
        print(data)
    finally:
        server.shutdown()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions