From patchwork Wed Feb 2 23:49:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Giovara X-Patchwork-Id: 34077 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp1999355iov; Wed, 2 Feb 2022 15:50:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGzYjbqYgyd/Cw7HIMNkQOpYtkVqY/D/JEknYT9ySBO+LzuUVuO+R1PjGZT1Ke3fh1oGiv X-Received: by 2002:a17:906:5d0e:: with SMTP id g14mr27128123ejt.211.1643845806510; Wed, 02 Feb 2022 15:50:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643845806; cv=none; d=google.com; s=arc-20160816; b=QKvCwKlwS/Ls7XKy8AMqnuEUxMAKjH4ID78K4klS1imjYBeEWWdJiR+i9PURcd79H2 F2Z1EhBvp4z5OwE+51GDGyvNczTRaIdPO4WRqKTkJqql9LDMyCVM7K4gbYKSTLDiTsDP b8MKND1q7Sr4WkNcXtwe5iUKLRudh9OvXFSYYqGB35sEhKAWpve3nq6wS2da8EstlB+F sb9HjsiFeor/d1PnZMGu0DrU8Yw07qtnD+EBmHdmL/rVGBBKAgBZl4MP4q3+EzD1X/tq XC2qQeDmoyuWk8rHWqTcVat0m5ehEFQpmFzP0h7cVDlhZQ/zH1pRlsz+bGG4Ay6LGrt7 mqJw== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=GJEFbiyEa7eTc9OoSlzZ/YSlz1sBI7CvkXUMZ98YM1c=; b=hFZHj3Ea5F6WlpfjoMCrwjT/z+lRu4gRrDTq4LlP1nF+ncWg/ZWs2AeMOnbs3RxnCG rccIOTcRRPysl5kFyr1Jrnz32lpJjUV2/qNTo2+a4cPsrNLCB3r1tIHy6gryfELykxi9 7yD2Lq/bNBSrf/4jo982wMqEkyWpaUVJW5MLguhb2ny7czEN1K623aZYaz23nI9xK/e7 qKQLR9DPpoR+3spWrhtc3ek7az0gbF9hBm2X/wSA22nUmiH5UV0hAyd6qDBsl17PWqOC 0/coVktZTKwDQ9fAATgPrbLPkjM82wXZyQbD7lIqdI+yjCPpCmbNhsMfipz2EzHviwdZ 9SiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=DmlS1Vs6; 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 f26si12020574edr.264.2022.02.02.15.50.05; Wed, 02 Feb 2022 15:50:06 -0800 (PST) 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=20210112 header.b=DmlS1Vs6; 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 56EFC68AC7B; Thu, 3 Feb 2022 01:50:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5309368AC7B for ; Thu, 3 Feb 2022 01:49:55 +0200 (EET) Received: by mail-ej1-f44.google.com with SMTP id a8so2299228ejc.8 for ; Wed, 02 Feb 2022 15:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=pJIGuv5yAK1mHj5cjr1VHs6ZkiIjBQzJm0qI1SWBpS0=; b=DmlS1Vs6JlI4OshrTne22ycBS8yZqxZoHaFb7SG66bjRA/NuvCZ8F8MwEMuWvu/Yx6 1Ys76ucrLjzk2D2KmmKWzh1sUg23dT24tb6jCNcuz4EQb74hgeqpVxfJmzNeTLJ5D2l5 VuT8Vim8uUph/Z9J8/VCv7o6MjgJnJ5c4GoP9axDRJ0PPugkUgGxe2jSpUcwx+ytfxcH 346fwknSOOgSKYKUNbEB3VtOfCB/+6LOkzMF4iEPeStZ2ttCG5cReDGXn6e7tR5ouX1W LFIsj8iC4w4zddGY91h4T5+hBGzKBr3QCU7u4E6uaF5uJXny79fkLvWzDYYDrCiYFjGA e58g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=pJIGuv5yAK1mHj5cjr1VHs6ZkiIjBQzJm0qI1SWBpS0=; b=LtApyb/mQ9peUllaNb+m3Q4oMj3n71gi9l8qonRlZ8UlMSl/V/5mCLPL89xwlnPZB9 cgyi9gno6zkJxuP/rUitcCVBHEmFZYori14drYeAzf44EJ8hRNhb9Hcd08Hvd/dwpEy3 0E7wvp2gK7fpp4qR/GM9kHGsKytiufRMFitCj1T9UASyKIelkoz8J3+X8X6Btd/UXNu6 uh5fO1sh3keQDNkVAZzgOxqOga+G5lXtKnXVcnxhQHpDHdz4nQ6RYwKAPx3PVL5lIcKv 5n/LR1e3CveqozNZ1m3SJYDEeKPpvhLY5rVJdcxF/pqv723hO7qQZr/JetXfU+D7OXn+ 45Rg== X-Gm-Message-State: AOAM531TXnLfCP6Ovaq/bK1jZhbv4yUr+adqED5Dp7fki0/0WYcPe1YZ zkAAPw4U4vMKuf9LpFtYAKtpK/cUr9Y= X-Received: by 2002:a17:907:7da8:: with SMTP id oz40mr21408190ejc.328.1643845794673; Wed, 02 Feb 2022 15:49:54 -0800 (PST) Received: from vimacbookpro.vimeows.com (93-41-18-244.ip79.fastwebnet.it. [93.41.18.244]) by smtp.gmail.com with ESMTPSA id g7sm21613744edr.71.2022.02.02.15.49.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Feb 2022 15:49:54 -0800 (PST) From: Vittorio Giovara To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 00:49:52 +0100 Message-Id: <20220202234953.6337-1-vittorio.giovara@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] http: Improve handling of Content-Range with Transfer-Encoding:chunked 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: 648bdZhHCHcX From: Justin Ruggles 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. --- libavformat/http.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 */