Skip to content

Commit b56a9c7

Browse files
committed
[GStreamer] Get length from content-length header when available in chunked content encoding
https://bugs.webkit.org/show_bug.cgi?id=266691 Reviewed by Xabier Rodriguez-Calvar. Currently, chunked content-encoding media content transfers are considered not to have a defined length and are treated as live videos (no seek available, the whole content is downloaded in a monolithic way). However, sometimes the web server specifies a content-length that, even if not mandatory, gives a hint about the total length. If that info was used, we could treat the download in a much more flexible way, downloading only the required pieces on demand, as the player needs them, and also enabling seek. See: #1257 This patch leverages the information supplied by the content-length header when content-encoding is set as chunked. * Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (CachedResourceStreamingClient::responseReceived): Set length with the right information when the circumstances are appropriate. Canonical link: https://commits.webkit.org/272355@main
1 parent a7a71c4 commit b56a9c7

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,15 @@ void CachedResourceStreamingClient::responseReceived(PlatformMediaResource&, con
10111011

10121012
// length will be zero (unknown) if no Content-Length is provided or the response is compressed with Content-Encoding.
10131013
uint64_t length = !response.httpHeaderFields().contains(HTTPHeaderName::ContentEncoding) ? response.expectedContentLength() : 0;
1014+
1015+
// But in some cases, Content-Encoding: chunked can specify the total length. Use it.
1016+
std::optional<uint64_t> contentLength;
1017+
// There's a contentLength assignment (=) on purpose, plus an implicit comparison on the variable having a value.
1018+
if (!length && response.httpHeaderFields().contains(HTTPHeaderName::TransferEncoding)
1019+
&& equalLettersIgnoringASCIICase(response.httpHeaderField(HTTPHeaderName::TransferEncoding), "chunked"_s)
1020+
&& (contentLength = parseInteger<uint64_t>(response.httpHeaderField(HTTPHeaderName::ContentLength))))
1021+
length = contentLength.value();
1022+
10141023
if (length > 0 && members->requestedPosition && response.httpStatusCode() == 206)
10151024
length += members->requestedPosition;
10161025

0 commit comments

Comments
 (0)