[Python-bugs-list] [ python-Bugs-579107 ] https broken by recent httplib changes

noreply@sourceforge.net noreply@sourceforge.net
Tue, 09 Jul 2002 14:28:44 -0700


Bugs item #579107, was opened at 2002-07-09 12:35
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=579107&group_id=5470

Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Kevin Jacobs (jacobs99)
Assigned to: Jeremy Hylton (jhylton)
Summary: https broken by recent httplib changes

Initial Comment:
Here is code that has worked previously, but does not in 
the current CVS:

  import urllib

  def get(url):
    return urllib.urlopen(url).read()

  u = get('http://dbserv2.theopalgroup.com/mediumfile')
  hlen = len(u)
  u = get('https://dbserv2.theopalgroup.com/mediumfile')
  slen = len(u)

  print "HTTP len = %d, HTTPS len = %d" % (hlen,slen)

Here are the results of running this code for various
python versions:

> python2.0 testhttps.py
HTTP len = 37140, HTTPS len = 37140

> python2.1 testhttps.py
HTTP len = 37140, HTTPS len = 37140

> python2.2 testhttps.py
HTTP len = 37140, HTTPS len = 37140

> python2.3 testhttps.py
HTTP len = 37140, HTTPS len = 0

Clearly, there is something wrong with rhe HTTPS
connection in Python 2.3.

With my proposed patch, the output is now as expected:

> python2.3+patch testhttps.py
HTTP len = 37140, HTTPS len = 37140

However, there are some unresolved issues with
the patch, so I hope that someone more familiar
with httplib will help out.  Basically, the problem
stems from non-obvious semantics of 
HTTPResponse and HTTPConnection with regard to 
closing the active connection.

I've marked several locations in the diff where these
classes close connections and I am not convinced
that it is proper to do so.  One of these locations
fixes the problem I demonstrate above.  i.e., the
SSL read fails because the socket has already
been closed, and no data is returned.

The exception caused by trying to read from a closed
connection is trapped, so the caller sees no error, and
recieves no bytes (i.e., EOF).


----------------------------------------------------------------------

>Comment By: Jeremy Hylton (jhylton)
Date: 2002-07-09 21:28

Message:
Logged In: YES 
user_id=31392

revision 1.58
date: 2002/07/09 21:22:36;  author: jhylton;  state: Exp; 
lines: +87 -35
Fix for SF bug 579107.

The recent SSL changes resulted in important, but subtle
changes to
close() semantics.  Since builtin socket makefile() is not
called for
SSL connections, we don't get separately closeable fds for
connection
and response.  Comments in the code explain how to restore
makefile
semantics.

Bug fix candidate.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=579107&group_id=5470