From d9b0f2b638fa78cec95ab5f39e855ab65dc3e83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Fri, 3 May 2024 22:40:12 +0300 Subject: [PATCH] http: allow short response byte range RFC9110 specifies that a client must handle a shorter response range than requested in all circumstanges. Previously, RFC7233 only required that behaviour for multipart ranges, which VLC did not use. This matches the newer specification: VLC will try to resume from the last received offset not only on unexpected error, but also on short response. Fixes #28627. (cherry picked from commit 90dc0a023f6ceee591f6464367efae65f2ccf6e7) --- modules/access/http/file.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/access/http/file.c b/modules/access/http/file.c index ce101f60d6..5a5d4622a1 100644 --- a/modules/access/http/file.c +++ b/modules/access/http/file.c @@ -235,20 +235,21 @@ block_t *vlc_http_file_read(struct vlc_http_resource *res) block_t *block = vlc_http_res_read(res); if (block == vlc_http_error) - { /* Automatically reconnect on error if server supports seek */ - if (res->response != NULL - && vlc_http_msg_can_seek(res->response) - && file->offset < vlc_http_msg_get_file_size(res->response) - && vlc_http_file_seek(res, file->offset) == 0) - block = vlc_http_res_read(res); + block = NULL; + + /* Automatically resume on short response or error if possible */ + if (block == NULL && res->response != NULL + && vlc_http_msg_can_seek(res->response) + && file->offset < vlc_http_msg_get_file_size(res->response) + && vlc_http_file_seek(res, file->offset) == 0) + { + block = vlc_http_res_read(res); if (block == vlc_http_error) - return NULL; + block = NULL; /* Non-recovered error */ } - if (block == NULL) - return NULL; /* End of stream */ - - file->offset += block->i_buffer; + if (block != NULL) + file->offset += block->i_buffer; return block; }