Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support streaming chunks in HTTP/1.0 read-until-close bodies #3370

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jadehh
Copy link

@jadehh jadehh commented Apr 11, 2024

No description provided.

@bdarnell
Copy link
Member

What exactly are you trying to do here? This looks the same as the chunking in _read_fixed_body. (and remember that all new functionality needs tests, and comments and commit messages should be in english)

@jadehh
Copy link
Author

jadehh commented Apr 18, 2024

_read_fixed_body function cannot parse like this headers

{
  "Access-Control-Allow-Credentials":true,
  "Access-Control-Allow-Headers": "Content-Type",
  "Access-Control-Allow-Origin": "*",
  "Cache-Control:": "no-cache",
  "Connection": "close",
  "Content-Type": "video/x-flv",
  "Expires": "-1",
  "Pragma": "no-cache"
}

this is a flv live url headers,this looks no Transfer-Encoding key

so,I created _read_chunked_body_byflv function and tested support flv live url

@jadehh jadehh changed the title * tornado支持解析video/x-flv格式 fix support flv live url Apr 18, 2024
@bdarnell
Copy link
Member

Without a Content-Length or Transfer-Encoding header, this is an HTTP/1.0-style read-until-close response, so it is handled by _read_body_until_close. This is discouraged in HTTP/1.1 but allowed for backwards compatibility.

Special-casing the video/x-flv content type is not appropriate, but it would be appropriate to modify _read_body_until_close to read the data in chunks and make multiple data_received calls (similar to _read_fixed_body).

@jadehh
Copy link
Author

jadehh commented Apr 19, 2024

thanks for reply, modify _read_body_until_close like this

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)
        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

like this I can use the streaming_callback get real-time chunk, if modify _read_body_until_close, will it have any other impact.

@bdarnell
Copy link
Member

bdarnell commented Jul 1, 2024

This change looks good, but it needs a test and should be rebased into a single commit with comments in english.

@bdarnell bdarnell changed the title fix support flv live url Support streaming chunks in HTTP/1.0 read-until-close bodies Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants