From b6fac245b5aaaf0b465c2f7f346c7f0ad82143f2 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Sat, 28 Dec 2013 17:36:18 -0800 Subject: Backporing the fix from Issue #12692 --- Lib/urllib/request.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Lib/urllib/request.py') diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index a7445d185d..ef62acc710 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1251,6 +1251,12 @@ class AbstractHTTPHandler(BaseHandler): raise URLError(err) else: r = h.getresponse() + # If the server does not send us a 'Connection: close' header, + # HTTPConnection assumes the socket should be left open. Manually + # mark the socket to be closed when this response object goes away. + if h.sock: + h.sock.close() + h.sock = None r.url = req.get_full_url() # This line replaces the .msg attribute of the HTTPResponse -- cgit v1.2.1