From 9743304d8a2ff6a850cb2b07fdeb1278228227af Mon Sep 17 00:00:00 2001 From: jade <jadehh@live.com> Date: Thu, 11 Apr 2024 18:29:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?*=20tornado=E6=94=AF=E6=8C=81=E8=A7=A3?= =?UTF-8?q?=E6=9E=90video/x-flv=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tornado/http1connection.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tornado/http1connection.py b/tornado/http1connection.py index ca50e8ff5..4e3423ab7 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -645,6 +645,8 @@ def _read_body( return self._read_fixed_body(content_length, delegate) if headers.get("Transfer-Encoding", "").lower() == "chunked": return self._read_chunked_body(delegate) + if headers.get("Content-Type","").lower() == 'video/x-flv': + return self._read_chunked_body_byflv(delegate) if self.is_client: return self._read_body_until_close(delegate) return None @@ -697,6 +699,17 @@ async def _read_chunked_body(self, delegate: httputil.HTTPMessageDelegate) -> No crlf = await self.stream.read_bytes(2) assert crlf == b"\r\n" + async def _read_chunked_body_byflv(self, delegate: httputil.HTTPMessageDelegate) -> None: + # TODO: "chunk extensions" http://tools.ietf.org/html/rfc2616#section-3.6.1 + while True: + chunk = await self.stream.read_bytes(1024,partial=True) + if not self._write_finished or self.is_client: + with _ExceptionLoggingContext(app_log): + ret = delegate.data_received(chunk) + if ret is not None: + await ret + + async def _read_body_until_close( self, delegate: httputil.HTTPMessageDelegate ) -> None: From f36472c78ec7df49cc13846f849b4dc2b2fc381c Mon Sep 17 00:00:00 2001 From: jade <jadehh@live.com> Date: Fri, 12 Apr 2024 09:13:25 +0800 Subject: [PATCH 2/3] =?UTF-8?q?*=20=E4=BF=AE=E6=94=B9=E6=B5=81=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E6=80=A7=E8=AF=BB=E5=8F=96=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tornado/http1connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tornado/http1connection.py b/tornado/http1connection.py index 4e3423ab7..1393c220c 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -702,7 +702,7 @@ async def _read_chunked_body(self, delegate: httputil.HTTPMessageDelegate) -> No async def _read_chunked_body_byflv(self, delegate: httputil.HTTPMessageDelegate) -> None: # TODO: "chunk extensions" http://tools.ietf.org/html/rfc2616#section-3.6.1 while True: - chunk = await self.stream.read_bytes(1024,partial=True) + chunk = await self.stream.read_bytes(self.params.chunk_size,partial=True) if not self._write_finished or self.is_client: with _ExceptionLoggingContext(app_log): ret = delegate.data_received(chunk) From d25f66ed3c1c09d364fdcfe1da35f00b8ff195ce Mon Sep 17 00:00:00 2001 From: jade <jadehh@live.com> Date: Mon, 22 Apr 2024 16:02:19 +0800 Subject: [PATCH 3/3] modify _read_body_until_close to support flv live url --- tornado/http1connection.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/tornado/http1connection.py b/tornado/http1connection.py index 1393c220c..86d73b88f 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -645,8 +645,6 @@ def _read_body( return self._read_fixed_body(content_length, delegate) if headers.get("Transfer-Encoding", "").lower() == "chunked": return self._read_chunked_body(delegate) - if headers.get("Content-Type","").lower() == 'video/x-flv': - return self._read_chunked_body_byflv(delegate) if self.is_client: return self._read_body_until_close(delegate) return None @@ -699,28 +697,17 @@ async def _read_chunked_body(self, delegate: httputil.HTTPMessageDelegate) -> No crlf = await self.stream.read_bytes(2) assert crlf == b"\r\n" - async def _read_chunked_body_byflv(self, delegate: httputil.HTTPMessageDelegate) -> None: - # TODO: "chunk extensions" http://tools.ietf.org/html/rfc2616#section-3.6.1 + async def _read_body_until_close( + self, delegate: httputil.HTTPMessageDelegate + ) -> None: while True: - chunk = await self.stream.read_bytes(self.params.chunk_size,partial=True) + chunk = await self.stream.read_bytes(self.params.chunk_size, partial=True) if not self._write_finished or self.is_client: with _ExceptionLoggingContext(app_log): ret = delegate.data_received(chunk) if ret is not None: await ret - - async def _read_body_until_close( - self, delegate: httputil.HTTPMessageDelegate - ) -> None: - body = await self.stream.read_until_close() - if not self._write_finished or self.is_client: - with _ExceptionLoggingContext(app_log): - ret = delegate.data_received(body) - if ret is not None: - await ret - - class _GzipMessageDelegate(httputil.HTTPMessageDelegate): """Wraps an `HTTPMessageDelegate` to decode ``Content-Encoding: gzip``."""