/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <libsoup/soup.h>

SoupSession *session;

gboolean unpause_msg (SoupMessage *msg)
{
  g_warning("unpausing msg");
  soup_session_unpause_message (session, msg);
  return FALSE;
}

void got_headers (SoupMessage *msg, gpointer data)
{
  g_warning("headers [%s]", soup_message_headers_get_content_type (msg->response_headers, NULL));
  g_warning("pausing msg");
  soup_session_pause_message (session, msg);
  g_timeout_add(2000, unpause_msg, msg);
}

void got_chunk (SoupMessage *msg, SoupBuffer *chunk, GMainLoop *loop)
{
  g_warning("got-chunk");
  g_main_loop_quit (loop);
}

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

  g_thread_init (NULL);
  g_type_init ();

  loop = g_main_loop_new (NULL, TRUE);

  session = soup_session_async_new();

  msg = soup_message_new ("GET", "http://ad.accelerator-media.com/st?ad_type=iframe&ad_size=160x600&section=388433&IASH=OPPER");

  soup_message_set_flags (msg, SOUP_MESSAGE_SNIFF_CONTENT);

  g_signal_connect (msg, "got-headers", G_CALLBACK(got_headers), NULL);
  g_signal_connect (msg, "got-chunk", G_CALLBACK(got_chunk), loop);

  soup_session_queue_message (session, msg, NULL, NULL);

  g_main_loop_run (loop);

  return 0;
}
