|
17 | 17 | # - or, for body readers, a dict of per-framing reader factories
|
18 | 18 |
|
19 | 19 | import re
|
20 |
| -from ._util import LocalProtocolError, validate |
| 20 | +from ._util import LocalProtocolError, RemoteProtocolError, validate |
21 | 21 | from ._state import *
|
22 | 22 | from ._events import *
|
23 | 23 |
|
@@ -177,16 +177,22 @@ def maybe_read_from_SEND_RESPONSE_server(buf):
|
177 | 177 | class ContentLengthReader:
|
178 | 178 | def __init__(self, length):
|
179 | 179 | self._length = length
|
| 180 | + self._remaining = length |
180 | 181 |
|
181 | 182 | def __call__(self, buf):
|
182 |
| - if self._length == 0: |
| 183 | + if self._remaining == 0: |
183 | 184 | return EndOfMessage()
|
184 |
| - data = buf.maybe_extract_at_most(self._length) |
| 185 | + data = buf.maybe_extract_at_most(self._remaining) |
185 | 186 | if data is None:
|
186 | 187 | return None
|
187 |
| - self._length -= len(data) |
| 188 | + self._remaining -= len(data) |
188 | 189 | return Data(data=data)
|
189 | 190 |
|
| 191 | + def read_eof(self): |
| 192 | + raise RemoteProtocolError( |
| 193 | + "peer closed connection without sending complete message body " |
| 194 | + "(received {} bytes, expected {})" |
| 195 | + .format(self._length - self._remaining, self._length)) |
190 | 196 |
|
191 | 197 | HEXDIG = r"[0-9A-Fa-f]"
|
192 | 198 | # Actually
|
@@ -260,6 +266,11 @@ def __call__(self, buf):
|
260 | 266 | chunk_end = False
|
261 | 267 | return Data(data=data, chunk_start=chunk_start, chunk_end=chunk_end)
|
262 | 268 |
|
| 269 | + def read_eof(self): |
| 270 | + raise RemoteProtocolError( |
| 271 | + "peer closed connection without sending complete message body " |
| 272 | + "(incomplete chunked read)") |
| 273 | + |
263 | 274 |
|
264 | 275 | class Http10Reader(object):
|
265 | 276 | def __call__(self, buf):
|
|
0 commit comments