Commit ca5300c9f4 for ffmpeg
commit ca5300c9f404d77a223ee26357ea55454a53e8f2
Author: Kacper Michajłow <kasper93@gmail.com>
Date: Fri Oct 2 03:46:08 2026 +0200
avformat/http: end or continue a reply at the end of its range
End a compressed reply with EOF where its range ends instead of passing
EAGAIN to the caller, as it is not continued with another request. A
chunked one is marked as ended, so that later reads return EOF too
instead of waiting for another chunk. Continue a chunked reply that ends
at the end of its range before the end of the data with the next
request, as a reply with a length already does.
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
diff --git a/libavformat/http.c b/libavformat/http.c
index 82bb9be7be..3245f47d01 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1869,15 +1869,18 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size)
"Chunked encoding data size: %"PRIu64"\n",
s->chunksize);
- if (!s->chunksize && s->multiple_requests) {
- http_get_line(s, line, sizeof(line)); // read empty chunk
- s->chunkend = 1;
- return 0;
- }
- else if (!s->chunksize) {
- av_log(h, AV_LOG_DEBUG, "Last chunk received, closing conn\n");
- ffurl_closep(&s->hd);
- return 0;
+ if (!s->chunksize) {
+ /* a partial reply that ends at its range end is continued */
+ int more = s->range_end && s->off == s->range_end &&
+ s->range_end < requested_end(s);
+ if (s->multiple_requests) {
+ http_get_line(s, line, sizeof(line)); // read empty chunk
+ s->chunkend = !more;
+ } else {
+ av_log(h, AV_LOG_DEBUG, "Last chunk received, closing conn\n");
+ ffurl_closep(&s->hd);
+ }
+ return more ? AVERROR(EAGAIN) : 0;
}
else if (s->chunksize == UINT64_MAX) {
av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n",
@@ -1937,6 +1940,10 @@ static int http_buf_read_compressed(URLContext *h, uint8_t *buf, int size)
if (s->inflate_stream.avail_in == 0) {
int read = http_buf_read(h, s->inflate_buffer, DECOMPRESS_BUF_SIZE);
+ if (read == AVERROR(EAGAIN)) {
+ s->chunkend = 1;
+ return AVERROR_EOF;
+ }
if (read <= 0)
return read;
s->inflate_stream.next_in = s->inflate_buffer;