Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #326 from obrown/development
Browse files Browse the repository at this point in the history
Check HTTP11 socket is initialized before closing
  • Loading branch information
Lukasa committed Jun 7, 2017
2 parents 496f3a0 + 87d10bb commit 88da7c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hyper/http11/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ def close(self):
.. warning:: This method should absolutely only be called when you are
certain the connection object is no longer needed.
"""
self._sock.close()
if self._sock is not None:
self._sock.close()
self._sock = None

# The following two methods are the implementation of the context manager
Expand Down
4 changes: 4 additions & 0 deletions test/test_http11.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ def read(self, size):
assert 'File-like bodies must return bytestrings. ' \
'Got: {}'.format(int) in str(exc_info)

def test_close_with_uninitialized_socket(self):
c = HTTP11Connection('httpbin.org')
c.close()


class TestHTTP11Response(object):
def test_short_circuit_read(self):
Expand Down

0 comments on commit 88da7c3

Please sign in to comment.