soup: Disable range requests when talking to Python's http.server

Python's SimpleHTTP server doesn't add Accept-Ranges and also doesn't
support range requests: https://github.com/python/cpython/issues/86809

According to the spec, this means the server may or may not support
Range requests, but we know that SimpleHTTP server doesn't, so let's
disable it. If they fix it, they will hopefully add an Accept-Ranges
header.

See also: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8505#note_2994060

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9341>
This commit is contained in:
Nirbheek Chauhan 2025-07-08 01:30:01 +05:30 committed by GStreamer Marge Bot
parent 160205b483
commit 19a2a158fa

View File

@ -1557,6 +1557,37 @@ gst_soup_http_src_got_headers (GstSoupHTTPSrc * src, SoupMessage * msg)
_soup_message_headers_get_one (response_headers, "Accept-Ranges"))) {
if (g_ascii_strcasecmp (accept_ranges, "none") == 0)
src->seekable = FALSE;
} else {
/* Python's SimpleHTTP server doesn't add Accept-Ranges and also doesn't
* support range requests: https://github.com/python/cpython/issues/86809
*
* According to the spec, this means the server may or may not support
* Range requests, but we know that SimpleHTTP server doesn't, so let's
* disable it. If they fix it, they will hopefully add an Accept-Ranges
* header.
*
* FIXME: this will break if there are some silly implementations that
* derive from http.server and support Range requests, but also don't set
* the Accept-Ranges response header. We could potentially change
* src->seekable to a tristate and do some auto-detection if the
* seekability is unknown and remove this special-casing, but it's not
* clear if it's worth it at present.
*/
const char *server = NULL;
if ((server = _soup_message_headers_get_one (response_headers, "Server"))) {
if (g_str_has_prefix (server, "SimpleHTTP/")
&& strstr (server, "Python/") != NULL) {
src->seekable = FALSE;
GST_WARNING_OBJECT (src, "No Accept-Ranges response header from "
"Python's SimpleHTTP server, assuming no support for Range "
"requests");
}
}
if (src->seekable) {
GST_WARNING_OBJECT (src, "No Accept-Ranges response header, assuming "
"server supports Range requests");
}
}
/* Icecast stuff */