/* gcc `pkg-config --cflags --libs glib-2.0 gio-2.0 libsoup-2.4` test.c -g -o test && ./test */

#include <glib.h>
#include <libsoup/soup.h>
#include <stdio.h>
#include <string.h>

static SoupSession *session;

static gpointer
thread_func (gpointer user_data)
{
	printf ("   about to send the message at a thread\n");
	soup_session_send_message (session, user_data);
	printf ("   finished the message send at a thread\n");

	return NULL;
}

static gboolean
main_quit (gpointer user_data)
{
	g_main_loop_quit (user_data);

	return FALSE;
}

static gboolean
main_idle (gpointer user_data)
{
	SoupMessage *msg;

	session = soup_session_sync_new ();
	/* just pick something large */
	msg = soup_message_new ("GET", "https://fedoraproject.org/download-splash?file=http://download.fedoraproject.org/pub/fedora/linux/releases/17/Live/x86_64/Fedora-17-x86_64-Live-Desktop.iso");

	g_thread_unref (g_thread_new (NULL, thread_func, msg));

	printf ("waiting one second in main idle\n");
	g_usleep (G_USEC_PER_SEC);
	printf ("done with wait one second in main idle, setting proxy to NULL\n");
	g_object_set (session, "proxy-uri", NULL, NULL);
	printf ("done with set proxy-uri to NULL in main idle\n");

	printf ("bye from main idle, trying one again\n");

	g_object_unref (msg);
	g_object_unref (session);

	return TRUE;
}

int
main (int argc, char **argv)
{
	GMainLoop *loop;

	g_type_init ();

	loop = g_main_loop_new (NULL, FALSE);
	g_idle_add (main_idle, loop);

	g_main_loop_run (loop);
	g_main_loop_unref (loop);

	return 0;
}
