souphttpsrc: properly check that seek range was respected
authorArnaud Vrac <avrac@freebox.fr>
Thu, 19 Jan 2017 10:05:00 +0000 (11:05 +0100)
committerSebastian Dröge <sebastian@centricular.com>
Mon, 23 Jan 2017 10:54:17 +0000 (12:54 +0200)
This check must be done only when we are sure the request was
successfully sent. soup_session_send() might fail without setting the
status code. In this case status code is 0 so we would only catch the
error after the seek range check. In this case we would report an error
saying that the seek range was not respected, instead of reporting the
underlying error that triggered the soup_session_send() failure.

https://bugzilla.gnome.org/attachment.cgi?bugid=777222

ext/soup/gstsouphttpsrc.c

index a7b1877..c4f70c6 100644 (file)
@@ -1024,7 +1024,6 @@ gst_soup_http_src_got_headers (GstSoupHTTPSrc * src, SoupMessage * msg)
   const char *value;
   GstTagList *tag_list;
   GstBaseSrc *basesrc;
-  GstFlowReturn ret;
   guint64 newsize;
   GHashTable *params = NULL;
   GstEvent *http_headers_event;
@@ -1239,23 +1238,7 @@ gst_soup_http_src_got_headers (GstSoupHTTPSrc * src, SoupMessage * msg)
   }
 
   /* Handle HTTP errors. */
-  ret = gst_soup_http_src_parse_status (msg, src);
-
-  /* Check if Range header was respected. */
-  if (ret == GST_FLOW_CUSTOM_ERROR &&
-      src->read_position && msg->status_code != SOUP_STATUS_PARTIAL_CONTENT) {
-    src->seekable = FALSE;
-    GST_ELEMENT_ERROR_WITH_DETAILS (src, RESOURCE, SEEK,
-        (_("Server does not support seeking.")),
-        ("Server does not accept Range HTTP header, URL: %s, Redirect to: %s",
-            src->location, GST_STR_NULL (src->redirection_uri)),
-        ("http-status-code", G_TYPE_UINT, msg->status_code,
-            "http-redirection-uri", G_TYPE_STRING,
-            GST_STR_NULL (src->redirection_uri), NULL));
-    ret = GST_FLOW_ERROR;
-  }
-
-  return ret;
+  return gst_soup_http_src_parse_status (msg, src);
 }
 
 static GstBuffer *
@@ -1463,6 +1446,8 @@ gst_soup_http_src_send_message (GstSoupHTTPSrc * src)
 static GstFlowReturn
 gst_soup_http_src_do_request (GstSoupHTTPSrc * src, const gchar * method)
 {
+  GstFlowReturn ret;
+
   if (src->max_retries != -1 && src->retry_count > src->max_retries) {
     GST_DEBUG_OBJECT (src, "Max retries reached");
     return GST_FLOW_ERROR;
@@ -1492,7 +1477,23 @@ gst_soup_http_src_do_request (GstSoupHTTPSrc * src, const gchar * method)
     return GST_FLOW_FLUSHING;
   }
 
-  return gst_soup_http_src_send_message (src);
+  ret = gst_soup_http_src_send_message (src);
+
+  /* Check if Range header was respected. */
+  if (ret == GST_FLOW_OK && src->request_position > 0 &&
+      src->msg->status_code != SOUP_STATUS_PARTIAL_CONTENT) {
+    src->seekable = FALSE;
+    GST_ELEMENT_ERROR_WITH_DETAILS (src, RESOURCE, SEEK,
+        (_("Server does not support seeking.")),
+        ("Server does not accept Range HTTP header, URL: %s, Redirect to: %s",
+            src->location, GST_STR_NULL (src->redirection_uri)),
+        ("http-status-code", G_TYPE_UINT, src->msg->status_code,
+            "http-redirection-uri", G_TYPE_STRING,
+            GST_STR_NULL (src->redirection_uri), NULL));
+    ret = GST_FLOW_ERROR;
+  }
+
+  return ret;
 }
 
 /*