From patchwork Mon Apr 15 16:27:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 48073 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp1953431pzb; Mon, 15 Apr 2024 09:28:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVIxLkwHQaofRrtzvWNKTkaW510HynFdVlMwkqoZaIApo4Zu9mgqBMu9mbf3+dlggabo5ONCe9HRp7TUShTmANnjPml6uFjTroQEg== X-Google-Smtp-Source: AGHT+IGwprJoTekzBQXBmYSzeptHgQQMWfqRTTle1EuifUuoTYu69dRQ3ab6gV1g9MhtrcKNPKp7 X-Received: by 2002:a50:d486:0:b0:56b:d158:c5de with SMTP id s6-20020a50d486000000b0056bd158c5demr6816815edi.16.1713198529197; Mon, 15 Apr 2024 09:28:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713198529; cv=none; d=google.com; s=arc-20160816; b=e1s3nO5E6ZnlIwWD52NhKrbj/G5AUAeMsKPd0dKnb7PBk0Tji8Wcz0xOjNXM49Qkrw +1QYyTJ8hHPGEfPIUv5y84uEH+Ug4pmQw7SPQ0DfZwmgXdRU2Ze/oLjlBG2UEuFPeHr3 dyBgYCl3wcSQjvMvH/X6FDPN8jOw39fiIBrfPLl8m7LZlVCSDItkEV6l4Zzj2s8thelO JGs0eWx8XOchRcSS16asICV8NQVG7fMPgK3hFK7zMh0pwXJzpWtT0FMIOHFm6ZzeSDMp oBxvgnl/xTzf9ADoE9hCZOkkUVB1c0Ub6q335hNwG7Mwv+ehV39SLUupbtBct4n1T9Je J+Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=tEmj8i/CUQUAEjbRscKcu4lgM7N6uQkynZzxFXPyoWs=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=grTPOrq/OJ3yZ7iIld34xUvBeokBRa0frk9Ut3PAYjvLRrxafuWsaDiJ7osX1X/UQ0 rhTKL02Uu5AjHw++WFy8hcr1EG+LmlXMG8yvDdSyykA+rFSEIKAvMJgni+rXI7LBeWFg YGEcsjsFQNwveLLCtSSj7g3LPmXi7jPNkPS0WxNifUp7abiWIyKnYy/z5bMbpyn32Zfu +wa2MpSz9rl4y9TqCXEEtd/1LYeDnNnvAGwEhiLML2Mzfu3iP858gacPt/YW5yBSL0LF TM6VRGSzzTvnicahj3bXFQ8P3mGEohzo5UZdvQTT1kgHe1ycUE4htvhu8QBRg2tmB07k Tjtg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=cXWQ5R0D; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z22-20020a05640235d600b0057022d5f466si1525474edc.498.2024.04.15.09.28.48; Mon, 15 Apr 2024 09:28:49 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=cXWQ5R0D; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A0C768CE03; Mon, 15 Apr 2024 19:28:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 174EC68CCBC for ; Mon, 15 Apr 2024 19:28:04 +0300 (EEST) Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-343c2f5b50fso2574556f8f.2 for ; Mon, 15 Apr 2024 09:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713198482; x=1713803282; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=EXJsIPBlk9FSxjEka/F0Of9+8Jtj4GrRpSmFn8sVkig=; b=cXWQ5R0Dx/y0K/jvY5KV83dQrvZjE3yWI6iOt+Bi4jbsV8sN0VDkIqH0qhYoKAitjz MYFg7HEjaL6e3XFNO716P9oajJU3pDKXPNpx2pyroAnBkUljTU890lrWKTCkbri7FRPy wbgz0XzG8XL7kBYk5GPUkIE1Yjmg0ix2J9a97fybklulfVMxp2TM7aWSqFayw8GVrngQ 7Eyd/2Du6KsE9QxT30MFOh7hKKDlV0lTAL1JWQt93xN2sNbiIeZL8D0soNYcXaWymE2L RrxVVRyEBZrVnZptBq2zJIuapGa/oYDyxvZxMSR/Jrn8NwMlyNiGJ1wZkJXTC54ljFSx d8aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713198482; x=1713803282; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EXJsIPBlk9FSxjEka/F0Of9+8Jtj4GrRpSmFn8sVkig=; b=DepxZDtNYx0TfyyruPtNerhlv3qd9TEqjApfzOOollLcW0k+TtXf55AxrsOce14RyH mdb9Pl2+aTnC5dKzBy7CeyeYxAQ2UpPy2hIh2G0CHpeVT/HqrtIKzTDgHlEC1s+vPfm2 5Qo2m+s6uj+nlmYj7HTGP+URkRqP8ZMzuxMUpEGMe/oUNTzQnRNJvZGalC9Kjiw5mMBQ 8CwMZffPbksXhUOaOHz6AVSJsZV363wgxJFHZ+wI5P4CKDVzsBCdoB0mhz/DYgd3MIJV LlIoT3o+VYOoE8D0LKkmJYkWPRC2FlfW231v+n3kYoE3k1bnMS2kdGWiP7+uH4GPF64o 7HPA== X-Gm-Message-State: AOJu0YzpZ3tRd1LT0+31xrk2+5ymIoGJFdIUo/o43TuL4KpDTLgJszfk h2+0dtwVHAa6o26EzGelogbZ7TOISpkrNajYk+yheLG1/c8i+3ZmfWD9eQ== X-Received: by 2002:a05:6000:1849:b0:346:ba70:7d8f with SMTP id c9-20020a056000184900b00346ba707d8fmr8770086wri.45.1713198482345; Mon, 15 Apr 2024 09:28:02 -0700 (PDT) Received: from localhost.localdomain (33bf3d9d.skybroadband.com. [51.191.61.157]) by smtp.gmail.com with ESMTPSA id u8-20020a5d4348000000b00347c187a3a0sm3899969wrr.24.2024.04.15.09.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 09:28:01 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Apr 2024 17:27:39 +0100 Message-ID: <20240415162741.110374-5-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240415162741.110374-1-derek.buitenhuis@gmail.com> References: <20240415162741.110374-1-derek.buitenhuis@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/6] avformat/http: Add support for Retry-After header X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: rj5dLKwimqWB 429 and 503 codes can, and often do (e.g. all Google Cloud Storage URLs can), return a Retry-After header with the error, indicating how long to wait, in seconds, before retrying again. If it is not respected by, for example, using our default backoff stratetgy instead, chances of success are very unlikely. This adds an AVOption to respect that header. Signed-off-by: Derek Buitenhuis --- libavformat/http.c | 12 ++++++++++++ libavformat/version.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libavformat/http.c b/libavformat/http.c index e7603037f4..8f092f108d 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -138,6 +138,8 @@ typedef struct HTTPContext { char *new_location; AVDictionary *redirect_cache; uint64_t filesize_from_content_range; + int respect_retry_after; + int retry_after; } HTTPContext; #define OFFSET(x) offsetof(HTTPContext, x) @@ -176,6 +178,7 @@ static const AVOption options[] = { { "reconnect_on_http_error", "list of http status codes to reconnect on", OFFSET(reconnect_on_http_error), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D }, { "reconnect_streamed", "auto reconnect streamed / non seekable streams", OFFSET(reconnect_streamed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D }, { "reconnect_delay_max", "max reconnect delay in seconds after which to give up", OFFSET(reconnect_delay_max), AV_OPT_TYPE_INT, { .i64 = 120 }, 0, UINT_MAX/1000/1000, D }, + { "respect_retry_after", "respect the Retry-After header when retrying connections", OFFSET(respect_retry_after), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, D }, { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, D | E }, { "resource", "The resource requested by a client", OFFSET(resource), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E }, { "reply_code", "The http status code to return to a client", OFFSET(reply_code), AV_OPT_TYPE_INT, { .i64 = 200}, INT_MIN, 599, E}, @@ -386,6 +389,13 @@ redo: reconnect_delay > s->reconnect_delay_max) goto fail; + if (s->respect_retry_after && s->retry_after > 0) { + reconnect_delay = s->retry_after; + if (reconnect_delay > s->reconnect_delay_max) + goto fail; + s->retry_after = 0; + } + av_log(h, AV_LOG_WARNING, "Will reconnect at %"PRIu64" in %d second(s).\n", off, reconnect_delay); ret = ff_network_sleep_interruptible(1000U * 1000 * reconnect_delay, &h->interrupt_callback); if (ret != AVERROR(ETIMEDOUT)) @@ -1231,6 +1241,8 @@ static int process_line(URLContext *h, char *line, int line_count, int *parsed_h parse_expires(s, p); } else if (!av_strcasecmp(tag, "Cache-Control")) { parse_cache_control(s, p); + } else if (!av_strcasecmp(tag, "Retry-After")) { + s->retry_after = strtoull(p, NULL, 10); } } return 1; diff --git a/libavformat/version.h b/libavformat/version.h index 7ff1483912..ee91990360 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ #include "version_major.h" #define LIBAVFORMAT_VERSION_MINOR 3 -#define LIBAVFORMAT_VERSION_MICRO 100 +#define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \