network/http-launch: Reduce duplicated code, using the same code for the HEAD and GET

requests.
This commit is contained in:
luis 2015-05-10 18:11:16 +02:00
parent 82c788e77f
commit fdf0d58143

View file

@ -125,42 +125,16 @@ send_response_404_not_found (Client * client)
static void
client_message (Client * client, const gchar * data, guint len)
{
gboolean http_head_request = FALSE;
gboolean http_get_request = FALSE;
gchar **lines = g_strsplit_set (data, "\r\n", -1);
if (g_str_has_prefix (lines[0], "HEAD")) {
gchar **parts = g_strsplit (lines[0], " ", -1);
gboolean ok = FALSE;
if (g_str_has_prefix (lines[0], "HEAD"))
http_head_request = TRUE;
else if (g_str_has_prefix (lines[0], "GET"))
http_get_request = TRUE;
g_free (client->http_version);
if (parts[1] && parts[2] && *parts[2] != '\0')
client->http_version = g_strdup (parts[2]);
else
client->http_version = g_strdup ("HTTP/1.0");
if (parts[1] && strcmp (parts[1], "/") == 0) {
G_LOCK (caps);
if (caps_resolved)
send_response_200_ok (client);
else
client->waiting_200_ok = TRUE;
G_UNLOCK (caps);
ok = TRUE;
} else {
send_response_404_not_found (client);
}
g_strfreev (parts);
if (ok && !started) {
g_print ("Starting pipeline\n");
if (gst_element_set_state (pipeline,
GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
g_print ("Failed to start pipeline\n");
g_main_loop_quit (loop);
}
started = TRUE;
}
} else if (g_str_has_prefix (lines[0], "GET")) {
if (http_head_request || http_get_request) {
gchar **parts = g_strsplit (lines[0], " ", -1);
gboolean ok = FALSE;
@ -185,6 +159,8 @@ client_message (Client * client, const gchar * data, guint len)
g_strfreev (parts);
if (ok) {
if (http_get_request) {
/* Start streaming to client socket */
g_source_destroy (client->isource);
g_source_unref (client->isource);
client->isource = NULL;
@ -193,6 +169,7 @@ client_message (Client * client, const gchar * data, guint len)
client->tosource = NULL;
g_print ("Starting to stream to %s\n", client->name);
g_signal_emit_by_name (multisocketsink, "add", client->socket);
}
if (!started) {
g_print ("Starting pipeline\n");