From 9dcc7d9caca8aae32e6b9ca3dc5309d79d8e6956 Mon Sep 17 00:00:00 2001 From: Alex Ashley Date: Fri, 14 Aug 2015 08:33:56 +0100 Subject: [PATCH] souphttpsrc: add property to set HTTP method To allow souphttpsrc to be use HTTP methods other than GET (e.g. HEAD), add a "method" property that is a string. If this property is not set, GET is used. https://bugzilla.gnome.org/show_bug.cgi?id=752413 --- ext/soup/gstsouphttpsrc.c | 30 ++++++++++++++++++++++++++++-- ext/soup/gstsouphttpsrc.h | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ext/soup/gstsouphttpsrc.c b/ext/soup/gstsouphttpsrc.c index 3259a1eed3..49f1a4d388 100644 --- a/ext/soup/gstsouphttpsrc.c +++ b/ext/soup/gstsouphttpsrc.c @@ -123,7 +123,8 @@ enum PROP_SSL_CA_FILE, PROP_SSL_USE_SYSTEM_CA_FILE, PROP_TLS_DATABASE, - PROP_RETRIES + PROP_RETRIES, + PROP_METHOD }; #define DEFAULT_USER_AGENT "GStreamer souphttpsrc " @@ -137,6 +138,7 @@ enum #define DEFAULT_TLS_DATABASE NULL #define DEFAULT_TIMEOUT 15 #define DEFAULT_RETRIES 3 +#define DEFAULT_SOUP_METHOD NULL static void gst_soup_http_src_uri_handler_init (gpointer g_iface, gpointer iface_data); @@ -391,6 +393,18 @@ gst_soup_http_src_class_init (GstSoupHTTPSrcClass * klass) G_MAXINT, DEFAULT_RETRIES, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + /** + * GstSoupHTTPSrc::method + * + * The HTTP method to use when making a request + * + * Since: 1.6 + */ + g_object_class_install_property (gobject_class, PROP_METHOD, + g_param_spec_string ("method", "HTTP method", + "The HTTP method to use (GET, HEAD, OPTIONS, etc)", + DEFAULT_SOUP_METHOD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + gst_element_class_add_pad_template (gstelement_class, gst_static_pad_template_get (&srctemplate)); @@ -471,6 +485,7 @@ gst_soup_http_src_init (GstSoupHTTPSrc * src) src->ssl_use_system_ca_file = DEFAULT_SSL_USE_SYSTEM_CA_FILE; src->tls_database = DEFAULT_TLS_DATABASE; src->max_retries = DEFAULT_RETRIES; + src->method = DEFAULT_SOUP_METHOD; proxy = g_getenv ("http_proxy"); if (!gst_soup_http_src_set_proxy (src, proxy)) { GST_WARNING_OBJECT (src, @@ -527,6 +542,7 @@ gst_soup_http_src_finalize (GObject * gobject) if (src->tls_database) g_object_unref (src->tls_database); + g_free (src->method); G_OBJECT_CLASS (parent_class)->finalize (gobject); } @@ -642,6 +658,11 @@ gst_soup_http_src_set_property (GObject * object, guint prop_id, case PROP_RETRIES: src->max_retries = g_value_get_int (value); break; + case PROP_METHOD: + if (src->method) + g_free (src->method); + src->method = g_value_dup_string (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -727,6 +748,9 @@ gst_soup_http_src_get_property (GObject * object, guint prop_id, case PROP_RETRIES: g_value_set_int (value, src->max_retries); break; + case PROP_METHOD: + g_value_set_string (value, src->method); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1766,7 +1790,9 @@ gst_soup_http_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) g_mutex_lock (&src->mutex); *outbuf = NULL; - ret = gst_soup_http_src_do_request (src, SOUP_METHOD_GET, outbuf); + ret = + gst_soup_http_src_do_request (src, + src->method ? src->method : SOUP_METHOD_GET, outbuf); http_headers_event = src->http_headers_event; src->http_headers_event = NULL; g_mutex_unlock (&src->mutex); diff --git a/ext/soup/gstsouphttpsrc.h b/ext/soup/gstsouphttpsrc.h index 163de3d4ab..ef9539cc7f 100644 --- a/ext/soup/gstsouphttpsrc.h +++ b/ext/soup/gstsouphttpsrc.h @@ -71,6 +71,7 @@ struct _GstSoupHTTPSrc { gboolean retry; /* Should attempt to reconnect. */ gint retry_count; /* Number of retries since we received data */ gint max_retries; /* Maximum number of retries */ + gchar *method; /* HTTP method */ gboolean got_headers; /* Already received headers from the server */ gboolean have_size; /* Received and parsed Content-Length