MCPcopy
hub / github.com/aio-libs/aiohttp / feed_data

Method feed_data

aiohttp/http_parser.py:340–577  ·  view source on GitHub ↗
(
        self,
        data: bytes,
        SEP: _SEP = b"\r\n",
        EMPTY: bytes = b"",
        CONTENT_LENGTH: istr = hdrs.CONTENT_LENGTH,
        METH_CONNECT: str = hdrs.METH_CONNECT,
        SEC_WEBSOCKET_KEY1: istr = hdrs.SEC_WEBSOCKET_KEY1,
    )

Source from the content-addressed store, hash-verified

338 return None
339
340 def feed_data(
341 self,
342 data: bytes,
343 SEP: _SEP = b"\r\n",
344 EMPTY: bytes = b"",
345 CONTENT_LENGTH: istr = hdrs.CONTENT_LENGTH,
346 METH_CONNECT: str = hdrs.METH_CONNECT,
347 SEC_WEBSOCKET_KEY1: istr = hdrs.SEC_WEBSOCKET_KEY1,
348 ) -> tuple[list[tuple[_MsgT, StreamReader]], bool, bytes]:
349
350 messages = []
351
352 if self._tail:
353 data, self._tail = self._tail + data, b""
354
355 data_len = len(data)
356 start_pos = 0
357 loop = self.loop
358 max_line_length = self.max_line_size
359
360 should_close = False
361 while start_pos < data_len or self._payload_has_more_data:
362 # read HTTP message (request/response line + headers), \r\n\r\n
363 # and split by lines
364 if self._payload_parser is None and not self._upgraded:
365 if (
366 self._max_msg_queue_size
367 and self._msg_in_flight >= self._max_msg_queue_size
368 ):
369 # Queue full: buffer the rest and stop. Safe pause point;
370 # any preceding body is consumed before the next request
371 # line. Resumes via feed_data(b"") when the queue drains.
372 self._tail = data[start_pos:]
373 break
374 pos = data.find(SEP, start_pos)
375 # consume \r\n
376 if pos == start_pos and not self._lines:
377 start_pos = pos + len(SEP)
378 continue
379
380 if pos >= start_pos:
381 if should_close:
382 raise BadHttpMessage("Data after `Connection: close`")
383
384 # line found
385 line = data[start_pos:pos]
386 if SEP == b"\n": # For lax response parsing
387 line = line.rstrip(b"\r")
388 if len(line) > max_line_length:
389 raise LineTooLong(line[:100] + b"...", max_line_length)
390
391 self._lines.append(line)
392 # After processing the status/request line, everything is a header.
393 max_line_length = self.max_field_size
394
395 if len(self._lines) > self.max_headers:
396 raise BadHttpMessage("Too many headers received")
397

Callers 4

feed_dataMethod · 0.45
feed_eofMethod · 0.45
feed_dataMethod · 0.45
feed_dataMethod · 0.45

Calls 10

parse_messageMethod · 0.95
BadHttpMessageClass · 0.85
LineTooLongClass · 0.85
InvalidHeaderClass · 0.85
_is_supported_upgradeFunction · 0.85
StreamReaderClass · 0.85
HttpPayloadParserClass · 0.85
set_exceptionFunction · 0.85
appendMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected