summaryrefslogtreecommitdiff
path: root/libavformat/http.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2022-02-02 10:39:07 -0500
committerVittorio Giovara <vittorio.giovara@gmail.com>2022-02-11 11:31:38 +0100
commitc1228315c97acbe7a6220b4a5f282bd93edbeb42 (patch)
tree60db991806cce0cf3472c9937c2325f620acfa4b /libavformat/http.c
parent402784ba9f1730d6438082a030deef9c9f41a25d (diff)
downloadffmpeg-c1228315c97acbe7a6220b4a5f282bd93edbeb42.tar.gz
http: Improve handling of Content-Range with Transfer-Encoding:chunked
When Transfer-Encoding:chunked is used, the client must ignore a Content-Length header, if present. However, it should not ignore a Content-Range header, which also includes the full size of the entity.
Diffstat (limited to 'libavformat/http.c')
-rw-r--r--libavformat/http.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/libavformat/http.c b/libavformat/http.c
index 8f39d11a88..c89f8a5517 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -132,6 +132,7 @@ typedef struct HTTPContext {
int64_t expires;
char *new_location;
AVDictionary *redirect_cache;
+ uint64_t filesize_from_content_range;
} HTTPContext;
#define OFFSET(x) offsetof(HTTPContext, x)
@@ -839,7 +840,7 @@ static void parse_content_range(URLContext *h, const char *p)
p += 6;
s->off = strtoull(p, NULL, 10);
if ((slash = strchr(p, '/')) && strlen(slash) > 0)
- s->filesize = strtoull(slash + 1, NULL, 10);
+ s->filesize_from_content_range = strtoull(slash + 1, NULL, 10);
}
if (s->seekable == -1 && (!s->is_akamai || s->filesize != 2147483647))
h->is_streamed = 0; /* we _can_ in fact seek */
@@ -1341,6 +1342,7 @@ static int http_read_header(URLContext *h)
av_freep(&s->new_location);
s->expires = 0;
s->chunksize = UINT64_MAX;
+ s->filesize_from_content_range = UINT64_MAX;
for (;;) {
if ((err = http_get_line(s, line, sizeof(line))) < 0)
@@ -1356,6 +1358,10 @@ static int http_read_header(URLContext *h)
s->line_count++;
}
+ // filesize from Content-Range can always be used, even if using chunked Transfer-Encoding
+ if (s->filesize_from_content_range != UINT64_MAX)
+ s->filesize = s->filesize_from_content_range;
+
if (s->seekable == -1 && s->is_mediagateway && s->filesize == 2000000000)
h->is_streamed = 1; /* we can in fact _not_ seek */