#include <gst/gst.h>
#include <libsoup/soup.h>

static void
server_callback (SoupServer *server, SoupMessage *msg, const char *path,
                 GHashTable *query, SoupClientContext *client,
                 gpointer user_data)
{
    if (msg->method == SOUP_METHOD_HEAD) {
        soup_message_set_status (msg, SOUP_STATUS_OK);
        soup_message_headers_set_content_length (msg->response_headers, 123456);
        soup_message_headers_set_content_type (msg->response_headers,
                                               "audio/mpeg", NULL);

        return;
    }

    soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
}

int
main (int argc, char *argv[])
{
    SoupServer *server;
    guint port;
    GstElement *pb;
    GMainLoop *loop;

#if !GLIB_CHECK_VERSION(2,36,0)
    g_type_init ();
#endif

    gst_init (&argc, &argv);

    server = soup_server_new (SOUP_SERVER_PORT, 12345, NULL);
    port = soup_server_get_port (server);

    soup_server_add_handler (server, "foo.mp3", server_callback, NULL, NULL);

    soup_server_run_async (server);

    pb = gst_element_factory_make ("playbin", NULL);
    g_object_set (pb, "uri", "http://localhost:12345/foo.mp3", NULL);
    gst_element_set_state (pb, GST_STATE_PLAYING);

    loop = g_main_loop_new (NULL, FALSE);
    g_main_loop_run (loop);
}
