Skip to content

Commit a170ed8

Browse files
committed
Change error text for connection closed by server between sending response
1 parent fe61070 commit a170ed8

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

aiohttp/protocol.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ class HttpResponseParser(HttpParser):
204204
Returns RawResponseMessage"""
205205

206206
def __call__(self, out, buf):
207+
try:
208+
yield from buf.wait(1)
209+
except aiohttp.EofStream:
210+
raise errors.ClientConnectionError(
211+
'Connection closed by server') from None
207212
try:
208213
# read http message (response line + headers)
209214
try:

tests/test_client_functional.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,12 +1095,21 @@ def go():
10951095
connector = aiohttp.TCPConnector(loop=self.loop)
10961096

10971097
url = 'http://{}:{}/'.format(*addr)
1098-
for i in range(2):
1099-
r = yield from client.request('GET', url,
1100-
connector=connector,
1101-
loop=self.loop)
1102-
yield from r.read()
1103-
self.assertEqual(1, len(connector._conns))
1098+
1099+
r = yield from client.request('GET', url,
1100+
connector=connector,
1101+
loop=self.loop)
1102+
yield from r.read()
1103+
self.assertEqual(1, len(connector._conns))
1104+
1105+
with self.assertRaisesRegex(
1106+
aiohttp.ClientConnectionError,
1107+
'Connection closed by server'):
1108+
yield from client.request('GET', url,
1109+
connector=connector,
1110+
loop=self.loop)
1111+
self.assertEqual(0, len(connector._conns))
1112+
11041113
connector.close()
11051114
server.close()
11061115
yield from server.wait_closed()

0 commit comments

Comments
 (0)