This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit ee2bc310326374fafc9e2809ec2ab5a88925f792 Author: Niklas Haas <[email protected]> AuthorDate: Sun Jun 28 12:47:40 2026 +0200 Commit: Niklas Haas <[email protected]> CommitDate: Sun Jun 28 12:47:40 2026 +0200 avformat/http: imply keep-alive by default when beneficial By turning it into a tristate that defaults to -1 (auto). Users can still force a particular value for debugging. Sponsored-by: nxtedition AB Signed-off-by: Niklas Haas <[email protected]> --- doc/protocols.texi | 7 ++++--- libavformat/http.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index 368ae005f8..5f8cc8094d 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -453,15 +453,16 @@ string describing the libavformat build. ("Lavf/<version>") Set the Referer header. Include 'Referer: URL' header in HTTP request. @item multiple_requests -Use persistent connections if set to 1, default is 0. +Force persistent connections if set to 1, or disable if 0. Default is -1, +which means auto (implies keep-alive when using -request_size or +-initial_request_size). @item request_size Limit the size of requests made. This is useful for some pathological servers that throttle unbounded range requests, as well as when expecting to seek frequently. Disabled (set to 0) by default. -Note that if enabling this option, it's strongly recommended to also enable -the @option{multiple_requests} option, as well as setting +Note that if enabling this option, it's strongly recommended to also set @option{short_seek_size} to the same value or higher. Doing so allows FFmpeg to reuse a single HTTP connection wherever possible. diff --git a/libavformat/http.c b/libavformat/http.c index e5e102923d..d5e3c2e181 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -194,7 +194,7 @@ static const AVOption http_options[] = { { "content_type", "set a specific content type for the POST messages", OFFSET(content_type), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D | E }, { "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT }, 0, 0, D }, { "referer", "override referer header", OFFSET(referer), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D }, - { "multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D | E }, + { "multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, D | E }, { "request_size", "size (in bytes) of requests to make", OFFSET(request_size), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, D }, { "initial_request_size", "size (in bytes) of initial requests made during probing / header parsing", OFFSET(initial_request_size), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, D }, { "post_data", "set custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D | E }, @@ -1625,6 +1625,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, // Note: we send the Range header on purpose, even when we're probing, // since it allows us to detect more reliably if a (non-conforming) // server supports seeking by analysing the reply headers. + int is_partial_request = 0; if (!has_header(s->headers, "\r\nRange: ") && !post && (s->off > 0 || s->end_off || s->seekable != 0)) { av_bprintf(&request, "Range: bytes=%"PRIu64"-", s->off); uint64_t req_size = request_size(h); @@ -1634,8 +1635,10 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, target_off = UINT64_MAX; if (s->end_off) target_off = FFMIN(target_off, s->end_off); - if (target_off != UINT64_MAX) + if (target_off != UINT64_MAX) { av_bprintf(&request, "%"PRId64, target_off - 1); + is_partial_request = 1; + } } else if (s->end_off) av_bprintf(&request, "%"PRId64, s->end_off - 1); av_bprintf(&request, "\r\n"); @@ -1644,7 +1647,9 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, av_bprintf(&request, "Expect: 100-continue\r\n"); if (!has_header(s->headers, "\r\nConnection: ")) { - keep_alive = s->multiple_requests; + keep_alive = s->multiple_requests > 0; + if (s->multiple_requests < 0 /* auto */ && is_partial_request) + keep_alive = 1; av_bprintf(&request, "Connection: %s\r\n", keep_alive ? "keep-alive" : "close"); } _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
