souphttpsrc: add redirection to the URI query

This commit is contained in:
Andoni Morales Alastruey 2013-07-13 01:50:56 +02:00
parent 2269ac8f28
commit b9faeab236
2 changed files with 14 additions and 1 deletions

View File

@ -299,6 +299,7 @@ gst_soup_http_src_init (GstSoupHTTPSrc * src)
g_mutex_init (&src->mutex); g_mutex_init (&src->mutex);
g_cond_init (&src->request_finished_cond); g_cond_init (&src->request_finished_cond);
src->location = NULL; src->location = NULL;
src->redirection_uri = NULL;
src->automatic_redirect = TRUE; src->automatic_redirect = TRUE;
src->user_agent = g_strdup (DEFAULT_USER_AGENT); src->user_agent = g_strdup (DEFAULT_USER_AGENT);
src->user_id = NULL; src->user_id = NULL;
@ -331,6 +332,9 @@ gst_soup_http_src_finalize (GObject * gobject)
g_mutex_clear (&src->mutex); g_mutex_clear (&src->mutex);
g_cond_clear (&src->request_finished_cond); g_cond_clear (&src->request_finished_cond);
g_free (src->location); g_free (src->location);
if (src->redirection_uri) {
g_free (src->redirection_uri);
}
g_free (src->user_agent); g_free (src->user_agent);
if (src->proxy != NULL) { if (src->proxy != NULL) {
soup_uri_free (src->proxy); soup_uri_free (src->proxy);
@ -744,8 +748,10 @@ gst_soup_http_src_got_headers_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
return; return;
if (src->automatic_redirect && SOUP_STATUS_IS_REDIRECTION (msg->status_code)) { if (src->automatic_redirect && SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
src->redirection_uri = g_strdup (soup_message_headers_get
(msg->response_headers, "Location"));
GST_DEBUG_OBJECT (src, "%u redirect to \"%s\"", msg->status_code, GST_DEBUG_OBJECT (src, "%u redirect to \"%s\"", msg->status_code,
soup_message_headers_get_one (msg->response_headers, "Location")); src->redirection_uri);
return; return;
} }
@ -1460,6 +1466,7 @@ gst_soup_http_src_query (GstBaseSrc * bsrc, GstQuery * query)
switch (GST_QUERY_TYPE (query)) { switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_URI: case GST_QUERY_URI:
gst_query_set_uri (query, src->location); gst_query_set_uri (query, src->location);
gst_query_set_uri_redirection (query, src->redirection_uri);
ret = TRUE; ret = TRUE;
break; break;
default: default:
@ -1506,6 +1513,11 @@ gst_soup_http_src_set_location (GstSoupHTTPSrc * src, const gchar * uri,
} }
} }
if (src->redirection_uri) {
g_free (src->redirection_uri);
src->redirection_uri = NULL;
}
src->location = g_strdup (uri); src->location = g_strdup (uri);
return TRUE; return TRUE;

View File

@ -49,6 +49,7 @@ struct _GstSoupHTTPSrc {
GstPushSrc element; GstPushSrc element;
gchar *location; /* Full URI. */ gchar *location; /* Full URI. */
gchar *redirection_uri; /* Full URI after redirections. */
gchar *user_agent; /* User-Agent HTTP header. */ gchar *user_agent; /* User-Agent HTTP header. */
gboolean automatic_redirect; /* Follow redirects. */ gboolean automatic_redirect; /* Follow redirects. */
SoupURI *proxy; /* HTTP proxy URI. */ SoupURI *proxy; /* HTTP proxy URI. */